Skip to content

Instantly share code, notes, and snippets.

View jelder's full-sized avatar

Jacob Elder jelder

View GitHub Profile
import hashlib
class NodeColor:
"""
Assign a random but deterministic color to a string, suitable for coloring a graph.
"""
def __init__(self, tag):
self.hue = self.__get_hue(tag)
@jelder
jelder / email.sql
Created March 12, 2015 17:06
Filtering emails by domain in PostgreSQL
BEGIN;
CREATE FUNCTION email_domain(email text) RETURNS text
LANGUAGE sql IMMUTABLE
AS $$
SELECT reverse(split_part(lower(email), '@', 2))
$$;
CREATE INDEX idx_users_email_domain ON users (email_domain(email));
EXPLAIN ANALYZE SELECT "users".* FROM "users" WHERE email_domain(email) = 'moc.sseldnuob' ORDER BY "users"."proposed_changes_count" DESC;
ROLLBACK;
@jelder
jelder / iteration.rb
Last active November 28, 2020 19:24
The difference between `for` and `each` in Ruby: scope.

for should only be used when you actually want the iteratee to be accessible after you leave the block. for pollutes the parent scope with old iteratees. For this reason, each should be your default.

@jelder
jelder / crossdomain.vcl
Created July 28, 2010 12:23
Example of serving static files from Varnish.
sub vcl_recv {
if (req.url == "/crossdomain.xml") {
error 843 "OK";
}
}
sub vcl_error {
if (obj.status == 843) {
set obj.status = 200;
set obj.http.Content-Type = "application/xml; charset=utf-8";
@jelder
jelder / ChromeFullscreen.applescript
Created December 9, 2011 22:24
AppleScript to launch Chrome in Presentation mode (Fullscreen)
# url.txt should contain the URL load in Chrome in full screen.
do shell script "open '/Applications/Google Chrome.app' " & readFile("/url.txt")
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "f" using {command down, shift down}
end tell
# All this just to read a file; no backticks in AppleScript.
on readFile(unixPath)
@jelder
jelder / haproxy.cfg
Created March 15, 2011 15:01
An HA Proxy configuration for putting various APIs behind a single whitelistable IP address.
global
description prod
maxconn 7777 # About 54k per connection; 400MB free on this machine.
stats socket /var/run/haproxy.stat mode 600 level admin
user haproxy
group haproxy
defaults
mode http
maxconn 7700 # Should be slightly smaller than global.maxconn.
@jelder
jelder / .my.cnf
Last active November 9, 2018 13:04
My ~/.psqlrc
[mysql]
prompt=\\d mysql>\_
auto-vertical-output=true
@jelder
jelder / get_lambda_request
Created October 31, 2018 16:20
Find logs for a single Lambda invocation and report timing data
#!/usr/bin/env node
const { truncate, chain } = require("lodash")
const AWS = require("aws-sdk")
AWS.config.update({ correctClockSkew: true })
const logs = new AWS.CloudWatchLogs()
const totalTimes = {}
const getAll = async ({ requestId, logGroupName, logStreamNames, nextToken, lastTimestamp }) => {
const response = await logs.filterLogEvents({ logGroupName, logStreamNames, nextToken }).promise()
@jelder
jelder / .gitconfig
Created April 6, 2017 14:04
Jacob Elder's .gitconfig
[user]
name = Jacob Elder
email = jacob@blissfully.com
[status]
submodulesummary = false
# https://gist.github.com/jelder/ce4344696139c36786ea08e860b1cf6f
[alias]
out = "log @{u}.."
fetchall = !git pull && git submodule update --init --remote --recursive && git submodule foreach -q --recursive 'echo Updating $name && git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master) && git -C $toplevel/$name pull && echo ---'