Skip to content

Instantly share code, notes, and snippets.

View mboeh's full-sized avatar

Matthew Boeh mboeh

View GitHub Profile
@mboeh
mboeh / speak.rb
Last active August 29, 2015 14:04 — forked from mrinterweb/speak.rb
#! /usr/bin/env ruby
# Some of the words are misspelled to help the say program pronounce them right
#
# copy the following line and paste for fun!
# curl -O https://gist.githubusercontent.com/mrinterweb/0ed2ac30a97e25e03fad/raw/5da7c2a012a08cfcc9649e0f410d53f8986e4990/speak.rb && mv speak.rb speak && chmod a+x speak && ./speak
def envlist(name, &default)
results = (ENV["SPEAK_#{name.to_s.upcase}"] || "").split(":")
results.empty? ? default.call : results
end
@mboeh
mboeh / cnd.rb
Created July 28, 2014 19:20
cnd.rb
alias λ proc
alias _l proc
class Object
def cnd(t:λ{},f:λ{})
t[]
end
end
class NilClass
@mboeh
mboeh / pretty-bunny.rb
Created August 5, 2014 18:35
nicer inspects for Bunny objects
# bunny uses the default Ruby inspect, which means it includes nested objects.
# that means that inspecting a Bunny::Queue ends up dumping a screenful of irrelevant
# gunk nested somewhere deep in the protocol implementation.
# These monkeypatches make #inspect terse and relevant for Exchange, Queue, Channel,
# and Session.
# Caveat emptor: there are some configuration details the inspect format doesn't cover,
# and there are very likely bugs -- this was thrown together through some experimentation
# on the REPL.
@mboeh
mboeh / Makefile
Last active August 29, 2015 14:05
play project with ocaml
run:
ocamlbuild -use-ocamlfind -package batteries world_common.native
ocamlbuild -use-ocamlfind -package batteries world.native && _build/world.native | tee results.txt
upload:
gist -u https://gist.github.com/mboeh/c45e477a8f737a9157e0 world.ml world_common.ml world_common.mli Makefile results.txt
@mboeh
mboeh / Dockerfile
Last active August 29, 2015 14:08
mlton docker environment
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y build-essential libgmp10-dev curl
RUN curl -s -L http://downloads.sourceforge.net/project/mlton/mlton/20130715/mlton-20130715-1.amd64-linux.tgz | zcat - | tar x
WORKDIR /home
VOLUME /home
@mboeh
mboeh / 2wice.c
Last active August 29, 2015 14:08
#include <stdio.h>
#include <stdint.h>
extern int32_t twice(int32_t, int32_t(*)(int32_t));
int32_t dbl(int32_t x) {
/* x = arbitrary number here */
return x+x;
}
@mboeh
mboeh / astar-room-search.rs
Last active August 29, 2015 14:09
rust astar experiments
extern crate astar; // from https://github.com/mboeh/astar.git
use std::vec::MoveItems;
#[deriving(Eq)]
#[deriving(Hash)]
struct Room<'a> {
id: int,
difficulty: int,
exits: Vec<&'a Room<'a>>
@mboeh
mboeh / symbol-gc.rb
Created March 8, 2015 06:29
symbol-gc.rb
puts "Ruby version: #{RUBY_VERSION}"
def show_a_sym(sym)
puts "sym #{sym} = #{sym.object_id}"
end
def pick_a_sym
a = (1..100_000).map{|s| :"dummy-#{s}" }
sym = a.sample
show_a_sym sym
[alias]
# Cheap fast way of getting the current branch for, say, your shell prompt
cbranch = !cat .git/HEAD | cut -d/ -f3-4
st = status
# A pattern I find myself using a lot
up = !git fetch && git rebase origin/$(git cbranch)
# The current staged patch
di = diff --cached
# checkout is so long, and co means something sort of different to me
sw = checkout
# Ruby syntax never fails to amaze me, casefile whatever.
# Yes, this could be accomplished more elegantly another way. But this is fun.
require 'ostruct'
def DStruct(*a)
klass = Struct.new(*a)
defs = Hash.new
yield defs
klass.send :define_method, :initialize do |*a|