Skip to content

Instantly share code, notes, and snippets.

@tony612
tony612 / new_server_setup.rb
Last active August 29, 2015 13:56
Setup a new server for rails
# login to server
$ ssh root@123.45.67.890
# change password
$ passwd
# add user
$ adduser user
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
curb (0.6.2.1)
em-http-request (0.2.5)
eventmachine (0.12.10)
typhoeus (0.1.13)
user system total real Memory (Kb)
4kb std
0.000000 0.000000 3.010000 ( 22.408594) 24,484
@tony612
tony612 / .travis.yml
Created March 15, 2014 18:09
travis.ci
# Notice:
# ci will fail when the coverage is less than the minimum coverage
bundler_args: --without development production
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- ruby-head
namespace :figaro do
desc "SCP transfer figaro configuration to the shared folder"
task :setup do
transfer :up, "config/application.yml", "#{shared_path}/application.yml", :via => :scp
end
desc "Symlink application.yml to the release path"
task :finalize do
run "ln -sf #{shared_path}/application.yml #{release_path}/config/application.yml"
end
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@tony612
tony612 / fibonaci.rb
Last active August 29, 2015 13:57
Algrithom
def fibonaci1(n)
return n if n <= 1
fibonaci1(n - 1) + fibonaci1(n - 2)
end
def fibonaci2(n)
helper = lambda do |a, b, i|
return b if i <= 1
helper.call(b, a + b, i - 1)
end
$ mkdie foo
$ cd foo
$ git init
$ npm init
$ atom Makefile
compile:
coffee --compile --output lib src
test: compile
mocha
package: test
@tony612
tony612 / validation.coffee
Last active August 29, 2015 13:59
A very simple validation used with twitter bootstrap
$('.register-modal #send_to_congress').click ->
validated = true
$('form .validating').each ->
$parent = $(@).parent()
$(@).keyup ->
if !@value
$parent.removeClass('has-success').addClass('has-error')
else
$parent.removeClass('has-error').addClass('has-success')
@tony612
tony612 / find_ids.rb
Created May 9, 2014 17:32
Rate limit exceeded based on Twitter wiki
def find_friend_ids(client, uid)
uid = uid.to_i
following_ids = Thread.new { client.friend_ids(uid) }
follower_ids = Thread.new { client.follower_ids(uid) }
TwitterHelper.handle_rate_limit { following_ids.value.to_a } &
TwitterHelper.handle_rate_limit { follower_ids.value.to_a }
end

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.