Skip to content

Instantly share code, notes, and snippets.

View nanne007's full-sized avatar
🏠
Working from home

caojiafeng nanne007

🏠
Working from home
View GitHub Profile
class Class
def to_proc
proc { |x, y| new x, y }
end
end
p [[1, 'a'], [2, 'b'], [3, 'c']].map &Array
@nanne007
nanne007 / repeat_until.scala
Last active December 28, 2015 07:09
repeat { command } until(condition) syntax in scala
def repeat(c: => Unit) = new {
def until(p: => Boolean): Unit = {
c
if(p) ()
else until(p)
}
}
@nanne007
nanne007 / thought-in-y-combinator.rkt
Created March 21, 2014 08:59
evolution of Y combinator
#lang racket
;;; a definition of Y(notice: it's not Y Combinator),
;;; which can run in a strict language
; (Y f) = (f (Y f)) = (f (lambda (x) ((Y f) x)))
(define Y
(lambda (f)
(f (lambda (x) ((Y f) x)))))
(define almost-factorial
@nanne007
nanne007 / continuation-monad.scala
Created April 17, 2014 07:27
Continuation Monad in Scala
case class M[+A](in: (A => Any) => Any);
def unit[A](x: A) = M { k: (A => Any) => k(x) }
def bind[A, B](m: M[A], f: A => M[B]): M[B] =
M { k: (B => Any) =>
m.in { x: A =>
f(x).in(k)
}
}
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

http://doc.rust-lang.org/guide-pointers.html#boxes 提到 `box` 是一种 affine type 。
相关的中文资料非常少,外文资倒是比较全,找个时间补上这个知识点。
@nanne007
nanne007 / theories supporting rust
Created September 15, 2014 03:28
Rust 的理论支持
1. affine type, region pointers. [Region-Based Memory Management in Cyclone](http://www.cs.umd.edu/projects/cyclone/papers/cyclone-regions.pdf)
@nanne007
nanne007 / fa.rb
Last active August 29, 2015 14:06
DFA and NFA
require 'set'
### finite automata rule
class FARule < Struct.new(:state, :character, :next_state)
def applies_to?(state, character)
self.state = state && self.character == character
end
def follow
next_state
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'