Skip to content

Instantly share code, notes, and snippets.

View alexy's full-sized avatar

Alexy Khrabrov alexy

View GitHub Profile
@alexy
alexy / addOrdering.scala
Created January 8, 2012 11:04
adding Ordering
case class User(sid: Int, uid: String) extends Ordered[User] {
override def compare(b: User): Int = {
(this.sid compare b.sid) match {
case 0 => this.uid compare b.uid
case x => x
}
}
}
@alexy
alexy / scoobi-run-mac-fail
Created November 8, 2011 23:28
Running Scoobi fails on Mac OSX
Ilyad% hadoop jar ./target/Scoobi_Word_Count-hadoop-0.1.jar /data/shake /data/output-scoobi
2011-11-08 15:27:41.856 java[68147:1903] Unable to load realm info from SCDynamicStore
11/11/08 15:27:46 INFO mapred.FileInputFormat: Total input paths to process : 1
11/11/08 15:27:46 INFO filecache.TrackerDistributedCacheManager: Creating scoobi.input.mappers in /tmp/hadoop-Alexy/mapred/local/archive/4123907766041581906_1466591507_92422095/file/Users/Alexy/.scoobi/201111081527/dist-objs-work--5404407803082534293 with rwxr-xr-x
11/11/08 15:27:46 INFO filecache.TrackerDistributedCacheManager: Cached file:/Users/Alexy/.scoobi/201111081527/dist-objs/scoobi.input.mappers as /tmp/hadoop-Alexy/mapred/local/archive/4123907766041581906_1466591507_92422095/file/Users/Alexy/.scoobi/201111081527/dist-objs/scoobi.input.mappers
11/11/08 15:27:46 INFO filecache.TrackerDistributedCacheManager: Cached file:/Users/Alexy/.scoobi/201111081527/dist-objs/scoobi.input.mappers as /tmp/hadoop-Alexy/mapred/local/archive/4123907766041581906_14
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# zsh colors -- http://spiralofhope.wordpress.com/2009/04/23/zsh-ansi-prompt/
function precmd {
# let's get the current get branch that we are under
# ripped from /etc/bash_completion.d/git from the git devs
git_ps1 () {
@alexy
alexy / read_lines.ml
Created March 22, 2011 20:30
return a list of lines in a file, with an optional skip number and max on actually returned ones
let read_lines ?skip ?maxn filename =
let ic = open_in filename in
let step,ctr = make_step_counter 0 in
E.from_while begin fun () ->
try
match skip,maxn with
| (Some s, _) when ctr () < s ->
ignore (input_line ic); step (); Some None
| (skip, Some n) when n > 0 && ctr () - (Option.default 0 skip) = n ->
close_in ic; None
let printShowTable: tex -> ?verbose:bool ->
('a BatInnerIO.output -> 'b -> unit) ->
'c list list -> string -> unit =
fun tex ?(verbose=false) printOne table tableName ->
let oc = open_out tableName in
printTable oc tex printOne table tableName;
close_out oc;
if verbose then
printTable stdout tex printOne table tableName
else ()
@alexy
alexy / cake's not bakin'
Created December 8, 2010 19:12
cake 0.6.0 wants bake.jar which it cannot have, never!
config: {"project.library.path"=>"/opt/local/lib"}
vars: {:script "bin/cake" :opts {:default ["deps"] :d [""]} :pwd "/s/w/clojure/cake" :args ["default" "-d" "deps"] :env {"MANPATH" "/s/src/srilm/current/bin:/s/src/srilm/current/bin/macosx/man:/opt/local/share/man:" "OLDPWD" "/Users/alexyk" "Apple_PubSub_Socket_Render" "/tmp/launch-QWcUGb/Render" "USER" "alexyk" "TMPDIR" "/var/folders/mw/mwJSf7ErEa4w8nWyKyyqD++++TY/-Tmp-/" "LC_CTYPE" "en_US.UTF-8" "TERM" "xterm-color" "DARCS_EMAIL" "[email protected] (Alexy Khrabrov)" "SSH_AGENT_PID" "474" "MAGICK_HOME" "/usr/local/ImageMagick" "GEM_HOME" "/Users/alexyk/.jgem" "PROMPT" "%~ " "SHLVL" "1" "__CF_USER_TEXT_ENCODING" "0x1F9:0:0" "LC_ALL" "en_US.UTF-8" "COMMAND_MODE" "legacy" "SHELL" "/bin/zsh" "DISPLAY" "/tmp/launch-VNuY4O/org.x:0" "LOGNAME" "alexyk" "LANG" "en_US.UTF-8" "DYLD_LIBRARY_PATH" "/usr/local/ImageMagick/lib" "PWD" "/s/w/clojure/cake" "PATH" "/opt/ocaml/bin:/opt/ocaml/sbin:/Users/alexyk/.cabal/bin:/opt/brew/bin:/Users/alexyk/bin:/opt/sbin:/opt/bin:
(defn tokyo-read-reps [db-pathname & [proto str-load?]]
(let [
proto (or proto Repliers)
init-params (let [par {:path db-pathname :read-only true}]
(if str-load? par
(merge par {:dump protobuf-dump :load (partial protobuf-load proto)})))
db (tc/db-init init-params)
_ (tc/db-open db)
tc (:db db)
r (when (.iterinit tc)
@alexy
alexy / foo.clj
Created July 27, 2010 18:07 — forked from hiredman/foo.clj
(defn sig [x]
(:sig (meta (resolve x))))
(defmulti type-of (comp type first list))
(defmethod type-of :function [thing & _] (sig thing))
(defmethod type-of java.util.List [expr & a]
(conj (map #(type-of % (first a)) (rest expr))
import System (getArgs)
import Data.Map hiding (map)
import Database.TokyoCabinet
import qualified Data.ByteString.Char8 as B
import Text.JSONb
fetch :: String -> Maybe Int -> TCM [(String,B.ByteString)]
fetch fileName maxElems = do
tc <- new :: TCM HDB -- alternatively you can use BDB or FDB
open tc fileName [OREADER]
;; routes.clj
(ns winston.ui.routes
(:use [clojure.contrib.except :only (throwf)])
(:require [clojure.contrib.string :as str])))
(defn path-for* [routefn route-args]
{:pre [routefn]}
(let [path (-> routefn meta ::http-path)]
(when (not path)