Skip to content

Instantly share code, notes, and snippets.

View jelder's full-sized avatar

Jacob Elder jelder

View GitHub Profile
@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 / .my.cnf
Last active November 9, 2018 13:04
My ~/.psqlrc
[mysql]
prompt=\\d mysql>\_
auto-vertical-output=true
@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 ---'
@jelder
jelder / summer_2015.md
Last active September 22, 2015 20:00
Summer 2015 Reading Recommendations.

The Culture (Series)

https://en.wikipedia.org/wiki/Culture_series

A series of novels exploring the political, economic, social, and military history of a galactic-scale, post-material-scarcity, post-singuarlty, and post-captialism society. Features godlike AIs embodied in hundred-cubic-kilometer starships!

Seven Eves

Seveneves

@jelder
jelder / passenger_throttle.sh
Created April 8, 2015 20:55
Dynamically configure Passenger based on current Dyno type
#!/bin/bash
# http://stackoverflow.com/questions/24634958/programmatically-detect-heroku-dyno-size-at-run-time/24634959#24634959
function dyno_size() {
case $(ulimit -u) in
256)
echo "1X"
;;
512)
echo "2X"
@jelder
jelder / json.sql
Created March 25, 2015 22:38
Converting between types of arrays in PostgreSQL
BEGIN;
CREATE TABLE json_test (
id SERIAL PRIMARY KEY,
label text,
examples text[] DEFAULT '{}'::text[]
);
INSERT INTO json_test (label,examples) VALUES ('before','{}');
INSERT INTO json_test (label,examples) VALUES ('before','{"[{\"a\":1}]"}');
@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 / deep_store.rb
Last active August 29, 2015 14:11
Extend Hash to allow insertion by path
require 'ap'
class Hash
def store_by_path(path, value)
case path
when String
if path =~ %r{/}
store_by_path(path.split('/'), value)
else
self[path] = value
end
@jelder
jelder / store_by_path.rb
Last active August 29, 2015 14:01
Hash insertion by path
require 'ap'
class Hash
def store_by_path(path, value)
case path
when String
if path =~ %r{/}
store_by_path(path.split('/'), value)
else
self[path] = value