Skip to content

Instantly share code, notes, and snippets.

View pjb3's full-sized avatar

Paul Barry pjb3

View GitHub Profile
import java.util.*;
/**
* @author Paul Barry
*/
public class Hash {
@SuppressWarnings("unchecked")
public static Map init(Map map, Object... keyValuePairs) {
if(keyValuePairs != null) {
#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
# 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)
class User
belongs_to :group
validates_presence_of :first_name
class << self
def find
"foo"
end
end
def awesome?
false
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?"
},
@pjb3
pjb3 / paranoid.rb
Created September 16, 2008 22:51
acts_as_paranoid for Rails 2.1
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
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
@pjb3
pjb3 / ants.clj
Created September 30, 2008 17:34
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 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
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)
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;