Skip to content

Instantly share code, notes, and snippets.

@karlrwjohnson
karlrwjohnson / RewrapLineCommand.py
Last active February 26, 2017 01:26
Sublime plugin that re-wraps plain text so it just fits under 80 characters. Supports indented blocks, too!
# Sublime plugin that re-wraps text blocks so that each line contains the
# maximum number of characters before line 80
# To install (Sublime 3?), find your Packages/User directory by going to
# Preferences Menu > Browse Packages...
#
# Save this file into that directory.
#
# To enable it in the [Ctrl+Shift+P] command palette, create a file called
# "mine.sublime-commands" (exact name before extension doesn't matter),
@karlrwjohnson
karlrwjohnson / message_queue_demo.py
Created November 7, 2017 22:41
PostgreSQL Message Queue Demo
'''
Postgres automatic message queue demo
Wherein a record-insertion trigger notifies a worker to process new table records
Requires:
- Python 3.6
- Postgres 9.6
- Psycopg2
Usage:
@karlrwjohnson
karlrwjohnson / generate_pinch_pot.py
Created December 22, 2017 06:02
Procedural STL file generation in Python
import functools
import numpy
import struct
import svg.path # pip install svg.path==2.2
from typing import List, Dict, Tuple, Callable # kitchen sink?
array=numpy.array
# SVG <path> string describing the undistorted profile of the pot
PATH_DATA='''
m 0,50.916666 9.1801683,0 c 0.8686257,-1.2561 2.0631007,-1.983971 3.2272117,-2.612425 6.345522,-3.425674 6.113453,-5.441741 9.183746,-10.130426 3.920877,-5.987623 6.247456,-11.575049 11.615424,-15.913572 1.361948,-1.10076 2.477231,0.565914 1.236122,1.532279 -5.445873,4.240321 -7.508074,9.124891 -11.047477,15.345625 C 20.372917,44.45 19.05,46.566667 12.975328,49.970155 11.821211,50.616778 10.583333,51.59375 10.583333,52.916667 L 0,52.916667
@karlrwjohnson
karlrwjohnson / Lodash FP.md
Last active February 27, 2018 16:17
Lodash FP Proposal

Lodash FP Proposal

Premises

  • Immutable: All functions return a copy of the data instead of modifying it. Even functions which normally mutate data, like _set, are wrapped to make a copy first.
@karlrwjohnson
karlrwjohnson / cycles.py
Last active May 1, 2018 03:27
Solution to Adam Babcock's brain-teaser
'''
Solution to Adam Babcock's brain-teaser
Here's the basic gist of the problem: A principal places one hundred students'
names into one hundred identical boxes, which are sitting in a row in the principal's
office. Each box contains exactly one name, but the names are not guaranteed to
be arranged in any particular order within those boxes.
Students are called in one at a time and are permitted to open up to fifty of
those boxes. If one of the boxes they open contains their name, they get a reward.
@karlrwjohnson
karlrwjohnson / pattern.java
Created October 19, 2018 14:44
Action pattern for turn-based games
// Let's define a couple of dependencies to get started.
interface GameContext {
// Methods which Actions can use to query the state of the game
}
interface ActionGameController {
// Methods which Actions can use to affect the game
// - In Redux, this is the dispatch() method and various actionCreators.
// - In Java, this is a controller.
@karlrwjohnson
karlrwjohnson / Show_nav_labels_in_bitbucket.js
Created November 26, 2018 16:05
Show navbar links in BitBucket (Greasemonkey script)
// ==UserScript==
// @name Show nav labels in Bitbucket
// @version 0.1
// @description Add labels below icons on the left nav bar
// @match (insert URL of bitbucket server)
// @grant none
// ==/UserScript==
console.log('user script loaded');
(function() {
@karlrwjohnson
karlrwjohnson / Taylor Cardsmith.txt
Created January 14, 2019 18:54
Taylor Cartsmith
Beastsoul Monk 1 / Armored & Gifted Blade (Soulknife) 4
STR 10 = ( 0p) 10
DEX 14 = ( 5p) 14
CON 14 = ( 5p) 14
INT 8 = (-2p) 8
WIS 20 = (17p) 18 + (Hu) 2
CHA 10 = ( 0p) 10
Level 1: Beastsoul Monk 1
@karlrwjohnson
karlrwjohnson / httpProxy.js
Created February 19, 2019 22:44
Quickie proxy that logs requests while forwarding to another service
const http = require('http');
const destHost = 'localhost';
const destPort = 4002;
http.createServer((req, res) => {
console.log(`> ${req.method} ${req.url}`);
for (let k in req.headers) {
console.log(`> ${k} = ${req.headers[k]}`)
}
@karlrwjohnson
karlrwjohnson / In-SQL Rules Engine Demo.sql
Created September 13, 2017 20:56
In-SQL Rules Engine Demo
---------------------------------------------------------
-- Boilerplate mocking out what we already have today. --
-- Just scroll down to the bottom. --
---------------------------------------------------------
-- Cleanup
drop table if exists
import_log,
my_data_source,
meta_record,