Jim Cheung

Tuesday, September 19, 2012

Class starts: Functional Programming Principles in Scala

Tools setup:

Thursday, September 20, 2012

vim tips: execute script while editing

autocmd BufNewFile,BufRead *.rb set makeprg=ruby\ %

type :make to run

a simple ruby line to generate mark six numbers

a=[]; 6.times do a << (1..49).to_a.sample end; a.sort!; p a

update: a better way which handles redundancy

a=[];until a.size.eql? 6 do a.push((1..49).to_a.sample).uniq! end;p a.sort!

update 2: a short version

p (1..49).to_a.shuffle.first(6).sort

Friday, September 21, 2012

found a ruby irb on android, which is open sourced too.

read a few chapters of Learn Vimscript the Hard Way, every chapter is short and clear, quite nice. added some mapping to my .vimrc too. I agree that after mapping <esc> to jk, editing could go more smoothly. still need some time to train the muscle.

jQuery just released 1.8.2, I've updated to latest version also.

Saturday, September 22, 2012

android apps I'm using daily

setting up dropbox client

although only python and ruby sdk are mentioned in dropbox documentation, you can use any language (php below) since it is restful. I bet you can find an unoffical php sdk on github easily, however, start from scratch is easy too.

dropbox uses oauth, to get a request token:

  1. setup an app, in order to get app-key and app-secret-key
  2. prepare post data (http://oauth.net/core/1.0/#auth_step1)
    $post_data = array(
      'oauth_consumer_key' => $app_key,
      'oauth_signature_method' => 'PLAINTEXT',
      'oauth_signature' => $app_secret . '&', // with tailing &
      'oauth_timestamp' => time(),
      'oauth_nonce' => md5(microtime()), // random string for every request, microtime is enough for low traffic site
      'oauth_version' => '1.0'
  3. curl https://api.dropbox.com/1/oauth/request_token with $post_data, if succeeded, you will get oauth_token_secret and oauth_token for future requests.
Blog Archive