Posts

Configure SonarAnalyzer.CSharp with .editorconfig, no need for SonarCloud or SonarQube

Our goal was to use  SonarSource / SonarQube  static code analysis with the most "minimal" install/configuration footprint. We wanted the static code analysis to break/fail the build on the local developer machines as well as our CI/CD Azure DevOps environment if a rule was violated. SonarSource products usually rely on some external source,  SonarCloud /SonarQube to determine which rules to apply on the local dev machine, and to store the results. We wanted to eliminate these dependencies. SonarSource also provides a Visual Studio extension called  SonarLint  to help check the static code analysis rules within the Visual Studio IDE without needing an external source for the rules. The static code analysis rules SonarLint enforces are also defined in the  SonarAnalyzer.CSharp  nuget package. This nuget package is a set of  Roslyn Code Analyzers . In .NET Core, Roslyn Code Analyzers are triggered during a build if the nuget package is referenced by the project. Also in .NET Co

AspNet Core JWT Authentication ValidateLifetime "The token has no expiration"

Found a "bug" within aspnet core JWT Authentication and thought I'd write something up since I could not find much info online. Found the answer here, but it's not easy to find:  https://github.com/SevenSpikes/api-plugin-for-nopcommerce/issues/99 Essentially, if you create a valid JWT with an expiration time after the year 2038, the default aspnet core JWT Auth will determine that it is invalid saying, " The token has no expiration ". The solution is to create a JWT with an expiration time after "now" but before the year 2038. Hope this helps, Aaron

United States Postal Code to State Map

Image
I had a need to determine the State code given a zip code/postal code and could not find a concise list I could use as the base of the map. There is a PDF available on irs.gov , but that doesn't lend itself well to automation. Using that PDF, I generated this CSV file:  https://gist.github.com/aaronhoffman/d7a598efb593e3acf5e0a39c0dd8b52a There are two different formats depending on your use case. I hope you find it useful! -Aaron

Newtonsoft Json BaseJsonConverter

Image
I've recently had a need for a custom JsonConverter to read and write data to CosmosDb in a way that utilizes a CosmosDb document's `id` property. (more on that in a later post) My first step was to investigate a custom Newtonsoft.Json JsonConverter . I thought that there might be a BaseJsonConverter implementation somewhere in the docs, but I was wrong . After digging through many different custom converters, I think I've discovered what the most trivial custom converter might look like. You can find the example here, and customize it further to fit your needs: https://gist.github.com/aaronhoffman/de40ac508de95101fa41859195728e39 Hope this helps, Aaron

Complete Project Gutenberg Catalog in JSON

Image
Project Gutenberg is an amazing site containing over 57,000 free ebooks at the time of this writing. Recently I've been working on a project to create a database of book bibliographies. A database of book references from within other books. You'd be able to answer the query: Show me all the books that reference "Thinking Fast and Slow". I plan to use Project Gutenberg as the repository that I use to create the first version of this database. Project Gutenberg currently makes their complete project catalog available as a collection of RDF files found here: http://www.gutenberg.org/wiki/Gutenberg:Feeds RDF is not something I've worked with in the past, so I converted them to JSON files. You can download that set of files from here: https://sfp.blob.core.windows.net/public/gutenberg_catalog.zip Hope this helps, Aaron