Categories
Programming

Naming TypeScript Custom Type Guards

This is a super quick one. Be super-careful about how you name your custom type guards to stop consumers falling into a trap. Basically, the name you give a custom type guard and the return type you specify form a kind of promise that you have to be able to keep. Take this example: function […]

Categories
Programming

JQuery and TypeScript – We Have a Big Problem With jquery.d.ts

This is a call to all my TypeScript connections. This is a call to all. We have a big problem with the official Definitely Typed definition for jQuery. The most fundamental definition for the JQuery interface is incorrect, as you can see in the snippet from jquery.d.ts below. We can fix it, but not without […]

Categories
Programming

CSS Clamp: The Goldilocks of CSS Math Functions

There is a problem I have wrestled with a couple of times, which was frustrating to solve… but can now be easily solved using clamp, which is currently in an Editors Draft of the CSS Values and Units Module Level 4 specification. It is sat alongside similar mathmatical CSS nuggets, such as min and max […]

Categories
Programming

Entity Type IdentityUserLogin Requires a Primary Key

You will usually come across this problem in .net Core Entity Framework when you first override the OnModelCreating method in your DbContext. The entity type ‘IdentityUserLogin‘ requires a primary key to be defined. If you intended to use a keyless entity type call ‘HasNoKey()’. If you check your DbContext class, you’ll see that when you […]

Categories
Programming

Run Multiple PowerShell Scripts from a Master PowerShell Script

Having put together some individual scripts that ripped data out of an Excel spreadsheet, I decided to co-ordinate them with a master PowerShell script that would contain my variables and call out to neat little scripts to do work. PowerShell gets tricky to read when it gets big, so I prefer to have a couple […]

Categories
Office Programming

Extract an Excel Column to a Text File with PowerShell

Having opened up the same Excel spreadsheet to copy out a list of domain names into a text file for my test automation tools to consume for the third time, I wrote a PowerShell script to do it for me. Yes, it’s the same spreadsheet I mentioned before, it is full of interesting data and […]

Categories
Office Programming

Copy Excel to CSV with PowerShell

Having opened up the same Excel spreadsheet to save the data as a CSV for the third time, I wrote a PowerShell script to do it for me. Simply set the source and destination files and the script takes care of the rest. & { $sourceFile = “C:\Temp\data.xlsx” $outFile = “C:\Temp\data.csv” $excelApplication = New-Object -ComObject […]

Categories
Programming

Convert a SQL SELECT into an INSERT Script

Sometimes you want to generate an INSERT script from existing data, perhaps with one or two values tweaked. It’s a pain to hand-crank the INSERT when you can see exactly what you want using a SELECT statement. It’s also a bit long-winded to use SQL import/export wizards or other tools. Sometimes, you just want to […]

Categories
Programming

Check Certificate Expiry Date in .NET Core

I needed to check the certificate expiry date in an NUnit test. The below snippet can be used to check any certificate properties, using a custom certificate validation callback. All you need to do is read the properties you are interested in within the callback so you can check them afterwards. DateTime notAfter = DateTime.UtcNow; […]

Categories
Programming

.NET Core Entity Framework Migrations

When you don’t want to script out your own database, Entity Framework Core has your back. When you change your database context or the models it uses, you can use a couple of commands to create and update your database to keep it in sync with your model. These examples run in the Package Manager […]