Skip to content

Instantly share code, notes, and snippets.

@eddking
eddking / review-data-export.js
Last active February 13, 2019 19:02
export pull request & review data from github via the http api
const request = require('request-promise-native');
const parseLinkHeader = require('parse-link-header');
const fs = require('fs');
/*
* This is an idempotent script for downloading pr & review data for a single repository
* Set the repo and auth variables below, then run and wait. its not speedy, but it works
*
* If you stop the script or it dies or you trigger abuse detection, it is safe to restart.
* it will only download the remaining data, any requests that were pending at the time of
@eddking
eddking / Main.purs
Created December 11, 2017 16:18
Free monad example in purescript
module Main where
import Data.Generic
import Prelude
import Control.Monad.Free (Free, liftF, runFreeM)
import Control.Monad.Eff
import Control.Monad.Eff.Console (log, CONSOLE)
import Control.Monad.Eff.Random (randomBool, RANDOM)
data Action =
import { Dictionary, Entry, entries, dict } from './Dictionary';
import { KVPair, kvPair } from './object';
import { identity } from './utils';
type Transformer<C, X> = (c: C, context?: X) => C;
type Getter<S, C> = (s: S) => C;
type Setter<S, C> = (s: S, v: C) => S;
type Reducer<R, C, X> = (sum: R, value: C, context: X) => R;
@eddking
eddking / updater.ts
Last active April 10, 2017 13:06
Update a nested structure in an immutable fashion (like a lens)
import { isEqual } from 'lodash';
/*
* Usage: imagine you have part of a reducer like this:
*
* switch(action.type) {
* case 'CAMPAIGN_INITIALISED':
* campaign = state[action.campaignId];
* return {
* ...state,
@eddking
eddking / lol.py
Created January 11, 2017 18:25
lol
import sys
def printstr(string):
sys.stdout.write(string)
def func(level):
if level == 0:
return
printstr("anti-")
@eddking
eddking / cumulative_binomial_distribution.rb
Created October 24, 2016 13:06
Utility for calculating the cumulative binomial distribution in ruby
module CumulativeBinomialDistribution
extend self
# s = successes
# p = probability of success per trial
# n = number of trials
def normal_estimate(s, p, n)
u = n * p
o = (u * (BigDecimal.new('1')-p)) ** BigDecimal.new('0.5')
# continuity correction
@eddking
eddking / recreate_table_without_downtime.sql
Created March 29, 2016 21:13
Re-create a table within postgres without downtime
-- This is a general process for recreating tables in postgres without downtime
-- it can help you recover from data corruption bugs like one seen in Postgres 9.3
-- The table in question should have no foreign key contraints
-- in this example I migrate a table called bibliography_entries to a table called bib_entries
-- create the new table
CREATE TABLE bib_entries (LIKE bibliography_entries INCLUDING ALL);
-- create a temporary table to hold the changes while the bulk of the table is migrated
CREATE TABLE bib_entries_tmp (LIKE bibliography_entries INCLUDING ALL);
@eddking
eddking / README.md
Created January 22, 2016 20:14
Amazon Machine Image Automation

Image Automation

Images are built using packer. Packer takes care of booting a source image, bootstrapping it, running your configuration management and then shutting down and creating an ami. It can run multiple builds in parallel

To make image building super simple, there is a python script build_image.py which simply takes the name of an image to build, the various images are configured in images.yml. The build_image.py script will find the appropriate source ami, generate the configuration for packer, and then run packer.

@eddking
eddking / Dockerfile
Last active August 29, 2015 14:24
Template for automating documentation
FROM ubuntu:14.04
# ---- Edit These ----
ENV DOCS_NAME=template
ENV DOCS_SOURCE=source
ENV DOCS_REMOTE=http://yoursite.com
# --------------------
# docs remote is used in the dash feed url, see build.sh
ENV DOCS_ROOT=/var/www
ENV DEBIAN_FRONTEND=noninteractive