Category Archives for Code

EF Core Soft-Delete V2

It turns out, my first version was subtlety broken in ways that only started occurring when you started implementing more complex joins. This version works.
https://stackoverflow.com/questions/45096799/filter-all-queries-trying-to-achieve-soft-delete/45097532#45097532

Undersized Instances

I launched a rather large project on AWS using very small instances for the application servers and database (RDS). The application itself is seasonal, so the traffic spikes in December and then levels out. In December we had 250k unique page views.

It was kind of interesting using under-sized instances and seeing how things go wrong. On the application side of things it sailed along. MySQL is where all the problems seemed to be concentrated.

I spent a bit of time early in my career writing A LOT of SQL and within the past few years I've spent a bit of time leveling up my skills in regards to MS-Sql internals. Things like indices, waits, latches, how to use extended events, etc. So anyways, I just happened to have a specific set of skills to put out the MySql dumpster fire before it crashed the whole application. 

If anyone is interested, below is what deadlocks look like.

It makes me wonder what would have happened if I had over-sized these instances and been ignorant of Sql internals. Would the application have just continued working? Maybe it would have kept trudging along, doing more heavy lifting than it should, while being just a little bit laggy. Maybe I would have thrown more resources at it. 

I can certainly empathize with someone who just wants to put their data somewhere and pull it back without having to worry about how a deadlock condition is going to exhaust their connection pool. I'm sure it's things like this that gave rise to BaaS platforms like firebase.

Successful launch

It’s really rewarding to see a project go live. Late last year I build and launched an online portal for a client. Over the past 10 months we registered 14k users. These users are already customers of the client, but historically have had to mail in checks and paper forms.

Last week we launched the online equivalent of these checks and forms. I was the sole developer of the external-facing application. I was worried when we turned it live that we wouldn’t see any traffic for a while…but someone started using it literally within seconds. We’ve had thousands of people using it this week.

So, had a fun little trial-by-fire thing last week with : hitting bank CC authorization limits, DB indexing, deadlocks, deploys, etc. In general though, everything worked really well and it was a complete success. 5 more came through while I was typing this. We crossed $150k over the weekend!

It’s a great feeling to work hard and have it pay off.

 

CLR Generics and Struct Boxing

The PR comments from @benaadams here are awesome. https://github.com/dotnet/corefxlab/pull/2358
This is likely basic knowledge needed for high-performance .NET, but it was new to me. Very interesting to see how defining a generic <T> can eliminate boxing/allocations.

The T parameter is explicitly being specified as an interface: IBufferWriter<byte>; so if you create that BufferWriter<IBufferWriter<byte>> and give it a struct as the T, then its boxed to the interface and stored in the BufferWriter<IBufferWriter<byte>> as the boxed IBufferWriter<byte> type.

So, if you explicitly specify the T, it will get boxed. If you specify it as a generic, and then call the generic constructor, it will not.

public static JsonWriter<TBufferWriter> Create<TBufferWriter>(
TBufferWriter bufferWriter,
bool isUtf8,
bool prettyPrint = false)
where TBufferWriter : IBufferWriter<byte>
{
     return new JsonWriter<TBufferWriter>(bufferWriter, isUtf8, prettyPrint);
}

ODWEK Middleware with Spring Boot

Recently a client was upgrading to CMOD V10.1 on the iSeries and we noticed that the CGI/Servlet support has been removed, after being deprecated in V9.0

"OnDemand Web Enablement Kit (ODWEK) CGI/Servlet support no longer shipped: Support for CGI/Servlet was deprecated at V9.0 and has been removed from the product at V10.1."

At this particular client, that I've wrote about before, we are doing some interesting things with pulling documents and text out of CMOD programatically. We have custom reports, email attachment functions, on the fly TIF conversion, etc. All of this is written in C# wrapped around the legacy CGI component.

Upgrading to V10.1 means we needed to re-implement the CGI functionality using the Java API. My first inclination was to use IKVM to convert the API to a C# dll and call it directly. I ended up hitting a brick wall with this related to some strange type marshalling and decided to implement the way IBM likely intended: with a java servlet.

I decided that if I was going to basically re-implement the CGI functionality, I would make it work the way I needed. Previously I was calling the CGI page and scrapping the HTML. Forget that now that I'm going to be in control, I'm going to return JSON!

Continue reading

Proper Date Formatting with Thymeleaf and Spring.

In Spring, if you attempt to display a Date from your viewmodel in an HTML5 date input, it won't format correctly.

To fix - you can implement custom binder on your controller. Put the following at the top of your controller.

.NET Core Message Pump

I'm writing a cross-platform mouse without borders clone right now. Basically a .NET version of Synergy. 

Tech stack: .NET Core, SignalR

I ran into an issue with my windows hooks not working when running inside a .NET Core console. This is because if you don't include Application.Run(new ApplicationContext()), there is no Windows message pump. Without a message pump, your hooks won't receive anything.

 Fortunately, you can implement your own message pump very easily.

Continue reading

Bash script to configure raspberry pi for kiosk mode

I wrote myself a script to provision the raspberry pi for kiosk mode. 

Be sure to change the password it sets.
Run it with an argument for the URL that it opens.

In the script I do some stuff with grep and sed to allow it to be run multiple times. I also explicitly set the keyboard to en-us and enable SSH for management.

Continue reading

Native OSX calls using .NET Core and pinvoke

As an experiment I wanted to write some code in .NET Core that would call native OSX call to perform an action not exposed by .NET Core. I decided to make a program that would simply move the mouse a little bit.

This ended up being really simple once I figured out a few gotchas. 

Continue reading