Samson’s Weblog

Technique

gem list

by Samson on Sep.02, 2010, under Ruby, Technique

响应蛋疼之号召,gem list一下,不过估计有点outdated,因为本人最近好几个月没碰ruby了,不过anyway,show了再说:

$ gem list --local | wc -l
147

为了有点视觉效果,特地把vertical scrollbar给干掉了,xd:
(continue reading…)

3 Comments : more...

From TextMate to MacVim: Vim installation

by Samson on Aug.24, 2010, under Share, Technique, Vim

本文分成两部分,前半部分介绍用macports安装terminal版本的vim,后半部分介绍gui版本的MacVim的安装,一般不推荐在macports里面安装vim的gui variants,想象一下编译的时间……

[MacPorts Vim Installation]
MacPorts的Vim 3天前刚刚更新到7.3.3,为了安装最新的版本,我们需要首先更新同步一下macports的port file tree:

$ sudo port -v selfupdate

安装之前先查看一下这个Vim包的variants:

$ port variants vim
vim has the variants:
   athena: Build GUI version using Athena widgets
     * conflicts with gtk1 gtk2 motif
     * requires x11
   big: Build big feature set
     * conflicts with small tiny
   cscope: Enable source code browsing with cscope
   gtk1: Build GUI version using GTK 1.x widgets
     * conflicts with athena gtk2 motif
     * requires x11
   gtk2: Build GUI version using GTK 2.x widgets
     * conflicts with athena gtk1 motif
     * requires x11
   huge: Build huge feature set
     * conflicts with big small tiny
   motif: Build GUI version with Motif widgets
     * conflicts with athena gtk1 gtk2
     * requires x11
   nls: National Language Support
   perl: Enable Perl scripting
   python: Compatibility variant, requires +python25
     * requires python25
   python25: Enable Python scripting
     * conflicts with python26 python27 python31
   python26: Enable Python scripting
     * conflicts with python25 python27 python31
   python27: Enable Python scripting
     * conflicts with python25 python26 python31
   python31: Enable Python scripting
     * conflicts with python25 python26 python27
   ruby: Enable Ruby scripting
   small: Build small feature set
     * conflicts with tiny
   tcl: Enable Tcl scripting
   tiny: Build tiny feature set
   universal: Build for multiple architectures
   x: Compatibility variant, requires +x11
     * requires x11
   x11: Build CLI version with X support
   xim: Build with support for X Input Method

(continue reading…)

2 Comments :, , more...

Terminal.app use option as meta key

by Samson on Aug.12, 2010, under Mac, Share, Tips

最近经常要在psql里输入很长很长很长很长的sql…要问有多长?答:很长,join多的都可以把hash-join temporary file搞到 “no space left on device” 的长…… ,然后蛋疼的case就是你写到很长的时候突然想修改句子中间的某个部分,注意是中间,不是开头也不是结尾,而你的光标还在行末朝你一闪一闪的…

你恨不得那时用鼠标能够点一下,但是很可惜这里是terminal,鼠标单击基本处于屏蔽状态;光标一个一个左移那是在考验你的毅力和忍耐力,你要时刻保持警惕不然就会漂移过头(一般此时容易睡着,所以那时我就很淡定的喝几口水,等光标移到后一般就可以去续杯了……);后来想到可以一个一个word的移啊,怎么这么傻… 由于bash默认是emacs的key binding,查了一下往前和往后移一个word的shortcut key是Meta-f和Meta-b,查这些花了1分钟不到,但是接下来2个多小时我一直在找这个Meta key…… 后来终于总算被我一个一个这么排列组合试出来了…… 做梦也没想到竟然是ESC… 可以想象一下同时按esc和b来往后移一个word的那种发自内心的不协调。

不过,最后还是顺利解决了(不然就没有标题,亦没有此文了),Terminal.app提供了一个选项帮助用户map option (就是alt) 到meta key,esc虽然还是meta,但显然我们更喜欢用大拇指去按alt (编者注:只要玩warcraft的人都知道用大拇指去按alt查看生命值那是多么重要的操作,哈哈)

最后附图一张,以作纪念:

14 Comments :, , more...

InfoQ文章推荐:年度绩效考评是一个“彻头彻尾的谎言”

by Samson on Jul.29, 2010, under Management, Share, Technique

我就贴个地址,我不多说话:
http://www.infoq.com/cn/news/2010/07/performance-appraisal

as always,评论和文章一样精彩,百家争鸣,集思广益才是解决问题的好方法,真理永远是越辩越明的,so… enjoy~

2 Comments :, more...

Bash variable unset or empty?

by Samson on Jul.27, 2010, under Bash, Technique

前几天开发遇到的诡异问题,最后总结下来就是标题所描述的case,怎么判断一个bash的variable到底是unset (undefined)还是set (defined)了只是正好是empty (“”)呢?

为了避免环境不同以及软件版本不同造成更大的confusion,这里先统一一下环境,以下命令或script都在如下环境下运行:

$ uname -a
Darwin mac.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386
$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.

[Source of the confusion: " -z "]
第一个solution是test的-z,也是confusion产生的根源。

test的manual这样解释-z:

NAME
     test, [ -- condition evaluation utility

SYNOPSIS
     test expression
     [ expression ]

DESCRIPTION
     -z string     True if the length of string is zero.

(continue reading…)

4 Comments :, more...

TextMate’s magic: bundles, customized commands, snippets and macros recording

by Samson on Jul.26, 2010, under Technique, TextMate

之前尝试过一段时间macvim后又转回了TextMate,想来我还是一个比较visual的人。都说“真正的程序员”都是用vi或是emacs的,不过有时候看着东西想用鼠标点却不能点,必须脑子里去想一下命令或是什么shortcut有时是不是也太隔靴搔痒了,这和五笔输入法其实很类似,重码少很高效很快速,但中断思路… 就是这么一个道理。
不过用久了也确实不排除熟能生巧的,所以我也对上面那句所谓的名言没有任何意见,比如退出vim的:q我基本不用思考 :)

好了闲话又扯远了……

[Bundles]
bundle应该是TextMate里名气最大的了,如果你熟悉eclipse的话,bundle其实和eclipse的plugin很像,虽然textmate也有plugin但bundle的应用显然要更为广泛,之于历史,特性,比较之类的请交给google,这不是我们这儿的focus。
一般TextMate一个release都会built-in一堆广泛使用并口碑较好的bundle,好的bundle很多以至于我本人从来是都是觉得bundle太多太眼花了,其实真正经常用到的bundle就这么几个,于是bundle的更新倒是成了更大的问题,好在TextMate继承了*nix的传统,会优先读取user home下的bundle,问题的解决于是变的异常之trivial。
以TextMate的ruby on rails bundle为例,安装只要几行命令:

mkdir -p ~/Library/Application\ Support/TextMate/Bundles
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/drnic/ruby-on-rails-tmbundle.git "Ruby on Rails.tmbundle"
osascript -e 'tell app "TextMate" to reload bundles'

下次更新只要git pull一下然后tell textmate to reload bundles就万事大吉了。
(continue reading…)

6 Comments :, more...

PHP dev & debug: var_dump, var_export, error_log and FirePHP (Part 2)

by Samson on Jul.02, 2010, under PHP, Technique

接上篇: PHP dev & debug: var_dump, var_export, error_log and FirePHP (Part 1)

前面介绍到的基本上都是php 5自带的,下面介绍一个third party的solution。

6. FirePHP
[Installation]
第三方工具不好的一点是需要另外安装,php不自带(不然就不叫 third party了…),FirePHP的安装包括2个部分,firefox plugin和php lib.

(1) Firefox Plugin
可以在这里找到FirePHP plugin的下载地址,由于其本质上其实属于firebug的extension/plugin,所以install之前确保firebug已经安装.

(2) php lib
official site给出了清晰的instructions:

sudo pear channel-discover pear.firephp.org
sudo pear install firephp/FirePHPCore

(continue reading…)

2 Comments : more...

PHP dev & debug: var_dump, var_export, error_log and FirePHP (Part 1)

by Samson on Jul.02, 2010, under PHP, Technique

总结一下最近比较常用或是刚刚发现觉得比较好用的php dev & debug tool,肯定不全面,欢迎大伙补充。

1. var_dump()
用法很简单,就是你要dump什么data就传给这个方法什么data(其支持可变参数,不过一般还是习惯一个data一个var_dump())。它的好处很像ruby里的PP(pretty print),不过limit是只能输出到标准输出(php-cli是输出到控制台,php网页便是browser).

<?php
$tools = array("var_dump", "var_export", "error_log", array("Firebug", array("FirePHP")));
var_dump($tools);
?>
array
  0 => string 'var_dump' (length=8)
  1 => string 'var_export' (length=10)
  2 => string 'error_log' (length=9)
  3 =>
    array
      0 => string 'Firebug' (length=7)
      1 =>
        array
          0 => string 'FirePHP' (length=7)

(continue reading…)

2 Comments : more...

Snow Leopard Headache

by Samson on Mar.29, 2010, under Life, Mac, Minds

今天终于升级到了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,这是晚点升级的好处,该碰到的问题人家应该都已经碰到了… 该解决的也已经解决了……
解决办法还是重装,一点脑子都不用动,全傻瓜式操作。
(continue reading…)

5 Comments :, , more...

Ruby gem geoip and Rack::GeoIPCountry

by Samson on Feb.25, 2010, under Ruby, Technique

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的麻烦。
(continue reading…)

3 Comments :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!