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; |
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; |
View calendar.css
.day { | |
fill: #fff; | |
stroke: #ccc; | |
} | |
.month { | |
fill: none; | |
stroke-width: 2px; | |
} |
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 |
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); |
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 |
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 . |
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); |
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', |
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'); |
NewerOlder