media downloaded from google.cn music (oh no, it’s still .cn and it’s still available…) Fool’s Garden - Lemon Tree I’m sitting here in the boring room It’s just another rainy Sunday afternoon I’m wasting my time I got nothing to do I’m hanging around I’m waiting for you but nothing ever happens and I wonder I’m driving around in my car I’m driving too fast I’m driving too far I’d like to change my point of view I feel so lonely I’m waiting for you but nothing ever happens and I wonder I wonder how I wonder why yesterday you told me about the blue blue sky and all that I can see is just a yellow lemon tree I’m turning my head up and down I’m turning turning turning turning turning around and all that I can see is just another lemon tree I’m sitting here I miss the power I’d like to go out taking a shower but there’s a heavy cloud inside my head I feel so tired put myself into bed well, nothing ever happens and I wonder Isolation is not good for me Isolation I don’t want to sit on the lemon tree I’m stepping around in the desert of joy baby anyhow I’ll get another toy and everything will happen and you wonder I wonder how I wonder why yesterday you told me about the blue blue sky and all that I can see is just another lemon tree I’m turning my head up and down I’m turning turning turning turning turning around and all that I can see is just a yellow lemon tree and I wonder, wonder I wonder how I wonder why yesterday you told me about the blue blue sky and all that I can see, and all that I can see, and all that I can see is just a yellow lemon tree
24 - Jack & Renee
[pro-player width=”480” height=”320”]http://blog.samsonis.me/wp-content/uploads/2010/04/24-jack-renee.mp4\[/pro-player\] [via youtube]
Some things we don’t talk about Rather do without just hold the smile Falling in and out of love Ashamed and proud of Together all the while You can never say never Why we don’t know when But time and time again Younger now than we were before Don’t let me go Don’t let me go … Picture, you’re the queen of everything As far as the eye can see Under your command I will be your guardian When all is crumbling Steady your hand You can never say never Why we don’t know when Time, time and time again Younger now then we were before Don’t let me go Don’t let me go … We’re pulling apart and coming together again and again We’re growing apart but we pull it together pull it together, together again Don’t let me go Don’t let me go …
Update-31: The best revenge is massive success
1. 尝试在标题中加点主题,主要为了make it searchable,以后写下标题后3s内有灵感的话就会考虑加上,没有的话还是会fall back到default,这样我也不用为了非要整出个标题而纠结不已. 2. The best revenge is massive success. 不知道当初命名sinatra的时候Blake是不是也带着这份双关的涵义,whatever,bible said love your enemies… 3. 清明公墓纷杂烦扰,熙熙攘攘,忙碌的人流中丝毫感受不到任何应有的气氛,当某种仪式落俗到只剩形式,迷信与否也许也只是一念之差…… 4. 终于明白“湿”疹这个名字的涵义,汉语果然是博大精深…… 上周一位德高望重的医生的忠告便是无论如何需要保持干燥,真可谓是治其根本呵呵~ 看了下去年刚得病时的update,时间差不多正好一年,不禁感叹其周期的准确…… 5. 没有参加过QCon,不过既然sunng羡慕如此,我也跟风表达一下羡慕tiger之情,呵呵~ 6. always prepared for “cheat” sheet, trust me, this is really awesome~
The Rose
这个版本也是昨天开心上刚刚看到的,这位名字有点难写也有点难读的(手嶌葵)歌手用其天籁般的声音诠释了歌曲新的意境,分享给大家~ google.cn music(没错,还是google.cn…)上找到的都是吉他伴奏的,但说实话我更喜欢其钢琴版的,一直感觉背后的钢琴旋律才是歌曲的灵魂…简单的旋律蕴涵着无限的意境。 [pro-player width=”360” height=”300”]http://blog.samsonis.me/wp-content/uploads/2010/04/The-Rose.flv\[/pro-player\]
Some say love, it is a river that drowns the tender reed Some say love, it is a razor that leaves your soul to bleed Some say love, it is a hunger an endless, aching need I say love it is a flower and you its only seed It’s a heart afraid of breaking that never learns to dance It’s a dream afraid of waking that never takes that chance It’s the one who won’t be taken who cannot seem to give and a soul afraid of dying that never learns to live When the night has been too lonely and the road has been too long and you think that love is only for the lucky and the strong just remember in the winter far beneath the bitter snows lies the seed that with the sun’s love in the spring becomes the rose
Snow Leopard Headache
今天终于升级到了snow leopard,因为终于准备好了要折腾了,这一准备还准备了半年,版本都从当时的10.6升到10.6.2了,黄花菜都那啥了都…… 1. zimbra desktop 邮件是第一个发现的问题,因为一升级完就要开,还是迫不及待的…瞧我多那啥…… 这个就是我平时用的邮件客户端,其实用不用都无所谓的,邮件本质上和gmail差不多,都是属于“在云端”,zdesktop本身也属于firefox的wrapper,用它和用firefox本质没啥区别,不过既然平时用的习惯了也就习惯了。 snow leopard后zdesktop就launch不了了,查了log然后google发现解决办法具彻底 —— 重装…… 好吧,not a good start,but anyway…… 2. system upgrade & update 接下来似乎很平静,没有发现啥问题,只是系统提示有具多的update,于是downloading和等着update,和平时的windows update没啥区别。这是顿感轻松,顺便还和同事开了开玩笑,世界真美妙…… 那时的感受是什么呀,和装个windows的新版本差不多嘛,除了windows升级一般是占更多的硬盘更多的系统资源,而mac升级则是给我省出了7G空间(后来升级完xcode后发现没有省那么多,现实是如此残酷)。 3. afloat 系统升级下载完了要安装的时候问题来了,系统频繁的问我要密码,敲了一边过去了转身马上又问,问完继续又问…… 于是继续google,这是晚点升级的好处,该碰到的问题人家应该都已经碰到了… 该解决的也已经解决了…… 解决办法还是重装,一点脑子都不用动,全傻瓜式操作。 4. firefox 好吧,我承认这不是升级搞出来的问题,纯粹属于历史遗留下来的问题,不过既然今天开始折腾了那索性一起搞搞干净。其问题是之前firefox升级失败然后就一直无法升级了,和这里描述的差不多,不过上边的解决办法是windows的,我在mac上面始终无法找到相应的updates目录,于是放弃…… 最后solution:重装…… 本来以为所有add-on也要重装一遍的,后来发现所有add-on全部放在我home目录下,好吧此时不重装更待何时。 5. iphone sdk & xcode 升级snow leopard的根本原因之一就是为了升级这玩意,因为最新的xcode 3.2需要snow leopard,升级没有遇到啥问题,但是就是好大呀,6G多…… 之前好不容易省下7G又还回去了…… 螳螂捕蝉,黄雀在后呀…… 6. 最后大boss之macports 由于snow leopard升级改了arch(i386 -> x86_64),所以之前凡事configure, make, make install的都要小心为妙。 担心不是不无道理的,macports就是最大的受害者,这是macports官方的migration instruction,看完直接晕过去… 又是重装…… 而且是全部删掉全部重新编译…… 这个工作量…… 好吧,好身体,抵抗力…… 7. TBD 目前还在重装macports编译各种悲剧的过程中(cpu高负荷运转,风扇狂转中…),由于编译实在无聊,所以过来啰嗦几句,也不知道后面还有没有啥隐藏boss…… 不过anyway,so far so “good”…… Conclusion: 今天我整个就是一重装党,重装正在进行,悲剧还在继续……
Update-30
update:刚刚看到google.cn redirect到google.hk的消息(不知道算不算退出中国,退出大陆吧算),顺便提一下之前看到的西厢计划,更新在#item 8。 1. long time no update? well, that’s true, 确实很久不update了,以至于title里的update number都整了我很久,老眼昏花不算,记性也不好了唉,好吧,但愿我没搞错标题…… 2. alright, the 2nd question may always be: why? too busy? 最近其实还好,it turns out 没有最忙,只有更忙,呵呵~ 希望大家都身体安康,health is always the most important thing. 3. 最近比较focus,这也是为什么大家最近看不到我有任何tweet,IM也不活跃的原因,twitter就我个人而言,noise已经多于info(可能也和我之前乱follow人有关,以后有空unfollow或block一些),每次看到几分钟popup一堆growl提示说多少多少new tweets,我总是很紧张,obviously,这俨然已经是一个information爆炸的时代,好吧,那就关掉我的tweetie,让那边爆炸去吧。 同理,IM的growl提示也被我暂时disable了,原因是经常有人msn client出问题(公司msn有问题那可已经是高山上倒马桶了……),频繁上线下线,平均5s popup一次提示我,我想我即便能坚持到现在估计也离去精神病院不远了…… 4. 我向来自诩从不hesitate to say no(经常耐着性子看我update的同学估计都或多或少被鄙人这样或那样的拒过,呵呵,but don’t get me wrong,那说明我 take you seriously,that’s why i don’t hesitate to do that :) ,如果这是狮子座的特点的话,我觉得这点我还蛮typical的,呵呵),不过这个自诩貌似已经越来越不靠谱了(开始向不typical转变?),原因是我发现我最近接受了很多内心很想拒却都没有拒的invitation,which turned out to be a mistake…… PS:如果某位看官碰巧最近约过我,我又正好有赴约的话请不要对号入座以为我这里就是在说你(你不知道我在说什么的啦),如果你想了半天还是觉得我就是在说你,好吧,那么大家都反省一下也不是没有好处的,呵呵~ 5. 老罗成名短句 —— 彪悍的人生不需要解释,好吧,我承认我的人生不彪悍,我还是需要时不时的那么解释一下子的,但有时候最无奈的是你想解释却无从解释,于是本不该彪悍的人生就这样被迫开始彪悍了…… 不知道为啥我突然联想到了大禹治水(汗,这思维发散的……),人都说大禹三过家门而不入,怎么怎么,好吧,我没说大禹怎么不好,功劳那是摆着的,但问题是大家怎么就知道大禹不回家那是因为一心治水呢,大禹自己又没有解释,说不定和老婆吵架了,斗气不回或是老婆不让回呢,哈哈…… 要是真是那样,那大禹的人生亦在那时开始被迫彪悍了…… 6. 上海的鬼天气终于似乎好像稍微正常一点了,之前气温不是猛升就是陡降,每次那样我都要小感冒一下,我纳闷我这白细胞就这么没有免疫功能的吗,学不会么看也看会了呀,于是质问它们,语气颇为强烈,但得到的回应却异常不屑:“彪悍的胞生亦不需要解释”…… 7. 软件开发现在倡导deploy early, deploy often,我发现现在改成update貌似也说的通,呵呵,which is update early, update often. 8. 之前看到西厢计划的时候确实是眼前一亮,虽然了解了一下后发现其实际操作起来还是有点问题的(其本质是通过在tcp/ip建立连接时候的sync/ack三路握手里面做手脚以达到迷惑墙的目的,但如果三路的第一个sync request就发不出去呢,唉…),但确实为咱们劳苦大众翻墙提供了从tcp/ip协议栈挖掘的新思路,这点绝对是功不可没。除此之外,我们还看到了follow rfc标准的重要性,下次看到rfc里面什么should还是当作must have实现吧,说不定以后哪天这个should实现就成为张某翻墙看莺莺所不可或缺的梯子了…… 9. alright, that’s all for today’s episode, stay tuned and see u next time. thanks for watching.
Ruby gem geoip and Rack::GeoIPCountry
wikipedia上对于geolocation的解释是这样的:
Geolocation is the identification of the real-world geographic location of an Internet-connected computer, mobile device, website visitor or other.
检测的方法貌似也有很多:
Geolocation can be performed by associating a geographic location with the Internet Protocol (IP) address, MAC address, RFID, hardware embedded article/production number, embedded software number (such as UUID, Exif/IPTC/XMP or modern steganography), invoice, Wi-Fi connection location, or device GPS coordinates, or other, perhaps self-disclosed information.
(班门弄斧一下先,呵呵呵呵) ruby里面取到geo信息的一个相对方便的办法是使用rubygem geoip,虽然本质上还是使用maxmind的data,但是免去了编译和安装其c library的麻烦。 安装gem并下载其depend到的geoip database: [cc lang=”bash”] $ sudo gem install geoip [/cc] [cc lang=”bash” nowrap=”false”] $ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz && gunzip GeoIP.dat.gz [/cc] 如果想要城市信息,还可以下载稍微大一点的带city info的free database: [cc lang=”bash” nowrap=”false”] $ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz && gunzip GeoLiteCity.dat.gz [/cc] 简单的测试一下: [cc lang=”ruby”] require ‘rubygems’ require ‘geoip’ p GeoIP.new(‘GeoIP.dat’).country(“google.com”) p GeoIP.new(‘GeoLiteCity.dat’).city(“baidu.com”) [/cc] alright, looks good: [cc lang=”bash”] [“google.com”, “66.249.91.104”, 225, “US”, “USA”, “United States”, “NA”] [“baidu.com”, “220.181.6.81”, “CN”, “CHN”, “China”, “AS”, “22”, “Beijing”, “”, 39.9289, 116.3883] [/cc] 由于geo的普遍性,把其做成可以plug&play的Rack middleware绝对是个好主意,这就是接下来要介绍的Rack::GeoIPCountry,CodeRack Contest的first place。 其原理就是调用geoip gem获得访问IP的geo信息并写入request header,这样后面的app或者middleware就能读到并处理了。 同样写个简单的middleware测试一下: [cc lang=”ruby” lines=”-1”] require ‘geo_ip_country’ class GeoTest def initialize(app) @app = app end def call(env) puts “Remote Address: #{env[‘REMOTE_ADDR’]}” puts “GeoIP Country ID: #{env[‘X_GEOIP_COUNTRY_ID’]}” puts “GeoIP Country Code: #{env[‘X_GEOIP_COUNTRY_CODE’]}” puts “GeoIP Country Code3: #{env[‘X_GEOIP_COUNTRY_CODE3’]}” puts “GeoIP Country: #{env[‘X_GEOIP_COUNTRY’]}” puts “GeoIP Continent: #{env[‘X_GEOIP_CONTINENT’]}” @app.call(env) end end use Rack::ContentLength use Rack::GeoIPCountry use GeoTest run Proc.new { |env| [200, { ‘Content-Type’ => ‘text/html’ }, ‘OK’] } [/cc] rackup起来后,访问http://localhost:9292,确认console下输出了我们想要的geo信息: [cc lang=”bash”] Remote Address: 127.0.0.1 GeoIP Country ID: 0 GeoIP Country Code: – GeoIP Country Code3: – GeoIP Country: N/A GeoIP Continent: – 127.0.0.1 - - [25/Feb/2010 16:36:11] “GET / HTTP/1.1” 200 2 0.0016 [/cc] 当然上面的127.0.0.1是不会有任何信息的,local network也是不会在database里面找到对应的,只有当真正的外网ip hit到我们的server时,我们才能看到有意义的geo信息。
关于Mac的Safe Sleep和Hibernate
据说Apple早在2005年10月发布Mac OS X 10.4.3的时候就已经加入了safe sleep这个功能,但是GUI界面上却至今始终对用户透明,用户在不装任何3rd party tools的情况下永远只能看到sleep而没有hiberate之类的选项。 但是此sleep又并非完全等同于我们平时常说的”suspend to RAM”(2005.10之前可能相同),它背后其实也做了”suspend to disk”,也就是PC上的hibernate的工作,实为明修栈道,暗渡陈仓。 这样做的好处也成了后来Apple命名此技术的offical name —— “safe sleep”,因为它解决了单纯”suspend to RAM”下电源耗完或故障导致的RAM信息丢失问题:其会在电源不足的情况下自动切换到”suspend to disk”,着实”smart and safe”。 但有趣的是,苹果似乎从来没有高调宣布过这项当时可能不新不revolutionary但确实对用户而言很实用的功能,for some “unknown” reason。 在大多数的情况下,用户可能并不会察觉这背后的不同,事实上我觉得Apple要不是考虑到了切换到”suspend to disk”后restore回来用户会等很久的user experience问题,而加入了这个progress bar, 很少真的会有用户察觉。 到了10.5,safe sleep似乎终于有了offcial的解释,但是总感觉好像简单了点,不知道你和我是否感觉一样,低调么也不带这样的… 系统早就有这个capability,但4年多后的今天普通用户却还是要很麻烦的来使用,Apple提供了一个命令行工具pmset来帮助用户进行power management,其中很多选项在”System Preferences… -> Energy Saver”里面都能找到对应,但是却偏偏没有关于hibernate mode的。 相应的信息如果不联网的话需要在命令行下用man pmset查看,可以看到pmset可以设置autorestart等10多个参数,与hibernate有关的有两个参数分别叫hibernatemode和hibernatefile,你会有趣的发现只有这两个参数后面跟了句”Please use caution.”,这是不是让你联想到了什么? ========================== 历史,背景以及浮想联翩的分界线 ========================== 下面我们来看看究竟怎么在Mac上hibernate,底下是man pmset里关于hibernatemode参数设置的描述: [cc lang=”bash” lines=”-1”] hibernatemode takes a bitfield argument defining SafeSleep behavior. Passing 0 disables SafeSleep altogether, forcing the computer into a reg- ular sleep. 0001 (bit 0) enables hibernation; causes OS X to write memory state to hibernation image at sleep time. On wake (without bit 1 set) OS X will resume from the hibernation image. Bit 0 set (without bit 1 set) causes OS X to write memory state and immediately hibernate at sleep time. 0010 (bit 1), in conjunction with bit 0, causes OS X to maintain system state in memory and leave system power on until battery level drops below a near empty threshold (This enables quicker wakeup from memory while battery power is available). Upon nearly emptying the battery, OS X shuts off all system power and hibernates; on wake the system will resume from hibernation image, not from memory. hibernatemode is set to 3 (binary 0011) by default on supported porta- bles. hibernatemode is set to 0 (binary 0000) by default on supported desktops. Please note that hibernatefile may only point to a file located on the root volume. [/cc] 可以看到portables默认的模式就是所谓的safe sleep(hibernatemode = 3)。 修改之前先查看一下当前系统使用的hibernate相关参数设置,我没有修改过(事实上之前都不知道怎么修改),应该就是默认的配置: [cc lang=”bash”] $ pmset -g | grep hibernate hibernatefile /var/vm/sleepimage hibernatemode 3 $ ls -lh /var/vm/sleepimage -rw——T 1 root wheel 2.0G Feb 23 10:09 /var/vm/sleepimage [/cc] 设置系统使用hibernate模式(hibernatemode = 0001)进行sleep: [cc lang=”bash”] $ sudo pmset -a hibernatemode 1 [/cc] 这时如果再按普通方式sleep的时候mac就会hibernate了,想要切换回safe sleep只要把hibernatemode修改回来就行了: [cc lang=”bash”] $ sudo pmset -a hibernatemode 3 [/cc] 如果不喜欢命令行操作,可以使用第三方工具,实现机制应该是一样的,我所知道的有smartsleep和deep sleep这两个,不过我都还没有测试过。
未成年先别優
今天偶然看到的 —— 好孩子的軟體設計心得(機車版),看着标题和表达习惯的第一感觉是貌似可能在墙外,不过还没验证过,如果是的话大家know what to do。 话说台湾人翻译起来有时还真的蛮有意思的,意思老有双关甚至三关,关键在于你的想象力,呵呵,摘录一句本来不好笑的经典名言但我看着就是老想笑的:
未成年就這麼優,是一切邪惡的根源 Premature optimization is the root of all evil
看完这句,你又想到了什么evil?
List performance: ruby 1.8 and 1.9 (Part 2)
接上篇: List performance: ruby 1.8 and 1.9 (Part 1) 有了之前的准备和热身,真正跑起步来似乎轻松不少,先贴上我们用来benchmark的code: [cc lang=”ruby”] require ‘benchmark’ n = ARGV.empty? ? 10 6 : 10 ARGV[0].to_i puts “n=#{n}” Benchmark.bmbm do |x| x.report do list = [] n.times do list << 0 end end end [/cc] 和之前用来benchmark loop performance的code结构上基本没有区别,这里不再赘述,具体的解释亦可参照前文。 下面分别是ruby 1.8和ruby 1.9的一次完整运行( n=10~10^8 )的数据结果(也是我唯一运行的一次…) ruby 1.8: [cc lang=”bash”] n=10 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000014) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000012) ============================================== n=100 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000118) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000061) ============================================== n=1000 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000375) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000314) ============================================== n=10000 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.002900) ————————— total: 0.000000sec user system total real 0.010000 0.000000 0.010000 ( 0.002790) ============================================== n=100000 Rehearsal ———————————— 0.030000 0.000000 0.030000 ( 0.027712) ————————— total: 0.030000sec user system total real 0.020000 0.000000 0.020000 ( 0.027713) ============================================== n=1000000 Rehearsal ———————————— 0.280000 0.010000 0.290000 ( 0.323298) ————————— total: 0.290000sec user system total real 0.280000 0.010000 0.290000 ( 0.283621) ============================================== n=10000000 Rehearsal ———————————— 2.740000 0.050000 2.790000 ( 2.809917) ————————— total: 2.790000sec user system total real 2.760000 0.040000 2.800000 ( 2.810491) ============================================== n=100000000 Rehearsal ———————————— 27.410000 0.490000 27.900000 ( 28.164103) ————————– total: 27.900000sec user system total real 27.620000 0.480000 28.100000 ( 28.230073) ============================================== [/cc] ruby 1.9: [cc lang=”bash”] n=10 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000068) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000012) ============================================== n=100 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000038) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000032) ============================================== n=1000 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.000297) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.000209) ============================================== n=10000 Rehearsal ———————————— 0.000000 0.000000 0.000000 ( 0.002164) ————————— total: 0.000000sec user system total real 0.000000 0.000000 0.000000 ( 0.002025) ============================================== n=100000 Rehearsal ———————————— 0.020000 0.000000 0.020000 ( 0.020366) ————————— total: 0.020000sec user system total real 0.020000 0.000000 0.020000 ( 0.020873) ============================================== n=1000000 Rehearsal ———————————— 0.190000 0.010000 0.200000 ( 0.208302) ————————— total: 0.200000sec user system total real 0.190000 0.000000 0.190000 ( 0.208822) ============================================== n=10000000 Rehearsal ———————————— 1.920000 0.050000 1.970000 ( 2.050276) ————————— total: 1.970000sec user system total real 1.920000 0.050000 1.970000 ( 2.054335) ============================================== n=100000000 Rehearsal ———————————— 19.220000 0.460000 19.680000 ( 20.466960) ————————– total: 19.680000sec user system total real 19.220000 0.460000 19.680000 ( 20.546417) ============================================== [/cc] 就这次运行的结果而言,ruby 1.9的performance平均都有25%~35%的提升,加之Part 1测试过的循环性能的倒退,则更可以确定list append操作的performance确实在1.9里面较1.8有了很大的提高。