Skip to content

Instantly share code, notes, and snippets.

View fictorial's full-sized avatar

Brian Hammond fictorial

View GitHub Profile
@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 / .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
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAvlaG3xvlRyrdeL3QDXE7F514jx87ed5kh80BLoOntY2qESvM/2iT
NDCmmWqPvloIogdBRRmeU6UcdOKmbXyMcTzk0d5Aj1LagKeZsC8J+eWD4Hbw0lMU
w17WlwATmgQnpuh1Yb+FKwg8sM4SVZSUjMfkiLfob7yiofQnhkMrMj/f3OQl8eVs
f0ciDvLGFLdPJ5omwM6MfAcwyNAtUAW3hRwCgTYhbSqzA+cOYyjV3GmgojRvwfy2
H84L2c/IBSOwe3ZtyADTw7NVx29GQqFhVD6SnWFnfoOpOxddfM5qtgId+1+w7/+n
DZjzMzBwyfXSiTd3uh2Dwnyz3FevWZH4ywIDAQAB
-----END RSA PUBLIC KEY-----
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 / 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 / YAHTZEE.BAS
Created October 10, 2012 16:37
YAHTZEE.BAS
'--------------------------
' Yahtzee Version 1.1
' Brian Hammond
' Finished: June 25, 1995
' Coded in: MS-QBasic 7.1
'--------------------------
'Initial Setup-------------------------------------------------------------
'make arrays static by usage of a MetaCommand (needs the comment)
@fictorial
fictorial / gist:3248414
Created August 3, 2012 15:00
dismiss keyboard from anywhere
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];