Skip to content

Instantly share code, notes, and snippets.

View sepeth's full-sized avatar

Sepeth sepeth

  • Cape Town, South Africa
View GitHub Profile
@sepeth
sepeth / useCallbackOnce.ts
Last active September 23, 2020 08:06
Gives you a func that you can call once. It is for React.
import {DependencyList, useCallback, useRef} from "react";
interface AnyFn<ReturnType> {
(...args: any[]): ReturnType;
}
/** Gives you a func that you can call once.
*
* It will store the return value of the original call, and return that for subsequent calls.
* This is true even when the deps change.
@sepeth
sepeth / use-profile
Last active July 12, 2021 15:42
Lets you pass your AWS CLI profile credentials to another program as environment variables
#!/usr/bin/env python3
# Say you have a NodeJS program that uses AWS.EnvironmentVariables,
# and you want to call that with different profiles you have:
#
# use-profile <profile> node your-script.js
import os
import sys
from configparser import ConfigParser
@sepeth
sepeth / words.py
Created September 24, 2013 07:31
"Python" as an Alternative to Java - http://www.norvig.com/java-lisp.html
# "Python" as an Alternative to Java.
#
# Given a list of words and a list of phone numbers,
# find all the ways that each phone number can be
# expressed as a list of words.
# http://www.flownet.com/ron/papers/lisp-java/
#
# Here, you can find Peter Norvig's solution in CL:
# http://www.norvig.com/java-lisp.html
#