This file contains hidden or 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
from mock import Mock, patch_object | |
import random | |
mock = Mock() | |
class MyTest(unittest.TestCase): | |
@patch_object(random, 'shuffle', mock) | |
def test_shuffling(self): | |
thing_that_should_shuffle() |
This file contains hidden or 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 MyClass { | |
void tweeter() { | |
println "Tweet, tweet" | |
} | |
} | |
def my_object = new MyClass() | |
This file contains hidden or 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 MyClass { | |
Closure aMethod | |
MyClass() { | |
aMethod = {println "Default"} | |
} | |
} | |
def myObject = new MyClass(aMethod: { println "Hello"}) | |
This file contains hidden or 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 MyClass | |
def my_method | |
puts "Hello" | |
end | |
end | |
def with_method(object, method_name, replacement_method, &block) | |
old_method = object.method(method_name) | |
object.class.class_eval { define_method method_name, replacement_method} | |
This file contains hidden or 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
(map #(intern *ns* %1 (fn [] println %2)) ['north 'south] ["North" "South"]) |
This file contains hidden or 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.Random | |
random = Random.new | |
def useRandom | |
puts random.nextInt(5) | |
end |
This file contains hidden or 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 MyClass { | |
def methodMissing (String name, Object args) { | |
println("Method missing was invoked for the call ${name}") | |
} | |
} | |
g = new MyClass() | |
g.attr() | |
g.attr |
This file contains hidden or 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
(fn | |
([seq] (find-inc-seq [] [] seq)) | |
([cur-seq cur-longest-seq a-seq] | |
(cond | |
(empty? a-seq) | |
(let [ret (if (> (count cur-seq) (count cur-longest-seq)) cur-seq cur-longest-seq)] | |
(if (> (count ret) 1) ret [])) | |
(empty? cur-seq) (find-inc-seq (conj [] (first a-seq)) cur-longest-seq (rest a-seq)) | |
:default (if (> (first a-seq) (last cur-seq)) |
This file contains hidden or 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 example-story-events [ | |
{ | |
:title "Funding cut again" | |
:tags [:science] | |
:author ["Chuck Newton"] | |
} | |
{ | |
:tags [:politics] | |
} | |
{ |
This file contains hidden or 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
(ns euroclojure.logic | |
(:use [clojure.core.logic])) | |
(defn query [] | |
(run 1 [q] | |
(membero q [1 2 3]))) | |
;; 1 | |
(defn query-all [] |
OlderNewer