Skip to content

Instantly share code, notes, and snippets.

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.

from scapy.all import *
import requests
import time
MAGIC_FORM_URL = 'http://put-your-url-here'
def record_poop():
data = {
"Timestamp": time.strftime("%Y-%m-%d %H:%M"),
"Measurement": 'Poopy Diaper'
}
# Helper method to adding the fixtures into the tests
def fixtures(*files)
files.each do |file|
klass = begin
Kernel::const_get(Extlib::Inflection.classify(Extlib::Inflection.singularize(file.to_s)))
rescue
nil
end
entries = YAML::load_file(File.dirname(__FILE__) + "/fixtures/#{file}.yml")
# do a migrate to create the table to clear the records
# spec_helper.rb
# Helper method to adding the fixtures into the tests
def fixtures(*files)
files.each do |file|
klass = begin
Kernel::const_get(
Extlib::Inflection.classify(
Extlib::Inflection.singularize(file.to_s)))
rescue
nil
@zhhz
zhhz / link_to_action with confirmation.rb
Created November 11, 2008 19:20
link_to_action with confirmation
<VirtualHost *:80>
ServerName app.myapp.com
DocumentRoot /Users/zhonghai/apps/ruby/current/public
# setting the env to development
RackEnv development
</VirtualHost>
# setting the env to development
RackEnv development
<VirtualHost *:80>
ServerName app.myapp.com
DocumentRoot /Users/zhonghai/apps/ruby/current/public
</VirtualHost>
zooo = Zoo.all
File.open('zoo.yaml', 'w'){|f| f.puts zooo.to_yaml}
# dm 0.9.8 breaks YAML.dump
zooo = Zoo.all
File.open('zoo.yaml', 'w'){|f| YAML.dump(zooo, f)}
z1 = Zoo.all(:condition.....)
z1.to_yaml # this OK
z2 = Zoo.all(:condition...)
z2.to_yaml # this OK
z3 = z1 + z2
z3.to_yaml # bam!. ERROR