Skip to content

Instantly share code, notes, and snippets.

View slyphon's full-sized avatar

Jonathan Simms slyphon

View GitHub Profile
#!/usr/bin/env ruby
class IHazName
def initialize(name)
@name = name
end
end
zero = IHazName.new('zero')
one = IHazName.new('one')
(ns hiredman.beans)
(defn -it [& _]
[[] (ref {})])
(defn setter [tis nam tat]
(dosync
(commute (.state tis)
assoc nam tat)))
(ns mbox.harpo.xmlrpc.XmlRpcRequestWrapper
(:gen-class
:extends javax.servlet.http.HttpServletRequestWrapper
:init init
:state state
:constructors {[javax.servlet.http.HttpServletRequest java.io.ByteArrayInputStream]
[javax.servlet.http.HttpServletRequest]})
(:import
[java.io Reader ByteArrayInputStream]
(ns user
(:use
[clojure.contrib
(logging :only (debug info warn error fatal spy))
[str-utils :only (re-gsub)]
[duck-streams :only (to-byte-array)]
[java-utils :only (set-system-properties as-properties read-properties)]
[pprint :only (pprint pp)]])
(:require
(use '[clojure.contrib [str-utils :only (re-gsub)]])
(use '[clojure.contrib [java-utils :only (as-str)]])
(defn #^String upcase
"upcases the initial character in s"
[s]
(let [string (as-str s)]
(apply str (Character/toUpperCase (first string)) (rest string))))
(defn #^String camelize [s]
@slyphon
slyphon / gist:401391
Created May 14, 2010 17:17 — forked from tobowers/gist:397354
zookeeper barrier implementation
require 'rubygems'
gem 'zookeeper'
require 'zookeeper'
REQUIRED_NUMBER_OF_PROCESSES = 2
class EventHandler
import org.apache.zookeeper.Watcher
@slyphon
slyphon / git-quick-tag.sh
Created December 17, 2010 22:26
just a shortcut for creating a tag object and (optionally) pushing it
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "Usage $(basename $0) [-p] tagname" >&2
echo 'the -p option will run `git push --tags` after creating the new tag' >&2
exit 1
fi
DO_PUSH=''
module DevNull
class FileEachWrapper
def initialize(io)
@io = io
end
def each
end
@slyphon
slyphon / gist:804981
Created January 31, 2011 22:35
findAndModify is confusing me
> db.messages.find()
{ "_id" : "msgid:test:e9f1aca0-2d86-11e0-9695-138376569236", "status" : "incomplete", "expires" : 1296598229, "timeout" : 1296512429 }
{ "_id" : "msgid:test:f93bf066-2d87-11e0-ab0b-d7db09943f10", "status" : "incomplete", "expires" : 1296598684, "timeout" : 1296512884 }
> db.messages.find( { _id : "msgid:test:f93bf066-2d87-11e0-ab0b-d7db09943f10" } )
{ "_id" : "msgid:test:f93bf066-2d87-11e0-ab0b-d7db09943f10", "status" : "incomplete", "expires" : 1296598684, "timeout" : 1296512884 }
> cmd = {
... findAndModify : "messages",
... query : { _id : "msgid:test:f93bf066-2d87-11e0-ab0b-d7db09943f10" },
> db.messages.find( { _id : "msgid:test:f93bf066-2d87-11e0-ab0b-d7db09943f10" } )
{ "_id" : "msgid:test:f93bf066-2d87-11e0-ab0b-d7db09943f10", "status" : "incomplete", "expires" : 1296598684, "timeout" : 1296512884 }
> cmd = {
... query : { _id : "msgid:test:f93bf066-2d87-11e0-ab0b-d7db09943f10" },
... update : { $inc : { attempts : 1 } },
... new : true,
... fields : { "_id" : 0, "attempts" : 1 }
... };
{
"query" : {