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 chopstick :id :holder) | |
(defstruct philosopher :name :left-stick :right-stick) | |
(defn make-chopstick [id] | |
(struct chopstick id (ref ""))) | |
(defn set-table [philosophers] | |
(let [stick-count (max 2 (count philosophers)) | |
stick-seq (map make-chopstick (range stick-count)) | |
stick-cycle (cycle (take stick-count stick-seq))] |
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 nth-val [first-val step val-count] | |
(+ first-val (* step (dec val-count)))) | |
(defn arithmetic-series [first-val step val-count] | |
(let [last-val (nth-val first-val step val-count)] | |
(* val-count | |
(/ (+ first-val last-val) 2)))) | |
(defn arithmetic-series-of-multiples-less-than [ceiling] | |
(fn [val] |
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
(let [fibs (iterate (fn [[a b]] [b (+ a b)]) [0 1]) | |
just-the-fibs (take-while #(> 4e6 (apply max %)) fibs)] | |
(reduce (fn [sum [_ r]] (+ sum (if (even? r) r 0))) | |
0 | |
just-the-fibs)) |
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 Foo | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
def method_missing(name, *args, &block) | |
return super unless name.to_s =~ /^go_/ | |
puts "Defining #{name}" | |
method = lambda { puts "hey #{@name}@#{object_id}, #{name.to_s.tr '_', ' '}" } |
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
describe "NIC-U" do | |
context "Fall conference" do | |
it "should be readable" do | |
"readable".should == "readable" | |
end | |
it { "readable".should == "readable"} | |
context "readable" do | |
it { should == "readable" } |
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
function hello_world () { | |
setTimeout(function() { | |
console.log("world"); | |
}, 5000); | |
console.log("hello"); | |
} | |
hello_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
var batch_util = { | |
'utility functions': { | |
'starts_sequence' : { | |
'can detect a simple sequence': function() { | |
assert.ok(ansi.util.starts_sequence('\u001b[foobar')); | |
}, | |
'rejects something obviously not a sequence': function() { | |
assert.ok(!ansi.util.starts_sequence('foobar')); | |
}, | |
'rejects a truncated sequence': function() { |
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
// vows calls transmute, which registers trap as the listener to all specified events | |
// node sends each message to the trap() callback | |
// FAIL: trap calls this.callback with its arguments | |
// PASS: trap calls this.callback with a property which cached arguments from each invocation of trap | |
// HOWTO pass / fail: toggle the conditional at line 152 | |
// revised sample output: | |
// | |
// PASS | |
// |
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
<script src="/socket.io/socket.io.js"></script> | |
<script type="text/javascript"> | |
var socket = new io.Socket(); | |
socket.connect(); | |
socket.on('connect', | |
function(){ | |
console.log('connected'); | |
socket.send('/var/log/system.log'); | |
}); |
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
// | |
// Just skip to the bottom | |
// | |
var express = require('express'); | |
var io = require('socket.io'); | |
var app = module.exports = express.createServer(); | |
// Configuration |
OlderNewer