Posts

Showing posts from December, 2020

C# Line Reader

Image
Sometimes I'll get a text file to parse, where it's too big or too complex for a spreadsheet, and not worth the trouble of importing to a database. Here's a quick way to parse the file line-by-line with C# Here's the same thing in NodeJS - personally I think the C# way is a little easier, especially since .NET Core and the dotnet CLI came out. View code on GitHub

NodeJS Line Reader

Image
Sometimes I'll get a text file to parse, where it's too big or too complex for a spreadsheet, and not worth the trouble of importing to a database. Here's a quick way to parse the file line-by-line with NodeJS. Here's the same thing in C# . View code on GitHub

TypeScript in NodeJS

Image
It doesn't take much to set up TypeScript in NodeJS. TypeScript's type safety makes it much more enjoyable to write than plain JavaScript. If you're new to TypeScript, check out the playground where you can see a bunch of examples of what TypeScript looks like compared to JavaScript. When importing NPM packages, you can almost always find the typings by installing @types/my-package-name . If that doesn't work, do a web search and you'll most likely find a blog post or StackOverflow answer that tells you how to use the package with TypeScript. View code on GitHub

Dependency Injection in Console Application

Image
With ASP.NET, you get built-in dependency injection. In a console application, it's not there out of the box, but it's ridiculously simple to get started. Read more about it here . Read all about the various options and lifetimes in the Microsoft documentation . View code on GitHub

LINQ Group By

Image
GROUP BY syntax in LINQ is a little bit different from SQL, but still pretty easy to use. For more LINQ examples and scenarios, check out LINQ Samples . View code on GitHub

GZip in .NET

Image
GZip in .NET is really simple and straightforward. Below you can find a helper class that gives you the ability to compress and decompress a stream, byte array, string, or file - you can easily modify these to suit your needs. View code on GitHub

DotNet CLI

Image
Don't be afraid of using the .NET CLI and skipping Visual Studio. Visual Studio Code is a fantastic IDE for .NET projects - obviously not as powerful as Visual Studio, but it's significantly lighter and faster, and the integrated terminal is desperately needed in Visual Studio. The .NET CLI is actually incredibly easy to work with. This video shows some of the basic commands. See the documentation for more. View code on GitHub

SCSS in ASP.NET

Image
If you're not using something like WebPack or Gulp, but still want to use SCSS stylesheets, here's an easy way: View code on GitHub

C# Record Serialization

Image
With .NET 5, you get a new concept called record . Lots of cool things, one of which is that you can serialize and deserialize with JSON just like a class, except you don't need to define properties one at a time, or even the body of the type. Apparently XML serialization doesn't quite work, so stick with JSON. View code on GitHub