Skip to content

Instantly share code, notes, and snippets.

@brampersandon
brampersandon / use-async.tsx
Last active November 1, 2023 11:53
Common hooks I use everywhere but don't want to install
import { useState, useCallback } from "react";
type AsyncStatus = 'notasked' | 'loading' | 'success' | 'error';
// from https://usehooks.com/useAsync/
export const useAsync = <T, E = string>(
asyncFunction: (...args: any[]) => Promise<T>,
) => {
const [status, setStatus] = useState<AsyncStatus>('notasked');
const [value, setValue] = useState<T | null>(null);
@brampersandon
brampersandon / monitor.js
Created December 1, 2020 00:48
Basic process monitor
const { spawn } = require("child_process");
const COMMAND = "ls"
const ALLOWED_REBOOTS = 10
async function main() {
console.log("Starting process");
let counter = 0;
let failed = false;
let handle;
@brampersandon
brampersandon / clean-react-native-app.sh
Last active January 7, 2019 15:43
A quick helper util for getting a misbehaving React Native environment back to normal.
alias clean-rn="watchman watch-del-all && rm -fr $TMPDIR/npm* && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && yarn cache clean && rm -rf ios/build && rm -rf ios/Pods && rm -rf android/.gradle && rm -rf android/.idea && rm -rf android/build && rm -rf android/app/build && rm -rf android/app/app.iml && yarn"

Keybase proof

I hereby claim:

  • I am skylineproject on github.
  • I am brandon_mn (https://keybase.io/brandon_mn) on keybase.
  • I have a public key ASDrbMBmaLAJrk4PSMKarjIQAuko3bnt5Owwwv-u1hb5MAo

To claim this, I am signing this object:

@brampersandon
brampersandon / docker-compose.example.yml
Created August 9, 2016 01:18
Docker Compose is Cool!
nginx:
build: ./loadbalancer
links:
- api
- messenger
ports:
- "80:80"
- "443:443"
api:
build: ./api
@brampersandon
brampersandon / app.js
Last active April 6, 2016 03:42
Tweet about Apple devices that are coming your way.
var shipit = require('shipit');
var Twit = require ('twit');
var thingToTrack = 'YOUR TRACKING NUMBER HERE';
var ups = new shipit.UpsClient({
licenseNumber: 'LICENSE',
userId: 'USERNAME',
password: 'PASSWORD'
});
@brampersandon
brampersandon / README.md
Last active January 13, 2016 11:03
SOTU.rb: a quick method to tweet and text hot-takes simultaneously

SOTU.rb

My friend was stuck without an internet connection during this year's State of the Union. I wanted to make sure we could all share our hot takes and direct quotes with them, so I made this 'lil distribution channel in the ten minutes before the speech.

I wrote these docs, and this script, in a total of ten minutes. It may be a bit rough. I'll be making updates to simplify and clarify in a few minutes. If you have any questions, leave a comment on the Gist, or get at me on Twitter -- I'm glad to help!

APIs used

For SMS messaging, I used the awesome Twilio SMS APIs. To post to Twitter, I used the one, the only Twitter API.

To use

@brampersandon
brampersandon / getKhan.sh
Created January 1, 2015 19:52
Download the Internet Archive's KhanAcademyVideos torrent, and then run this script to convert things. See http://brndn.xyz/khan for more info.
function getKhan() {
for i in *; do
if [ -d $i ]; then
echo "$i"
(cd $i; getKhan)
fi
if [[ $i =~ \.7z$ ]]; then
7z x $i
fi
if [[ $i =~ \.flv$ ]]; then