Skip to content

Instantly share code, notes, and snippets.

@zerokarmaleft
zerokarmaleft / example.rb
Created March 20, 2013 18:18
Adventures in Functional Ruby, Part 1
require 'java'
require 'jbundler'
require 'stunted'
%w{ PersistentArrayMap, PersistentHashMap, PersistentHashSet, PersistentList,
PersistentQueue, PersistentStructMap, PersistentTreeMap, PersistentTreeSet,
PersistentVector }.each do |data_structure|
java_import "clojure.lang.#{ data_structure }"
end
@zerokarmaleft
zerokarmaleft / Vagrantfile
Created February 28, 2013 17:08
bare bones node for application_python
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "precise32"
config.vm.network :hostonly, "33.33.33.10"
config.vm.provision :chef_client do |chef|
chef.chef_server_url = "https://api.opscode.com/organizations/#{ENV['ORGNAME']}"
@zerokarmaleft
zerokarmaleft / medicat.rb
Last active December 14, 2015 06:39 — forked from laod/medicat.rb
map = [
#general
{name: "Patient Control ID", value: nil},
{name: "SSN", value: nil},
{name: "Other ID", source: :ldap, source_name: "datatelid"},
{name: "Last Name", source: :ldap, source_name: "sn"},
{name: "First Name", source: :ldap, source_name: "givenName"},
{name: "Middle Initial", source: :ldap, source_name: "initials", mapper: Proc.new {|v| v[0]}},
{name: "Sex", source_name: "gender", source: :ods},
{name: "Address", source: :ods, source_name: ["home_address_line_1","home_address_line_2"], mapper: Proc.new{|v| v.join " "}},
@zerokarmaleft
zerokarmaleft / encodings.txt
Created December 4, 2012 22:06
Deviations from ASCII English
./rfc101.txt: ISO-8859 English text
./rfc1061.txt: ASCII text
./rfc1182.txt: ASCII text
./rfc1260.txt: ASCII text
./rfc1305.txt: ISO-8859 English text
./rfc14.txt: ASCII text
./rfc1489.txt: ASCII FORTRAN program text
./rfc159.txt: ASCII text
./rfc16.txt: ASCII text
./rfc162.txt: ASCII Pascal program text
@zerokarmaleft
zerokarmaleft / merge.rb
Created December 4, 2012 21:43
in `delete': invalid byte sequence in UTF-8 (ArgumentError)
# encoding: utf-8
merged_file = File.open("rfc-all.txt", "w")
Dir.entries(".").each do |file|
if (file != "rfc-all.txt" and File.extname(file) == ".txt")
merged_file.print "#{ file }\t"
File.open(file).each do |line|
merged_file.print line.chomp.delete "\t"
end
merged_file.print "\n"
@zerokarmaleft
zerokarmaleft / trace.clj
Created December 4, 2012 20:43
stack overflow in reducer
ERROR - caught Throwable, no trap available, rethrowing
cascading.pipe.OperatorException: [803c4175-eb65-4168-bec...][cascalog.workflow$buffer$fn__572.invoke(workflow.clj:249)] operator Every failed executing operation: ClojureBuffer[decl:'?minhash-sig']
at cascading.flow.stream.BufferEveryWindow.receive(BufferEveryWindow.java:139)
at cascading.flow.stream.BufferEveryWindow.receive(BufferEveryWindow.java:41)
at cascading.flow.hadoop.stream.HadoopGroupGate.run(HadoopGroupGate.java:90)
at cascading.flow.hadoop.FlowReducer.reduce(FlowReducer.java:129)
at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:463)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:411)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:215)
Caused by: java.lang.StackOverflowError
@zerokarmaleft
zerokarmaleft / minhash.clj
Created November 28, 2012 18:25
generating minhash signatures
(defmapcatop [extract-shingles [k]] [line] (shingles k line))
(defmapop [multihash [n]] [shingle]
[(map (fn [seed]
(.asInt (.hashString (Hashing/murmur3_32 seed) shingle)))
(range n))])
(defn merge-vectors
[v1 v2]
(map #(map min %1 %2) v1 v2))
@zerokarmaleft
zerokarmaleft / authoryear.bib
Created October 26, 2012 17:03
LaTeX: [author year] numbered references using natbib
@book{Jacky:1996,
author = {Jacky, Jonathan},
title = {The Way of Z: Practical Programming with Formal Methods},
year = {1996},
publisher = {Cambridge University Press},
address = {New York, NY, USA},
}
@zerokarmaleft
zerokarmaleft / books.clj
Created October 10, 2012 17:12
Reading list
(def books
{{:title "Eloquent Ruby" :tags [:ruby]}
{:title "Design Patterns in Ruby" :tags [:ruby :oop]}
{:title "Practical Object-Oriented Design in Ruby" :tags [:ruby :oop]}
{:title "Let Over Lambda" :tags [:common-lisp :lisp :fp]}
{:title "Pearls of Functional Algorithms" :tags [:haskell :fp]}
{:title "Functional Data Structures" :tags [:ml :haskell :fp]}
{:title "Learn You a Haskell for Great Good" :tags [:haskell :fp]}
{:title "The Little MLer" :tags [:ml :fp]}
{:title "Hadoop: The Definitive Guide" :tags [:java :hadoop :data]}
@zerokarmaleft
zerokarmaleft / hairy-reduce.clj
Created October 5, 2012 01:34
reducing into a 2d matrix
;; matrix M
;; 0 1 2 3
;; ==========
;; 0: 1 0 0 1
;; 1: 0 0 1 0
;; 2: 0 1 0 1
;; 3: 1 0 1 1
;; 4: 0 0 1 0
;; index correspond to checking rows of M