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
import java.util.*; | |
/** | |
* @author Paul Barry | |
*/ | |
public class Hash { | |
@SuppressWarnings("unchecked") | |
public static Map init(Map map, Object... keyValuePairs) { | |
if(keyValuePairs != null) { |
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
#Throw this in spec helper | |
def block_should(matcher, &block) | |
block.should matcher | |
end | |
def block_should_not(matcher, &block) | |
block.should_not matcher | |
end | |
#Use it like this |
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
# I hear that aliasing lambda is bad, but this is | |
# much more readable... | |
def this_block(&block) | |
block | |
end | |
this_block{ @this.destroy }.should change(Thing, :count).by(-1) |
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 User | |
belongs_to :group | |
validates_presence_of :first_name | |
class << self | |
def find | |
"foo" | |
end | |
end | |
def awesome? | |
false |
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 do_something(callbacks={}) | |
callbacks[:before].call if callbacks[:before] | |
yield | |
callbacks[:after].call if callbacks[:after] | |
end | |
do_something({ | |
:before => lambda { | |
puts "Will this work?" | |
}, |
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 Acts | |
module Paranoid | |
def acts_as_paranoid | |
named_scope :not_deleted, :conditions => ["(deleted_at < ? OR deleted_at is null)", Time.now] | |
class << self | |
alias_method :find_with_deleted, :find | |
end | |
alias_method :destroy!, :destroy | |
extend ClassMethods | |
include InstanceMethods |
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
require 'email_re' | |
#I assume this is monkey patching a BasicBackend class | |
#that is already defined in Django? | |
#Or else you would just define both methods in EmailBackend? | |
class BasicBackend | |
def self.get_user(id) | |
User.find(id) | |
rescue ActiveRecord::RecordNotFound | |
nil |
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Copyright (c) Rich Hickey. All rights reserved. | |
; The use and distribution terms for this software are covered by the | |
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php) | |
; which can be found in the file CPL.TXT at the root of this distribution. | |
; By using this software in any fashion, you are agreeing to be bound by | |
; the terms of this license. | |
; You must not remove this notice, or any other, from this software. | |
;dimensions of square world |
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
require 'uri' | |
module Http | |
DEFAULT_TIMEOUT = 30 | |
class Request | |
attr_accessor :method, :uri, :headers, :body | |
def initialize(_method, _uri, options={}, &block) | |
self.method = _method | |
self.uri = _uri | |
options.each do |k,v| | |
send("#{k}=", v) |
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
package clojure.velocity; | |
import org.apache.velocity.util.introspection.UberspectImpl; | |
import org.apache.velocity.util.introspection.VelPropertyGet; | |
import org.apache.velocity.util.introspection.Info; | |
import org.apache.velocity.runtime.parser.node.AbstractExecutor; | |
import clojure.lang.APersistentMap; | |
import clojure.lang.Keyword; | |
import java.lang.reflect.InvocationTargetException; |
OlderNewer