Skip to content

Instantly share code, notes, and snippets.

# truly curried function !
add = (x)->(y)-> x()+y()
add4 = add(()->4)
console.log(add(()->4)(()->6))
console.log(add4(()->6))
@snowmantw
snowmantw / gist:2417631
Created April 19, 2012 00:55
FunTang-Lambda Parser
/* description: Parses end executes mathematical expressions. */
/* lexical grammar */
%lex
%%
\s+ { return 'SP'; }
"->" { return 'AR'; }
"(" { return 'LP'; }
")" { return 'RP'; }
@snowmantw
snowmantw / gist:2627057
Created May 7, 2012 10:18
strong 偵測問題
應該是在 toggle 設定時,雖然做了 names_node 去存父子的 name ,偵測反應時卻依然只是用 dom_name 這個單層者,沒有使用 names_node
@snowmantw
snowmantw / be_same_file_as.rb
Created July 7, 2012 15:35 — forked from mattwynne/be_same_file_as.rb
RSpec matcher to compare two file, using their MD5 hashes
RSpec::Matchers.define(:be_same_file_as) do |exected_file_path|
match do |actual_file_path|
md5_hash(actual_file_path).should == md5_hash(exected_file_path)
end
def md5_hash(file_path)
Digest::MD5.hexdigest(File.read(file_path))
end
end
@snowmantw
snowmantw / gist:3126682
Created July 17, 2012 02:47
Local async javascript use Web Worker in Chrome.
var t = ["3+3;console.log('abc');"]
var tb = new Blob(t, {"type": "text\/javascript"});
w = new Worker(window.webkitURL.createObjectURL(tb))
@snowmantw
snowmantw / gist:3126781
Created July 17, 2012 03:16
Ajax do no-op from server in nginx
location /newapi/no-op {
add_header Content-Type "application/json; charset=utf-8";
return 200;
}
@snowmantw
snowmantw / gist:3161609
Created July 23, 2012 01:34
DESL of asynchronous computation.
Compute
.init( {:Xa => xa, :domain => domain, :uid => uid} )
.wait("resource.scalar_product.Ra_ra",:Ra, :ra) #1.
.compute(:Xa_, lambda{ |m| add(m[:Xa], m[:Ra], m[:domain]) } ) #2.
.send("resource.scalar_product.Xa_", :Xa_) #3.
.wait("resource.scalar_product.Xb_", :Xb_) #4.
.wait("resource.scalar_product.t", :t) #5.
.compute( :yA, lambda{ |m| t1 = trans(m[:Xb_], m[:domain])
t2 = mul(m[:Ra],t1, m[:domain])
t3 = sub(m[:t] ,t2, m[:domain]) }) #6.
@snowmantw
snowmantw / gist:3161907
Created July 23, 2012 03:47
fluorine flow controlling
t = fluorine.Environment({a: 1})
.local(function(e){ return {'b': this.a+1}; })
.async()
.local(function(data){ console.log('data');console.log(this.data);return this})
.done().run()
// 重點:async 實作中設定了接續 run 的部份
/*
// THIS FUNCTION IS ONLY FOR TEST ASYNC CALLS.
@snowmantw
snowmantw / gist:3811858
Created October 1, 2012 13:40
try coffeescript + fluorine
Env(a:3, b:4)
._(()->@a+=3)
._(()->@b+=4)
.done()
.run()
@snowmantw
snowmantw / infinity_matrix_curries.js
Last active December 16, 2015 01:39
Because using Array is too mainstream
// From http://stackoverflow.com/questions/14850511/js-matrix-multiplication-issue
function multiplyMatrix(m1, m2) {
var result = [];
for(var j = 0; j < m2.length; j++) {
result[j] = [];
for(var k = 0; k < m1[0].length; k++) {
var sum = 0;
for(var i = 0; i < m1.length; i++) {
sum += m1[i][k] * m2[j][i];
}