This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create-venv() { | |
name=$(basename $PWD) | |
venv_path="$HOME/.venvs/$name" | |
if [ -d "$venv_path" ]; then | |
echo "$venv_path already exists" | |
return | |
fi | |
python3 -m venv "$venv_path" | |
source "$venv_path/bin/activate" | |
pip install --upgrade pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" If we're using iterm2 (OS X), check if there's a colorscheme in vim matching the iterm2 profile name. | |
" If the profile name has suffix " - light" then set bg=light else bg=dark. | |
" If we're not using iterm2, based on the time of day, pick a colorscheme light (day) vs dark (night). | |
" I like the yin and yang colorschemes for vim and iterm2: https://github.com/pgdouyon/yin-yang | |
" So I have a profile in iterm2 named "yang - light" and "yin - dark". | |
" Note: iterm2 does not _update_ the env var ITERM_PROFILE after _changing_ the profile, just on launch. | |
" You'll have to `source ~/.vimrc` after changing the iterm2 profile or if not running vim, launch it. | |
let itermprofile = system("osascript -e 'tell application \"iTerm2\"\nget profile name of current session of current window\nend tell'") | |
try |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
counts = dict() | |
for root, dirs, files in os.walk(sys.argv[1]): | |
for filename in files: | |
full_path = os.path.join(root, filename) | |
base, ext = os.path.splitext(full_path) | |
if len(ext) == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
app.use((req, res, next) => { | |
res.once("finish", () => { | |
console.log("finish"); | |
}); | |
next(); | |
}); | |
app.get("/", (req, res) => { | |
console.log("in get"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// note: encoded data is NOT encrypted | |
const crypto = require('crypto'); | |
const secret = '20BBEBB8-DCC1-4544-AD32-7F3973CCED7A'; | |
function createDigest(encodedData, format) { | |
return crypto | |
.createHmac('sha256', secret) | |
.update(encodedData) | |
.digest(format); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
trap 'rm -f .all .used' 0 1 2 3 6 9 15 | |
curl -s https://raw.githubusercontent.com/sindresorhus/builtin-modules/master/builtin-modules.json | jq -c '.[]' | sed -e 's/"//g' > .all | |
ack --js -h "require\('([^']+)'" --output '$1' | egrep -v '^\.' | sort -u > .used | |
npm i -S $(grep -Fvxf .all .used) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function time_diff_in_words( | |
a timestamp with time zone, | |
b timestamp with time zone | |
) returns text as $$ | |
declare | |
_age interval; | |
_suffix text; | |
_years integer; | |
_months integer; | |
_days integer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Optional where Wrapped == String { | |
var nilIfEmpty: String? { | |
guard let strongSelf = self else { | |
return nil | |
} | |
return strongSelf.isEmpty ? nil : strongSelf | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var scene, camera, renderer; | |
$(function () { | |
renderer = new THREE.WebGLRenderer(); | |
renderer.setPixelRatio(window.devicePixelRatio); | |
renderer.setSize(window.innerWidth, window.innerHeight); | |
renderer.shadowMapEnabled = true; | |
document.body.appendChild(renderer.domElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from os.path import getmtime | |
import sys, subprocess, time | |
import signal | |
usage = 'usage: autoreload "/bin/foo --bar" *.py' | |
try: | |
cmd = sys.argv[1] |
NewerOlder