Skip to content

Instantly share code, notes, and snippets.

View use-debounced-value.ts
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 / NHibernateMicrosoftLoggerFactory.cs
Last active Aug 14, 2020
NHibernate to MicrosoftLogger Factory
View NHibernateMicrosoftLoggerFactory.cs
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;
@ngbrown
ngbrown / calendar.css
Created Aug 3, 2020 — forked from AndyCross/calendar.css
How the Calendar Visual might look in a few files
View calendar.css
.day {
fill: #fff;
stroke: #ccc;
}
.month {
fill: none;
stroke-width: 2px;
}
@ngbrown
ngbrown / BlurImg.tsx
Last active Apr 2, 2021 — forked from WorldMaker/use-blurhash.ts
useBlurhash hook
View BlurImg.tsx
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 / Program.cs
Last active Apr 3, 2020 — forked from DanielSWolf/Program.cs
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
View Program.cs
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 / AuthProvider.tsx
Last active Jan 1, 2021
useAuth React authentication with oidc-client
View AuthProvider.tsx
import React, {
createContext,
useReducer,
useEffect,
useState,
useContext,
} from 'react';
import * as Oidc from 'oidc-client';
// Inspired by https://github.com/Swizec/useAuth
@ngbrown
ngbrown / ResetRDPCertToLetsEncrypt.ps1
Created Oct 17, 2019
Reset RDP Cert To Let's Encrypt
View ResetRDPCertToLetsEncrypt.ps1
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 / check_used_characters.sql
Last active Jul 18, 2019
Check used characters
View check_used_characters.sql
-- Based on https://stackoverflow.com/a/2926213/25182
WITH a AS (SELECT LTRIM(dut_eosonum) AS s, '' AS x, 0 AS n
FROM dbo.[dutmast]
WHERE LEN(dut_eosonum)>0
UNION ALL
SELECT a.s, SUBSTRING(a.s, n+1, 1) AS x, n+1 AS n FROM a WHERE n<LEN(a.s))
SELECT x, COUNT(*) AS c FROM a WHERE n>0 GROUP BY x ORDER BY x
OPTION(MAXRECURSION 0);
@ngbrown
ngbrown / ApolloLoggingExtension.ts
Created Mar 29, 2019
Custom logging in Apollo Server 2 using the extension API
View ApolloLoggingExtension.ts
import {GraphQLExtension, GraphQLResponse} from 'graphql-extensions';
import {formatApolloErrors} from 'apollo-server-errors';
import {GraphQLError, GraphQLFormattedError} from 'graphql';
import Logger from 'bunyan';
import icepick from 'icepick';
const filterOutErrorPaths = [
['extensions', 'exception', 'options', 'auth', 'bearer'],
[
'extensions',
@ngbrown
ngbrown / bunyan-format.js
Last active Jan 17, 2019
bunyan-format for node
View bunyan-format.js
'use strict';
const util = require('util');
const format = util.format;
const http = require('http');
const chalk = require('chalk');
const stream = require('stream');
const _merge = require('lodash/merge');
const _get = require('lodash/get');