Skip to content

Instantly share code, notes, and snippets.

@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;
@ngbrown
ngbrown / RandData.cs
Created June 18, 2010 16:14
C# UnitTest Helpers
namespace UnitTestHelpers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
/// Provides random test data
/// </summary>

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 / FormatterExtensions.cs
Last active June 9, 2022 10:04
NancyFX PartialFileResponse
using System;
using System.IO;
using Nancy;
namespace WebService.Extensions
{
public static class FormatterExtensions
{
public static Response AsPartialFile(this IResponseFormatter formatter, string applicationRelativeFilePath, string contentType)
{
@ngbrown
ngbrown / ArrayHelpers.cs
Created June 18, 2010 15:56
C# Extension Methods
namespace Helpers
{
using System;
/// <summary>
/// A static class of extension methods for <see cref="Array"/>.
/// </summary>
public static class ArrayHelpers
{
/// <summary>
@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 / 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 / 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"
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;