Skip to content

Instantly share code, notes, and snippets.

View dantman's full-sized avatar

Daniel Friesen dantman

View GitHub Profile
@dantman
dantman / aws-vault-sync-import.py
Created December 18, 2022 01:18
Utility for syncing credentials in WSL between aws-vault.exe and a Keepass database
import os, sys, re, shutil
from subprocess import check_call, CalledProcessError
AWS_VAULT_EXE = shutil.which('aws-vault.exe')
def process_entry(pw_entry):
if 'E' in pw_entry:
print(pw_entry['E'])
sys.exit(1)
if 'OK' in pw_entry:
@dantman
dantman / README.md
Created June 15, 2022 04:42
Test Page for of ES modules usage with nullish coalescing

Test Page for of ES modules usage with nullish coalescing

TestCafe's proxy breaks nullish coalescing. This is a basic demo using the syntax for a test case.

@dantman
dantman / gist:dd48cef249d82353d37276d955a37a34
Last active December 23, 2021 03:41
Basic TypeScript friendly validate/cast function based validation library experiment
import Axios, { AxiosError } from "axios";
// Casting/validation library
class DataInputError extends Error {
path: string[] = [];
static isDataInputError(error: unknown): error is DataInputError {
return error ? error instanceof DataInputError : false;
}
@dantman
dantman / awaitPromise.ts
Created February 17, 2021 03:17
A hook that takes a promise and throws it according to the Suspense API
interface PromiseCachePending {
promise: Promise<void>;
}
interface PromiseCacheResolved<T> {
promise: Promise<void>;
result: T;
}
interface PromiseCacheError {
promise: Promise<void>;
error: any;
@dantman
dantman / check_nvm_latest.sh
Created January 20, 2021 23:11
bashrc script used for checking for out of date nvm versions of node
#!/bin/bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
TAG="$1"
if [ -z "$TAG" ]; then
echo "Tag not specified"
exit 1
fi
@dantman
dantman / wsl-git-credential-manager.sh
Created January 20, 2021 05:19
WSL Bash script that makes the Linux `git` use the same Windows based credential manager as the host system's git.exe
echo "Setup WSL's Git to use the same credential manager that the Windows git.exe is using"
GIT_CREDENTIAL_MANAGER_CORE_EXE=$(wslpath "$(git.exe config --global --get credential.helper | sed 's/\\\(\s\)/\1/g')" | sed 's/\(\s\)/\\\1/g')
git config --global credential.helper "$GIT_CREDENTIAL_MANAGER_CORE_EXE"
@dantman
dantman / context.js
Created March 22, 2019 02:21
React context slice idea
MyContext.slice(value => value.foo);
const KeyContext = useMemo(() => MyContext.slice(value => value[key]), [key])
const keyValue = useContext(KeyContext);
const KeyContext = useMemo(() => MyContext.slice(value => value[key]), [key])
return <KeyContext.Consumer>{keyValue => keyValue}</KeyContext.Consumer>
@dantman
dantman / useId.js
Created January 23, 2019 06:54
A simple hook that returns a unique ID (locally unique and good for dynamic id attributes; not SSR safe)
import warning from 'warning';
import { useState } from 'react';
let idCounter = 0;
function nextId() {
idCounter += 1;
warning(
idCounter < 1e10,
'Id: you might have a memory leak.' +
'The idCounter is not supposed to grow that much.'
@dantman
dantman / Id.js
Created January 23, 2019 06:40
Render prop component that returns a unique id
import warning from 'warning';
import { Component } from 'react';
let idCounter = 0;
function nextId() {
idCounter += 1;
warning(
idCounter < 1e10,
'Id: you might have a memory leak.' +
'The idCounter is not supposed to grow that much.'
@dantman
dantman / .babelrc
Last active August 28, 2018 00:03
Demonstration of the "Duplicate declaration" error in Babel.
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": 8
}
}
]