Skip to content

Instantly share code, notes, and snippets.

View fritzy's full-sized avatar
💽
Please Insert Disk III

Nathan Fritz fritzy

💽
Please Insert Disk III
  • Kennewick, WA
  • 18:11 (UTC -07:00)
  • X @fritzy
View GitHub Profile
@fritzy
fritzy / nodewebcrypto.js
Created April 13, 2018 21:20
Test of node-webcrypto-ossl
const RSA = { name: 'RSASSA-PKCS1-v1_5' };
const testValue = 'I am the very model of a modern major general.';
const testValue2 = 'I am the very model of a modern majr general.';
//if browser, uses window.crypto, if node wraps openssl
const WebCrypto = require('node-webcrypto-ossl');
const crypto = new WebCrypto();
(async () => {
console.log('generating key');
@fritzy
fritzy / keybase.md
Created January 23, 2018 01:32
keybase.md

Keybase proof

I hereby claim:

  • I am fritzy on github.
  • I am fritzy (https://keybase.io/fritzy) on keybase.
  • I have a public key ASCnN0TAG8SqzlRfVWz9_usucplgGZjT_Nxuf0lzAMzcWAo

To claim this, I am signing this object:

@fritzy
fritzy / 1unique_short_id.sql
Last active September 15, 2017 17:43
Fight the German Tank Problem in Postgresql with short, unique, url-safe ids.
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-- Create a trigger function that takes no arguments.
-- Trigger functions automatically have OLD, NEW records
-- and TG_TABLE_NAME as well as others.
CREATE OR REPLACE FUNCTION unique_short_id()
RETURNS TRIGGER AS $$
-- Declare the variables we'll be using.
DECLARE
@fritzy
fritzy / checkpassword.lua
Created November 7, 2013 20:14
Set password as sha1 hash and check password against hash.
--EVAL "this script" 1 key userid password
local key = KEYS[1];
local userid, pass = unpack(ARGV);
local hash = redis.sha1hex('SOME-STATIC-SALT'..string.sub(pass, 1, 2)..userid..string.sub(pass, 3));
--no error, does hash match?
return {false, (redis.call('GET', key) == hash)}
@fritzy
fritzy / updatekeyandlookup.lua
Created November 13, 2013 23:12
Update a key and lookup for a specific root level JSON attribute.
--EVAL "this script" 2 key lookup jsonvalue attribute
local key, lookup = unpack(KEYS);
local jsonvalue, attribute = unpack(ARGV);
local value = cjson.decode(jsonvalue);
local oldvalue = redis.call('GET', key);
--if this key was set before, remove the old lookup
if type(oldvalue) == 'string' then
oldvalue = cjson.decode(oldvalue);
@fritzy
fritzy / updatesendnotice.lua
Last active April 19, 2017 21:10
Update a key, send out a notice, and log the notice.
--2 key changelog update millisecond-epoch
local key, changelog = unpack(KEYS);
local update, epoch = unpack(ARGV);
local result = redis.call('SET', key, update);
local notice = cjson.encode({key = key, value = update, time = epoch});
redis.call('ZADD', changelog, epoch, notice);
redis.call('ZREMRANGEBYSCORE', changelog, '-inf', epoch - 86400000);
@fritzy
fritzy / pushmaxlist.lua
Last active April 19, 2017 21:07
Appending to a Redis List, deleting entries to the left past a maximum size.
--EVAL "this script" 1 key_name new_item max_size
local key = KEYS[1];
local item, max = unpack(ARGV);
redis.call('RPUSH', key, item);
redis.call('LTRIM', key, -max, -1);
@fritzy
fritzy / collate.lua
Last active April 19, 2017 20:55
Collate a Hash in Redis
--EVAL "this script" 1 some-hash-key
local key = KEYS[1];
local keyvalues = redis.call('HGETALL', key);
local result = {};
--every other value is a key
for idx = 1, #keyvalues, 2 do
result[keyvalues[idx]] = keyvalues[idx + 1]
end
@fritzy
fritzy / changes_and_workarounds.md
Last active December 15, 2016 22:20
2016 Dell XPS 13 9360 Developer Edition

Upgrade to Linux 4.8

apt-cache search linux | grep 4.8

apt-get install linux-image-4.8xxxxx linux-extras-4.8xxxx linux-headers-4.8.x-xxxx

I used 4.8.0-30-generic flavors of all of those.

linux-image-4.8.0-30-generic - Linux kernel image for version 4.8.0 on 64 bit x86 SMP

#!/usr/bin/env node
// ./generatelookup -l lookupkey -p somekey* -a attribute
var redis = require('redis').createClient();
var async = require('async');
var opt = require('optimist');
opt.usage('$0 -l lookup -p pattern -a attribute');
opt.demand(['l', 'p', 'a']);
var argv = opt.argv;
var iter = '0';