Skip to content

Instantly share code, notes, and snippets.

View Fjeddo's full-sized avatar
πŸƒ

Fredrik Johnsson Fjeddo

πŸƒ
View GitHub Profile
@Fjeddo
Fjeddo / Program.cs
Created June 5, 2025 04:48
Three ways using DI in a console application (program.cs)
/// <summary>
/// Three ways using DI in a console application (program.cs)
/// </summary>
/*
csproj:
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
*/
//////////////////////////////////////////////////////////////////////////////////////////
@Fjeddo
Fjeddo / show_shutdowndialog.ps1
Last active April 15, 2025 17:00
Show windows (11) shutdown dialog
(New-Object -ComObject Shell.Application).ShutdownWindows()
@Fjeddo
Fjeddo / my-slim-oh-my-posh.omp.json
Last active May 16, 2025 05:12
my-slim-oh-my-posh.omp
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"console_title_template": "{{if .Root}}admin :: {{end}}{{.Shell}} :: {{.Folder}}",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"properties": {
@Fjeddo
Fjeddo / Program.cs
Last active May 26, 2021 08:59
Validate JWT (C# .NET Core)
//////////
// .net core 3.1 (console app)
//////////
// PM> install-package System.IdentityModel.Tokens.Jwt -Version 6.11.1
//////////
using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;
namespace jwtValidation
@Fjeddo
Fjeddo / gifconfig
Created November 27, 2020 05:41
On the top the .gitconfig-file, below that the alternative gitconfigs active/included through the if-statement
##############################################################
# The .gitconfig read by git, placed in the user home folder,
# e.g. c:\users\[username]\.gitconfig on windows
##############################################################
[include]
path = ~/git-base.conf
[includeIf "gitdir:D:/Develop/Customer_1/repos/"]
path = ~/git-customer1.conf
# Get installed version .NET 4.x
Get-ItemProperty "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
# Get last boot time
(Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime
# Get Win OS info
Get-CimInstance -ClassName win32_operatingsystem | select *
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using Microsoft.Graph;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
@Fjeddo
Fjeddo / Get_all_row_counts.sql
Created April 17, 2019 04:37
Gets all tables' row count in SQL Db
USE -- Db name goes here
GO
SELECT SCHEMA_NAME(A.schema_id) + '.' +
A.Name, AVG(B.rows) AS 'RowCount'
FROM sys.objects A
INNER JOIN sys.partitions B ON A.object_id = B.object_id
WHERE A.type = 'U'
GROUP BY A.schema_id, A.Name
ORDER BY A.schema_id, A.Name
@Fjeddo
Fjeddo / createSASTokenDemo.js
Created February 7, 2016 12:26
Javascript demo on how to create a SAS token to be used for the Azure IoT hub
var getToken = function(iotHubName, key, keyName) {
var expiry = Math.floor(new Date().getTime() / 1000) + 3600 * 24; // 24 h expiry
var uri = iotHubName + ".azure-devices.net";
var hmacer = new jsSHA("SHA-256", "TEXT"); // This is from https://github.com/Caligatio/jsSHA/releases/tag/v2.0.1
hmacer.setHMACKey(key, "B64");
hmacer.update(encodeURIComponent(uri) + "\n" + expiry);
var sig = hmacer.getHMAC("B64");
write-host @"
β”Œβ”€ Welcome ─────────────────────────────────────────────────────────────────────┐
β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„ β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„ β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„ β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„ β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„ β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„
β–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–Œβ–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–Œβ–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–Œβ–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–Œ β–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–Œ β–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–Œ
β–β–‘β–ˆβ–€β–€β–€β–€β–€β–€β–€β–€β–€ β–€β–€β–€β–€β–€β–ˆβ–‘β–ˆβ–€β–€β–€ β–β–‘β–ˆβ–€β–€β–€β–€β–€β–€β–€β–€β–€ β–β–‘β–ˆβ–€β–€β–€β–€β–€β–€β–€β–ˆβ–‘β–Œβ–β–‘β–ˆβ–€β–€β–€β–€β–€β–€β–€β–ˆβ–‘β–Œβ–β–‘β–ˆβ–€β–€β–€β–€β–€β–€β–€β–ˆβ–‘β–Œ
β–β–‘β–Œ β–β–‘β–Œ β–β–‘β–Œ β–β–‘β–Œ β–β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œ
β–β–‘β–ˆβ–„β–„β–„β–„β–„β–„β–„β–„β–„ β–β–‘β–Œ β–β–‘β–ˆβ–„β–„β–„β–„β–„β–„β–„β–„β–„ β–β–‘β–Œ β–β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œ
β–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–Œ β–β–‘β–Œ β–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œ
β–β–‘β–ˆβ–€β–€β–€β–€β–€β–€β–€β–€β–€ β–β–‘β–Œ β–β–‘β–ˆβ–€β–€β–€β–€β–€β–€β–€β–€β–€ β–β–‘β–Œ β–β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œβ–β–‘β–Œ β–β–‘β–Œ