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 state-field (first (filter #(= "state" (.getName %)) (seq (.getDeclaredFields (java.lang.Class/forName "clojure.lang.Agent")))))) | |
(.setAccessible state-field true) | |
(def foo (agent 1)) | |
(.set state-field foo 5) | |
user=> @foo | |
5 |
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 Array | |
class Val | |
attr_reader :i | |
def initialize(i) | |
@i = i | |
end | |
def eql?(other) | |
other.is_a?(Val) && @i==other.i |
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
# evil Ruby dynamic variables | |
class DynamicValue | |
attr_read :default_value | |
def initialize(val) | |
@default_value = val | |
end | |
def method_missing(name, *args) |
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
#!/usr/bin/env ruby | |
# Trivial little twitter script | |
# Pass it a list of names as command line arguments | |
# and it will return a list of all people who follow everyone in the | |
# list. | |
# A person is implicitly assumed to follow themselves, so if foo follows | |
# bar and bar follows foo then common_followers foo bar would include | |
# both foo and bar in the output, but if bar did not follow foo it | |
# would include neither. |
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
(defstruct board :size :values :value-index :all-transitions) | |
(defn create-board | |
"create a board of a given size" | |
[size] | |
(assert (> size 0)) | |
(let [values (vec (range 1 (inc size))) | |
value-index (reduce (fn [h i] (assoc h (values i) i)) {} (range 0 (count values))) | |
all-transitions (reduce (fn [t n] (assoc t n (set values))) {} values)] | |
(struct-map board |
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
(ns puzzle) | |
(defstruct board :size :values :value-index :constraints) | |
(defn create-board | |
"create a board with given size and constraints" | |
[size constraints] | |
(assert (> size 0)) | |
(let [values (vec (range 1 (inc size))) | |
value-index (reduce (fn [h i] (assoc h (values i) i)) {} (range 0 (count values))) |
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
(defn multi-split-with | |
"Returns a lazy collection of lists which elements ..." | |
[pred coll] | |
(let [[head tail] (split-with pred coll) | |
tail-without-seps (drop-while (complement pred) tail)] | |
(lazy-seq | |
(if (seq tail-without-seps) | |
(cons head (multi-split-with pred tail-without-seps)) | |
(list head))))) |
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
>> puts m.to_s | |
Date: Thu, 21 Oct 2010 16:28:20 +0100 | |
From: craig mcmillan <[email protected]> | |
To: =?UTF-8?B?ImNyYWlnIOaXpeacrOWbvSI=?= <[email protected]> | |
Message-ID: <[email protected]> | |
Subject: =?UTF-8?Q?big_in_=E6=97=A5=E6=9C=AC=E5=9B=BD?= | |
Mime-Version: 1.0 | |
Content-Type: text/plain; | |
charset=UTF-8; | |
format=flowed |
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
;; pin windows | |
(defun toggle-window-dedicated () | |
"Toggle whether the current active window is dedicated or not" | |
(interactive) | |
(message | |
(if (let (window (get-buffer-window (current-buffer))) | |
(set-window-dedicated-p window | |
(not (window-dedicated-p window)))) | |
"Window '%s' is dedicated" | |
"Window '%s' is normal") |
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
{"status":200, | |
"data": | |
{"longitude":0.1537217, | |
"name":"AUTONOMY SYSTEMS LIMITED", | |
"postcode":"CB4 0WZ", | |
"last_revenue_year":2010, | |
"last_tweet":null, | |
"colocated":["03857576","03879840","04255000","07117553","03266657","04031841","06063523","05212691","04217293","06917673","03008226","03781249","04858580","03891934","02926171"], | |
"directors":[ | |
{"name":"Mr Roberto Adriano Putland", |
OlderNewer