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
#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
@nanne007
nanne007 / reset-shift.scala
Created December 16, 2014 02:29
reset/shift in scala
class Shift[+A, -B, +C](val fun: (A => B) => C) {
def map[A1](f: (A => A1)): Shift[A1, B, C] = {
new Shift((k: A1 => B) => fun { (x: A) => k(f(x)) })
}
def flatMap[A1, B1, C1<:B](f: A => Shift[A1, B1, C1]): Shift[A1, B1, C] = {
new Shift((k: A1 => B1) =>
fun { (x: A) => f(x).fun(k) })
}
}
@nanne007
nanne007 / StreamOps.scala
Last active August 29, 2015 14:08
这代码写的我一点脾气都没有了
object Stream {
private def interleave[T](s1: Stream[T], s2: Stream[T]): Stream[T] = {
if (s1.isEmpty) s2
else s1.head #:: interleave(s2, s1.tail)
}
private def pairs[S, T](s: Stream[S], t: Stream[T]): Stream[(S, T)] = {
if (s.isEmpty || t.isEmpty) Stream.empty[(S, T)]
(s.head, t.head) #:: interleave(t.tail map ((s.head, _)), pairs(s.tail, t.tail))
}
#!/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'
@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
@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)
http://doc.rust-lang.org/guide-pointers.html#boxes 提到 `box` 是一种 affine type 。
相关的中文资料非常少,外文资倒是比较全,找个时间补上这个知识点。

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.

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
@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)
}
}