Skip to content

Instantly share code, notes, and snippets.

@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
@tony612
tony612 / arcanist_cheatsheet.md
Last active July 7, 2023 05:29 — forked from sekimura/gist:6367366
arcanist cheatsheet
  • create tasks T{NNNN} asign them
  • create a branch with name like "T{NNNN}-boo-hoo"
  • git checkout -b T1234-boo-foo
  • commit changes on that branch until it gets ready to be reviewed
  • git commit -am 'first'
  • git commit -am 'now it works'
  • check if it's lint free (NOTE: it runs lint against only modified files)
  • arc lint
  • push a review request to the server. This will create a diff with id D{NNNN}
  • arc diff

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.

#!/usr/bin/env bash
# Pre-requisites
sudo apt-get -y update
sudo apt-get --no-install-recommends -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev vim
# Download and compile Ruby 2.0.0-p0
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
tar -xvzf ruby-2.0.0-p0.tar.gz
# http://unfoldthat.com/2012/06/02/quick-deploy-chef-solo-fabric.html
from fabric.api import settings, run, sudo, reboot, put, cd, env
AWS_ACCESS_KEY = '...'
AWS_SECRET_KEY = '...'
AWS_KEYPAIR_NAME = '...'
AWS_SECURITY_GROUPS = ['default']
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
@tony612
tony612 / label_required.rb
Last active August 29, 2015 14:05
A nice way to add asterisk* to "required" field in frontend used with https://github.com/amatsuda/html5_validators
# config/initializers/label_required.rb
module ActionView
module Helpers
# For rails 4
if ActionPack::VERSION::STRING >= '4'
module Tags
class Label
def render_with_required(&block)