The Summer

August 15th, 2011 § 1 comment § permalink

暑气依旧弥漫,but the summer is over。
The Summer
一。尽管 SPX 以接连好几天的大幅振荡表示信心不稳,WTI 原油期货也跌回了 2011 年的起始点,金融市场是如此担忧我的离去,我还是不得不说白白,my summer is over。对不起了,全球的投资者们,在这危急的关头,我不能继续肩负起稳定和推动原油、天然气、活牛、瘦猪、堪萨斯小麦还有澳大利亚滑羊毛期货市场的重任,要留下你们孤军奋战了:)。
更需要我回到的是那更艰巨更漫长的屁爱取缔的劳作中,不过在那之前我将修个小假,沉淀一下心中的 volatility。In the meantime do some important thinking,reflect on what I’ve missed,what I’ve learnt and where to go。不过这次不像以往的夏末去北美大陆北方的草原河畔或是雪山,而是要回到祖国大陆,看看重要的人:P
Return Graph
二。夏天的起身离去也是新一轮来来往往的开始,而这来这往又都是发生在俗到不能再俗的餐桌上。最近一次宴席的主角是奥斯汀某无理念无愿景党派的重要人物。此君名号不雅,行事却实有大将之风。归去时,销声匿迹,远离腐败;归来时,统筹规划,花天酒地。此君目标明确,规划缜密,尤其擅长地道战,以及地道战成功之后在风平浪静中扔出原子弹。在大家瞠目结舌时,再咪一口小酒,道一声冷静冷静。虽颇有戏剧效果,然亦易造成混乱。行车时说已容易导致危险驾驶,饭局上说更易造成旁人酒后昏话,真是抱歉抱歉。此番此君将去北加湾区开始新的征程,定能开疆拓土,在那天时地利之域营造出新的人和。告别宴上埋下了回家的种子,以后也定能长相见。要说有什么祝愿的,就是多多享受北加的自然风光吧~

Twitter OAuth: a Simple Ruby Script

June 3rd, 2010 § 0 comments § permalink

We all want shortcuts.
As of the end of this month, Twitter will deprecate support for http authentication (provide username and password explicitly) in API request. The alternative is called OAuth and Twitter has a comprehensive guide here. However, it appears too complex to us, and what we need is a method as similar to http auth as possible, since for researchers like us, the sole purpose of using API request is to get data via a robot account.
Here is the simplest shortcut, illustrated in Ruby.

  1. Register an app at http://dev.twitter.com/apps/new, and you’ll get a consumer key and a consumer secret. From the page “my access token”, you can find an access token and an access secret.
  2. Write the four strings into a config file, e.g. $HOME/.twitter. Below is a yaml config example.
    #!/usr/bin/ruby -w
    # require 'pp'
    require 'yaml'
    
    CToken   = "AAAAAAAAAAAAAAAAAAAAA"
    CSecret  = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
    AToken   = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
    ASecret  = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
    
    config = {"ctoken" => CToken, "csecret"=>CSecret, "atoken"=>AToken, "asecret"=>ASecret}
    File.open("#{ENV["HOME"]}/.twitter", "w") do |f|
      f.puts config.to_yaml
    end
    
  3. Authorize your application in a script, using twitter gem.
    #!/usr/bin/ruby -w
    
    require 'pp'
    require 'yaml'
    require 'twitter'
    require 'mysql'
    
    conf = {}
    File.open("#{ENV["HOME"]}/.twitter", "r") { |f| conf = YAML.load(f) }
    
    # twitter authentication
    oauth  = Twitter::OAuth.new(conf["ctoken"], conf["csecret"])
    oauth.authorize_from_access(conf["atoken"], conf["asecret"])
    client = Twitter::Base.new(oauth)
    
    client.home_timeline.each { |tweet| pp tweet }
    exit