Skip to content

Instantly share code, notes, and snippets.

View chreke's full-sized avatar
💭
Just catching up on some reading

Christoffer Ekeroth chreke

💭
Just catching up on some reading
View GitHub Profile
@chreke
chreke / trees.erl
Created November 23, 2012 08:14
Build tree from proplist with list keys
-module(trees).
-export([build_tree/1]).
%% @doc Builds a (proplist-based) tree from a proplist where each key
%% is a list of keys.
build_tree(Proplist) ->
build_tree(Proplist, []).
build_tree([], Tree) ->
@chreke
chreke / eunit_and_meck.erl
Created December 5, 2012 21:48
Eunit and Meck test skeleton
foo_tests() ->
{foreach,
fun setup/0,
fun teardown/1,
[{"Should do something",
do_something()}]}.
setup() ->
Mods = [foo, bar],
meck:new(Mods),
@chreke
chreke / gist:6181891
Created August 8, 2013 06:10
hypem.rb, a script that will turn HypeMachine playlists into Spotify playlists, eventually
#!/usr/bin/ruby
require 'open-uri'
require 'json'
require 'pp'
# Some example URLs;
# http://hypem.com/playlist/loved/JohnyTex/json/1/data.js
# http://hypem.com/playlist/popular/3day/json/1/data.js
# http://ws.spotify.com/search/1/track.json?q=little%20talks
@chreke
chreke / gist:6382345
Last active December 21, 2015 23:29
js examples
// The classic for-loop
var strings = ['1', '2', '3'],
numbers = [];
for (var i = 0; i < strings.length; i++) {
var number = parseInt(strings[i]);
numbers.push(number);
}
// numbers == [1, 2, 3]
@chreke
chreke / underscore.join.js
Last active December 22, 2015 16:48
SQL-like "join" function as an underscore.js mixin
(function () {
/*
TODO: Support more join types?
TODO: Support single key?
*/
var crossProduct = function(objects1, objects2) {
var objects = [];
@chreke
chreke / json-to-csv
Last active December 26, 2015 04:49
Convert JSON to CSV using Ruby
#!/usr/bin/env ruby
# USAGE:
#
# json-to-csv [filename]
#
# This script takes a JSON array of objects as its input and outputs
# the data as CSV to STDOUT. The JSON array can be fed to the
# script either via STDIN or by supplying a filename as an argument.
@chreke
chreke / gist:7740342
Last active December 29, 2015 22:59
JSQL Sketch
// Quick sketch / spec for how a JSQL module might work
var people = [{
'name': 'Mary Jane Watson',
'job': 'Actress',
'alignment': 'Good',
'age': 23
}, {
'name': 'Peter Parker',
'job': 'Photographer',
@chreke
chreke / json-to-csv.py
Last active August 29, 2015 14:07
JSON to CSV
#!/usr/bin/env python
# Reads JSON from a file or STDIN and outputs CSV to STDOUT.
import fileinput
import json
import sys
import csv
jsonstr = ''
@chreke
chreke / mdpreview.sh
Last active August 29, 2015 14:07
Render Markdown and open in browser
#!/usr/bin/env bash
OUTPUT=/tmp/$(basename $1).html
markdown $1 > $OUTPUT
open $OUTPUT
# FIXME: This is a hack to prevent deleting the file before it's opened.
# Is it possible to use `wait` instead?
sleep 1
rm $OUTPUT
@chreke
chreke / cleaner.rb
Last active August 29, 2015 14:07
Ruby script to clean up dead git branches
#!/usr/bin/ruby
# Interactively remove branches not in remote, *by name*. This is
# useful for pruning branches that were rebased prior to merging,
# since those branches will not show up in `git branch --merged`.
# List local branches which may have been merged
remotes = `git branch -r`.split.map {|x| x.sub('origin/', '') }
locals = `git branch`.split.select {|x| x != '*' }
complement = locals.select {|x| not (remotes.include? x) }