Skip to content

Instantly share code, notes, and snippets.

View joshuamiller's full-sized avatar

Joshua Miller joshuamiller

View GitHub Profile
class UsernameConstraint
def matches?(request)
if /^\/(?<username>[a-zA-Z0-9-]+)/ =~ request.path
User.exists?(:conditions => {:username => username})
end
end
end
#...
def create
respond_to do |format|
if @my_model.save
format.json do
render :json => @my_model.to_json(:methods => [:owner_name]) #owner_name is a method that returns owner.display_name
end
end
format html { ... }
else
format.json { errors... }
[info] [<0.4586.0>] 127.0.0.1 - - 'GET' /_all_dbs 200
[info] [<0.4587.0>] 127.0.0.1 - - 'PUT' /test_db 201
[info] [<0.4588.0>] 127.0.0.1 - - 'GET' /test_db/_design/SpatialTest%3A%3ASpatialModel 404
[info] [<0.4589.0>] 127.0.0.1 - - 'PUT' /test_db/_design/SpatialTest%3A%3ASpatialModel 201
[info] [<0.4590.0>] 127.0.0.1 - - 'GET' /test_db/_design/SpatialTest%3A%3ASpatialModel 200
[info] [<0.4591.0>] 127.0.0.1 - - 'PUT' /test_db/_design/SpatialTest%3A%3ASpatialModel 201
[info] [<0.4592.0>] 127.0.0.1 - - 'GET' /test_db/_design/SpatialTest%3A%3ASpatialModel 200
[info] [<0.4593.0>] 127.0.0.1 - - 'PUT' /test_db/_design/SpatialTest%3A%3ASpatialModel 201
[info] [<0.4594.0>] 127.0.0.1 - - 'GET' /test_db/_design/SpatialTest%3A%3ASpatialModel 200
[info] [<0.4596.0>] 127.0.0.1 - - 'PUT' /test_db/_design/SpatialTest%3A%3ASpatialModel 201
[[], [["a", "b", "c"], ["d", "e", "f"]], [["g", "h", "i"]]]
#=>
[["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]]
#=> via
array.reject(&:empty?).inject([]) {|acc, array| array.each {|entry| acc << entry}; acc}
should "accept timestamps" do
time = Time.now
Timecop.travel(time)
new_model = TestModel.new
new_model.save
assert_equal time, new_model.created_at
assert_equal time, new_model.updated_at
future = time + 10.minutes
Timecop.travel(future)
new_model.save
class Tester
attr_accessor :name, :age
def testy (&block)
instance_eval &block
end
end
name = "Josh"
t = Tester.new
t.name = "Larry"
; joshuafarm.org [81583]
$TTL 86400
@ IN SOA ns1.linode.com. josh.joshinharrisburg.com. (
2010031666
14400
14400
1209600
86400
)
@ NS ns1.linode.com.
module XAuth
module_function
def retrieve_access_token(username, password, consumer_key, consumer_secret, site = 'https://api.twitter.com')
consumer = OAuth::Consumer.new(
consumer_key,
consumer_secret,
:site => site
)
# The code below is helped by:
- Flannel sheets (queen)
- Comforter (queen)
- Steak knives
- Under-cabinet mounted iPhone stereo for kitchen
- iHome or similar with alarm for bedroom
- ...
$ cat $(which clojure)
BREAK_CHARS="(){}[],^%$#@\"\";:''|\\"
CLOJURE_JARS="/opt/jars/*"
CP="/opt/clojure/clojure.jar:/opt/clojure/clojure-contrib.jar:$CLOJURE_JARS"
# If no file is being passed, start the REPL
if [ -z "$1" ]; then
rlwrap --remember -c -b $BREAK_CHARS -f $HOME/.clj_completions \