This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsernameConstraint | |
def matches?(request) | |
if /^\/(?<username>[a-zA-Z0-9-]+)/ =~ request.path | |
User.exists?(:conditions => {:username => username}) | |
end | |
end | |
end | |
#... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[], [["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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tester | |
attr_accessor :name, :age | |
def testy (&block) | |
instance_eval &block | |
end | |
end | |
name = "Josh" | |
t = Tester.new | |
t.name = "Larry" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; joshuafarm.org [81583] | |
$TTL 86400 | |
@ IN SOA ns1.linode.com. josh.joshinharrisburg.com. ( | |
2010031666 | |
14400 | |
14400 | |
1209600 | |
86400 | |
) | |
@ NS ns1.linode.com. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Flannel sheets (queen) | |
- Comforter (queen) | |
- Steak knives | |
- Under-cabinet mounted iPhone stereo for kitchen | |
- iHome or similar with alarm for bedroom | |
- ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 \ |