RSSAmplifier

Blog

Aaron Hoffman's Blog

Over 350,000 pageviews and counting!

aaron-hoffman.blogspot.comRSS feed ↗25 posts

Latest posts

AWS DynamoDB SDK support for .NET DateTimeOffset

The AWS DynamoDB SDK does not support the .NET DateTimeOffset datatype by default . You may have received an exception similar to: System.InvalidOperationException: Type System.Nullable System.DateTimeOffset is unsupported, it cannot be instantiated. at Amazon.DynamoDBv2.DataModel But you can add a custom IPropertyConverter so that you can persist DateTimeOffset. public class…

ASP.NET .NET 6 OIDC Retrieve JWT AccessToken after SaveTokens

I was not able to find the docs for retrieving the JWT AccessToken in ASP.NET .NET 6 after they are saved so I decided to document it here. You may be familiar with the HttpContext.GetTokenAsync() method . This appears to have worked in previous version of .NET, but I could not get it to work in .NET 6. First, make sure you are saving the access tokens in the AddOpenIdConnect configuration.…

Auth0: Restrict SPA Application Access to API Audience/Permissions/Scopes

In Auth0 you can restrict the APIs/Permissions a Machine-to-Machine type Application has access to using the "APIs" section in the Application Configuration: However, SPA type Applications do not have an equivalent configuration option: There is no way to restrict the APIs a SPA type Application has access to directly . Instead, you must restrict the APIs/Permissions/Scopes a User has access to .…

Find Azure Application Insights Resource by InstrumentationKey

I had a need to query some Application Insights logs, but all I had was the InstrumentationKey. I didn't want to open each of the Application Insights instances and check the key (there were a lot), but as long as you have the Azure "Az" Powershell Module installed, you can run this script to print out all App Insights instances and their associated Instrumentation Key:…

Simple Rules Engine in C#

There are some C# "Rules Engines" floating around however they rely on a no-longer-supported nuget package (dynamic linq) https://github.com/microsoft/RulesEngine I created this "SimpleRulesEngine" that does not rely on lambdas or expression trees. The expressions can be serialized to JSON. https://github.com/aaronhoffman/SimpleRulesEngine I hope to get a simple example web application added to…

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…

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…

United States Postal Code to State Map

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.…

Newtonsoft Json BaseJsonConverter

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…

Complete Project Gutenberg Catalog in JSON

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…

ASP.NET Core 2.1 Identity

I thought I'd compile some resources on ASP.NET Core 2.1 Identity . Hope you find these useful: Database schema of tables that are generated after the first EF Migration: https://gist.github.com/aaronhoffman/74f4c072afaa0459dcd6595b6380f67d You can override password rules in the Startup.cs class: services.AddDefaultIdentity () .AddEntityFrameworkStores (); services.Configure (options => {…

Programmatically add Other Search Engines to Google Chrome for VSTS Shortcuts

When I'm working with a new repo/project in VSTS , I like to set up shortcuts in Google Chrome to be able to quickly jump to a specific Work Item, PR, Build, or Release based on the ID. To do this, I take advantage of Chrome's " other search engines " settings. You can manually add these by specifying a Short Name, a Keyword, and the URL to navigate to when that keyword is typed into the browser's…

Location of SqlPackage.exe on VSTS and Azure

If you're looking to deploy a Visual Studio Database Project via VSTS to Azure, you can use the Azure SQL Database Deployment Release Task to include the deployment in your CI/CD process. When a .dbproj builds, it creates a .dacpac file that contains the database definition/schema. The DB Deployment Release Task uses the SqlPackage.exe executable to deploy/sync the target database with the…

Sync Github Gists with Git Repo

I needed an easy way to sync github gists to my local machines and I couldn't find anything provided by gist, or any other open source projects out there so I put this little node app together quick. Simply clone this repo and update the `users.json` file to sync all the associated public gists to your local machine. https://github.com/aaronhoffman/gists The node app uses the gists api and `git…

Use Azure Functions to Execute a SQL Azure Stored Procedure on a Timer

It was hard to find this information all in one place, so I thought I'd throw a post together quick. If you have the need to execute a stored procedure on a timer, that can be fairly easily accomplished with Azure Functions . Create a new Timer Trigger Azure Function , set the cron timer as desired, and add code similar to the code below: using System; using System.Data; using…

Create Google Contact via API and Add To My Contacts System Group

When you create a new Contact via the Google Contacts API , by default it will not appear in the list of contacts on the Google Contacts webpage , however, if you search for the contact there, it will appear. If you then click the "Add to contacts" button, it will appear in that contacts list, and increase your contact count in the top left of the page. There is a way to add new contacts via the…

Visual Studio 2017 Code Snippet INotifyPropertyChanged

This is an update to the vs2010 code snippet: https://aaron-hoffman.blogspot.com/2010/09/visual-studio-code-snippet-for-notify.html Code can now be found here: https://gist.github.com/aaronhoffman/c821acf4bb3b3beb0759e93bbe3a2402 Hope this helps, Aaron

NYSE Historical Stock Price Data From Quandl

Quandl is a great resource for historical stock price data. I thought I'd pull some meta-data out of the " Wiki EOD Stock Prices " data set in order to help future developers. First, here is the table structure I used to insert the CSV flat file into SQL Server: CREATE TABLE [dbo].[SymbolHistory]( [ticker] [varchar](5) NULL, [date] [date] NULL, [open] [decimal](16, 6) NULL, [high] [decimal](16, 6)…

Generate Random AES Encryption Key

I was looking for a way to quickly generate a random AES key online, but couldn't find anything. I looked into a couple methods using JavaScript, but determined that a C# solution would be better. I needed to base64 encode the key array to store that value in a config file. Here's the code I ended up with: https://gist.github.com/aaronhoffman/09b56f77a95205fe10365bde2f4a02e5 UPDATE Using Visual…

Sync Gmail Contacts Between Accounts

For the last few years I've needed a way to easily sync contacts between gmail accounts. The only method previously supported by Google is to export to csv then re-import the contact list . This may work for some, but clearly there is a desire for something else. I finally found some time to dig into the Google Contact APIs and created a site to perform this sync operation easily, without needing…

Hide Main Menu for Visual Studio 2017

To improve my development experience, I disable as many windows and toolbars in Visual Studio as possible. The one toolbar that you can not disable via the IDE itself is the "main menu" toolbar (File, Edit, View, etc.). There is an extension that I've used in previous versions of Visual Studio that hides this menu until the user presses the `alt` key. Here is a link to that extension in the…

git - protect local master branch, prevent commit and push

If you've worked with a remote git hosting service like github , you're likely familiar with the concept of protecting a branch . Other remote git hosting services ( vsts , bitbucket , gitlab , etc) also support the concept. It's a good idea to protect your remote in this way, but why stop there? You can also protect your local dev environment from human error by using git hooks . A new git repo…

Search iPhone Text Messages with SQLite SQL Query

While you're here, check out some of our interactive visualizations: Would you like to visualize your text messages? ------------------------------------------------------------------------------- In my experience, the iPhone text message search functionality is usually pretty awful. Especially if you're trying to find a text from a few years ago. Luckily, if you backup your iPhone using iTunes,…

Azure Kudu Deployment with Version Number

I recently blogged about generating a version.txt file on every build via Visual Studio . This solution is fine if you are building from you local machine and using Web Deploy to deploy to Azure, but if you have a github webhook and are using kudu, the VS Post Build Events are not executed. The easiest way I found to generate a version.txt file for every deployment is to add a post deployment…

Stop Azure WebJob from Azure WebSite

I recently had the need to toggle the status of an Azure WebJob from the WebSite in the same Azure App Service. I found a couple half-complete answers online, but I thought I'd put together this simple guide to have a complete example all in one place. To accomplish this, we'll be using the kudu REST API for WebJobs . (note: I also looked into toggling the WEBJOBS_STOPPED environment variable from…