Skip to content

Instantly share code, notes, and snippets.

@ngbrown
ngbrown / generate-fontawesome-icons.js
Created December 21, 2023 02:42
Generate TypeScript files containing Font Awsome Icons from kit metadata
#!/usr/bin/env node
/* eslint-env node */
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
async function main() {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@ngbrown
ngbrown / use-dynamic-throttle.ts
Last active August 19, 2023 17:10
useDynamicThrottle React hook
import { useCallback, useEffect, useRef, useState } from "react";
/**
* Returns a throttled version of the value and a function to release the next update, which may occur immediately or
* on the next value change.
*
* This can be used to keep the interface responsive when you have values that are changing too fast for async processes to keep up.
* @param value The value that is going to be throttled
*/
export function useDynamicThrottle<T>(
@ngbrown
ngbrown / uplot-react.tsx
Last active August 11, 2023 08:47
Updated uplot-react
// Adapted from https://github.com/skalinichev/uplot-wrappers
// MIT license
import type { JSX } from "react";
import React, { useCallback, useEffect, useRef } from "react";
import uPlot from "uplot";
import { dataMatch, optionsUpdateState } from "./uplot-wrappers-common.js";
export default function UplotReact({
@ngbrown
ngbrown / hash-code.js
Last active November 30, 2023 16:28
Print CSP Hash
function _arrayBufferToBase64(buffer) {
let binary = '';
const bytes = new Uint8Array(buffer);
for (var i = 0; i < bytes.byteLength; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
function getCspDigest(code) {
crypto.subtle.digest('SHA-256', new TextEncoder().encode(code)).then(function(val){
@ngbrown
ngbrown / Export-Files-Csv.ps1
Created May 3, 2023 20:32
Export list of files with PowerShell
Get-ChildItem "\\?\C:\*.*" -Recurse | Select-Object FullName,LastWriteTime,Length | Export-Csv "$([Environment]::GetFolderPath("Desktop"))\File-Listing.csv" -NoTypeInformation
@ngbrown
ngbrown / background.js
Created February 15, 2023 06:01
CSP Nonce by extension
async function getCurrentTab() {
let queryOptions = { active: true, lastFocusedWindow: true };
// `tab` will either be a `tabs.Tab` instance or `undefined`.
let [tab] = await chrome.tabs.query(queryOptions);
return tab;
}
function reddenPage() {
document.body.style.backgroundColor = 'red';
const nonce = [...document.getElementsByTagName("script")].find(x => x.nonce)?.nonce;

cryptosi: Hi guys, looking to convince my company to use Remix but need some compelling arguments. This new project is definitely a good use case so I want to be able to articulate why we should use Remix. I've been doing my own research but wanted to reach out here to see if anyone had resources they might use for me to read and compile a list of reasons to use remix.

From purpler:

  • helped me avoid needing a graphql layer between my frontend and prisma

From Julienng:

  • simpler model than next : no isr, & all : it's easier to explain to new developer
  • simpler form than anything in the react world when you don't need anything fancy, and you can still do fancy stuff when needed
  • auto reload of loader when an action is fired : bye bye refreshListeners on parents for us and reloadPage() callback 😅
@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
@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 / 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"