Skip to content

Instantly share code, notes, and snippets.

View OskarKlintrot's full-sized avatar
🐢

Oskar Klintrot OskarKlintrot

🐢
View GitHub Profile
@OskarKlintrot
OskarKlintrot / Program.cs
Created February 3, 2023 19:40
Use an ObservableCollection for configuration during testing
#nullable enable
ObservableCollection<KeyValuePair<string, string?>> inMemoryOptions = new()
{
new("MyOptions:MyProperty", "Foo"),
};
var builder = Host.CreateDefaultBuilder();
builder
@OskarKlintrot
OskarKlintrot / Manipulate.cs
Last active September 1, 2022 09:06
Write to Utf8JsonWriter from Utf8JsonReader
var reader = new Utf8JsonReader(Encoding.UTF8.GetBytes(json));
using var stream = new MemoryStream();
using (var writer = new Utf8JsonWriter(stream))
{
while (reader.Read())
{
switch (reader.TokenType)
{
case JsonTokenType.None:
@OskarKlintrot
OskarKlintrot / IProcessRunner.cs
Created February 7, 2022 12:39
ProcessRunner
using System.Diagnostics;
namespace PRunner;
public interface IProcessRunner
{
Task<ProcessResult> ExecuteProcess(
string executable,
string arguments,
CancellationToken cancellationToken,
# Might need this later on: https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-core-60?view=powershell-6#backwards-compatibility-with-windows-powershell
# Install posh-git first with
# > PowerShellGet\Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force
Import-Module posh-git # Might want to add it to $profile.CurrentUserAllHosts instead: https://github.com/dahlbyk/posh-git#step-2-import-posh-git-from-your-powershell-profile
Set-PSReadLineOption -Colors @{ "Command"=[ConsoleColor]::DarkYellow }
Import-Module C:\_repos\tools\scripts\Eparkering-Module\EparkeringModule\EparkeringModule.psd1
@OskarKlintrot
OskarKlintrot / Spam.css
Last active March 13, 2018 12:02
Twitter extension
<span>
<button type="button" class="
EdgeButton
EdgeButton--danger
EdgeButton--small
button-text
follow-text" onclick="jQuery.post('https://api.twitter.com/1.1/users/report_spam.json?screen_name=rabish2&amp;perform_block=true')">
<span aria-hidden="true">Spam</span>
<span class="u-hiddenVisually">Report <span class="username u-dir u-textTruncate" dir="ltr">@<b>rabish2</b></span></span>
@OskarKlintrot
OskarKlintrot / FindNotNullable.sql
Created January 3, 2018 09:31
A SQL query to find all columns in a table that is not nullable (good to have ie when populating a table for testing)
USE DATABASENAME
DECLARE @table varchar(250) = 'TABLENAME'
SELECT name, is_nullable
FROM sys.columns
WHERE object_id = object_id(@table)
AND is_nullable = 0
ORDER BY name
@OskarKlintrot
OskarKlintrot / AutoHotkeyScript.ahk
Last active March 8, 2018 09:43
My Auto Hotkey Script
; Create Task
;RunWait, %A_WinDir%\System32\schtasks.exe /create /TN AHK /TR C:\Users\oskkli\Documents\AutoHotkey\AutoHotkeyScript.ahk /RL HIGHEST /SC ONLOGON
#SingleInstance, force ; Always replaces the old instance automatically
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetCapsLockState, AlwaysOff ; Turn off Caps Lock
SetNumLockState, AlwaysOn ; Set state to On and then disable NumLock
@OskarKlintrot
OskarKlintrot / CSharpClassGenerator.sql
Created October 27, 2017 06:45
Generate C# class from database table
--from SO and changed according to the comments: http://stackoverflow.com/questions/5873170/generate-class-from-database-table
declare @TableName sysname = 'Bilplats'
declare @Result varchar(max) = 'public class ' + @TableName + '
{'
select @Result = @Result + '
public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }
'
from
@OskarKlintrot
OskarKlintrot / custom.d.ts
Created June 7, 2017 13:31
TinyMCE with SSR and webpack
interface NodeRequire {
ensure: (paths: string[], callback: (require: NodeRequireFunction) => void) => void
}
private static void SaveChanges(DbContext context)
{
try
{
context.SaveChanges();
}
catch (DbEntityValidationException exception)
{
var sb = new StringBuilder();
foreach (var failure in exception.EntityValidationErrors)