Skip to content

Instantly share code, notes, and snippets.

@ngbrown
ngbrown / ResetRDPCertToLetsEncrypt.ps1
Created October 17, 2019 20:44
Reset RDP Cert To Let's Encrypt
Write-Host Clear security certificates. Removes SSLCertificateSHA1Hash from the registry.
$name = 'SSLCertificateSHA1Hash'
$path = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp'
Remove-ItemProperty -Path $path -Name $name -ErrorAction SilentlyContinue
Set-ItemProperty -Path $path -Name 'MinEncryptionLevel' -Value 1
Set-ItemProperty -Path $path -Name 'SecurityLayer' -Value 0
Remove-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet001\Control\Terminal Server\WinStations\RDP-Tcp' -Name $name -ErrorAction SilentlyContinue
Remove-ItemProperty -Path 'HKLM:\SYSTEM\ControlSet002\Control\Terminal Server\WinStations\RDP-Tcp' -Name $name -ErrorAction SilentlyContinue
Write-Host Clear security certificates. Set SSLCertificateSHA1Hash to .
@ngbrown
ngbrown / AuthProvider.tsx
Last active June 18, 2021 09:24
useAuth React authentication with oidc-client
import React, {
createContext,
useReducer,
useEffect,
useState,
useContext,
} from 'react';
import * as Oidc from 'oidc-client';
// Inspired by https://github.com/Swizec/useAuth
@ngbrown
ngbrown / Program.cs
Last active April 3, 2020 03:32 — forked from DanielSWolf/Program.cs
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
using System;
using System.Threading;
static class Program {
static void Main() {
Console.Write("Performing some task... ");
using (var progress = new ProgressBar()) {
for (int i = 0; i <= 100; i++) {
progress.Report((double) i / 100);
@ngbrown
ngbrown / BlurImg.tsx
Last active January 14, 2025 08:35 — forked from WorldMaker/use-blurhash.ts
useBlurhash hook
import React, { useState, useCallback } from "react";
import { useBlurhash } from "./use-blurhash";
import { useInView } from "react-intersection-observer";
type Props = React.DetailedHTMLProps<
React.ImgHTMLAttributes<HTMLImageElement>,
HTMLImageElement
> & { blurhash?: string | null };
// Uses browser-native `loading="lazy"` to lazy load images
@ngbrown
ngbrown / calendar.css
Created August 3, 2020 04:54 — forked from AndyCross/calendar.css
How the Calendar Visual might look in a few files
.day {
fill: #fff;
stroke: #ccc;
}
.month {
fill: none;
stroke-width: 2px;
}
@ngbrown
ngbrown / NHibernateMicrosoftLoggerFactory.cs
Last active August 14, 2020 21:06
NHibernate to MicrosoftLogger Factory
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using NHibernate;
namespace App.Infrastructure
{
public class NHibernateMicrosoftLoggerFactory : INHibernateLoggerFactory
{
private readonly Microsoft.Extensions.Logging.ILoggerFactory loggerFactory;
import {useEffect, useRef, useState} from 'react';
import {debounce} from 'lodash';
export function useDebouncedValue<V>(value: V, wait: number) {
const [debouncedValue, setDebouncedValue] = useState(value);
const debounceRef = useRef<typeof setDebouncedValue>();
useEffect(() => {
const debounceFn = debounce(setDebouncedValue, wait);
debounceRef.current = debounceFn;
@ngbrown
ngbrown / Generate-SyncCerts.ps1
Created April 27, 2021 23:16
Download root certs for offline computer
certutil -syncwithwu -f -f .\certs
$certFiles = Get-ChildItem "$PSScriptRoot\certs\*.crt"
$certCommands = $certFiles | %{'certutil -addstore root "%~dp0certs\' + $_.Name + '"'}
extrac32 /Y .\certs\authrootstl.cab .\certs\authroot.stl
extrac32 /Y .\certs\disallowedcertstl.cab .\certs\disallowedcert.stl
extrac32 /Y .\certs\pinrulesstl.cab .\certs\pinrules.stl
$outputCmdPath = "$PSScriptRoot\update-certs.cmd"
@ngbrown
ngbrown / lint-eol-history.py
Created May 8, 2021 19:59
Filter for git-filter-repo to convert all text files to LF line endings, for example after a Mercurial conversion
#!/usr/bin/env python3
"""
This is a simple program that will run a linting program on all non-binary
files in history. It also rewrites commit hashes in commit messages to
refer to the new commits with the rewritten files.
See https://github.com/newren/git-filter-repo/issues/45
and https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/lint-history
"""
@ngbrown
ngbrown / LineDelimitedProgram.cs
Last active September 3, 2021 17:28
Line delimited json de-serializing with .NET 5
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipelines;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program