Skip to content

Instantly share code, notes, and snippets.

View fictorial's full-sized avatar

Brian Hammond fictorial

View GitHub Profile
@fictorial
fictorial / .vimrc
Last active November 11, 2021 19:22
switch vim color scheme to match iterm profile
" 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
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:
@fictorial
fictorial / example.js
Last active April 2, 2019 16:26
express "middleware" after request handling
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");
@fictorial
fictorial / encode_decode_hmac.js
Created April 1, 2019 19:03
encode / decode with hmac for node.js
// 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);
@fictorial
fictorial / install_js_packages.sh
Last active March 27, 2019 20:26
Install Node.js packages from NPM for any referenced package in JavaScript under current directory
#!/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)
@fictorial
fictorial / time_diff_in_words.sql
Last active June 21, 2018 13:50
time difference in words for postgres
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;
@fictorial
fictorial / emptyIfNil.swift
Created September 8, 2017 14:40
empty if nil
extension Optional where Wrapped == String {
var nilIfEmpty: String? {
guard let strongSelf = self else {
return nil
}
return strongSelf.isEmpty ? nil : strongSelf
}
}
@fictorial
fictorial / app.js
Created July 2, 2015 14:24
Clara.io issue w.r.t. THREE.js import and spotlights
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);
@fictorial
fictorial / autoreload.py
Last active August 29, 2015 14:08
autoreload
#!/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]
@fictorial
fictorial / acks_acks.txt
Created October 31, 2014 12:52
Please do not ACK my ACKs!
Please do not ACK my ACKs!
I already have stacks and stacks!
If you would be so kind, offer me some pork rind.
You see, I prefer snacks, not ACKs!
I have a yak. His name is Jack.
And when he walks, Jack makes tracks.
I follow his tracks to stacks of snacks.
But when you ACK my ACKs, all I see are stacks of ACKs.
I cannot see Jack's yak tracks!