顯示具有 Computers 標籤的文章。 顯示所有文章
顯示具有 Computers 標籤的文章。 顯示所有文章

2011年1月26日 星期三

OS/X Server Default Gateway 卡死事件

把 Mac Mini Server 從上海帶回台灣,打算放在家裡當做 VPN server 來用。既然是 OS/X Server,就不用客氣,直接接上寬頻 modem 應該就可以了,不過接上去以後,發現怎樣都不會動,用 netstat -r  看了一下,發現 default gateway 變成 192.168.121.254。

想了很久,才想起來這是第一次在上海辦公室設定這台 server 的時候,因為一時手滑加上沒有好好 RTFM,所以設定得相當混亂。當時把 en0 設定為固定 IP,default gateway 也就定下來了。

依照一般的常理,只要是 DHCP 在這個 interface 上取得了動態的 ip, gateway, dns 等等設定,之前設定過的靜態 ip 和配置應該就會自動失效,不過 OS/X Server 的怪癖性好像不會依照常理而行,每次 reboot 都告訴我 default gateway 還是 192.168.121.254,變成 dyndns 也完全無法正常動作。

/etc 裡面的設定檔都找過了,只好使出 grep 大法,跑到 '/' 底下用 'grep -r 192.168.121 *',最後才發現,在 /Library/Preferences/SystemConfiguration 裡面,有兩個檔案有這個字串,一個是 com.apple.network.identification.plist, 另外一個則是 preferences.plist。根據此處的說明,這兩個檔案分別控制了所有連接過的網路以及不同位置的網路喜好配置。

從這兩個檔案裡面把 192.168.121 相關的東西全部清掉、reboot,這下子 default gateway 就正常了。

下一步,VPN!

2010年11月12日 星期五

How to add numbers using AWK

awk 'BEGIN{total=0}

{total += $1}

END{print total}'

 

2010年8月25日 星期三

SSH Connection Multiplexing And DynamicForward Control Script

一直以來,上網在中國就是個大問題,很多東西因為有萬里防火牆的關係無法 access,比如 twitter、facebook、wikipedia。來了中國以後,一直都是依靠塞外的機器做 ssh tunnel。最早的時候用的是 local port forward,需要在 remote machine 上面建 http proxy,然後用以下的語法連到遠端的 http proxy 去:

ssh -f -N -L <local port number>:<http proxy hostname>:<http proxy port> <user>@<ssh login hostname>

這樣 data 的傳遞路徑是  Application -> local port -> SSH -> login host -> proxy host,通常 login host 就是 proxy host,但是也可以不一樣,以前用過家裡的機器當做 ssh host,然後 proxy host 設定成 proxy.seed.net.tw,這樣指令就變成

ssh -f -N -L 1080:proxy.seed.net.tw:1080 myname@home.machine

-f 是要求在輸入密碼(或是不需要輸入密碼)後,ssh process 就到背景去執行,-N 則是要求進入背景後不需要 timeout,也就是說不管這個tunnel上有沒有資料傳送,都一直維持連接的狀態。這樣再把 browser 的 http proxy 設定成 localhost:1080就可以開始用了。
這樣的作法有兩個問題:

  • 只有 http/https protocol 可以用
  • 控制這個 tunnel 的建立和停止機制很麻煩,只能用 ps -auxwww|grep ssh 找出 pid 然後送 -9 給它。

後來發現了有 -D 這個 option,可以建立 SOCKS4/SOCKS5 proxy,就可以把指令改為:

ssh -f -N -D 1080 <user>@<ssh login hostname>

其中的 -g 表示打開 GatewayPort,讓別的機器也可以把這個 port 當做 proxy 來用。改成這樣以後,OS/X 上只要可以用 SOCKS4/SOCKS5 的程式(幾乎是所有會 honor 系統 proxy 設定的程式)都可以用到這個 proxy,而不僅限於 http/https protocol。

只是改成這樣還是無法解決第二個 control 的問題,每次都還是要很工人智慧去用 ps, grep, kill。一直到昨天晚上看到 OpenSSH 5.6 的 release 公告,才重新發現有個叫做 multiplexing connection 的東西。

這個功能其實從 OpenSSH 3.9 就已經放進去了,主要是提供一個 local unix socket,透過這個 socket 重複使用已經建好的 connection,省去 authentication handshake 的時間。這個功能要在 .ssh/config 裡面設定

ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h:%p

這樣建一個 tunnel 或是啟動任何 ssh session 就會在這裡生一個新的 socket 出來,並且把這個主要的 connection 設定為 Master,以後建立到同樣的 user@host 的 ssh connection 就會利用這個 local socket 來 multiplex。對於這個 Master 我們可以送一些控制的 command,目前只有兩個(according to the manpage)exit 和 check。送 exit 當然就會讓 Master 結束,送 check 的話,會 return 這個 Master 目前的狀態和使用的 pid。看到了嘛?出現 pid 了喔,好像可以解決上面第二個問題了,但是有個更簡單的方法,直接送 exit 就好了。所以最後簡化了建立 SOCKS tunnel 的 shellscript,變成如下的片段:

 #!/bin/sh
port=1080
ssh=/usr/bin/ssh


if [ "$2" = "" ] ; then
echo 'Usage: '$0' {start|stop|check} user@hostname'
fi

if [ "$2" = "start" ]; then
$ssh -f -g -D $port -N $1
fi

if [ "$2" = "stop" ]; then
$ssh -D $port -O exit $1
fi
if [ "$2" = "check" ]; then
$ssh -D $port -O check $1
fi

加上 host, hostname 的設定,就可以用 ./socks.sh start hostname 這樣的形式來啟動 tunnel,然後用 ./socks.sh stop hostname 來停止,用 ./socks.sh check hostname 來檢查目前的 tunnel 狀態了。

 

2010年7月28日 星期三

繼續昨天的奮鬥──Subversion + Trac on Solaris, Part 2

今天花的時間比較少,但是一樣遇到問題。

依照昨天的作法,已經把所有該 compile 的東西都 compile 好了,但是今天啟動 apache 的時候才發現,mod_dav_svn 和 mod_authz_svn 這兩個 module 版本和 Solaris 內建的 Apache 不合。內建的是 2.0.x 系列,Collabnet 上面抓下來的是給 2.2 系列用的。所以……係裡~又要自己來惹~

參考了這篇文章,先去這裡抓 subversion 最新版的 source 回來。後來發現直接用 Sun Studio 12 也可以順利 compile,唯二的麻煩是 neon 和 sqlite3;這兩個 lib 在系統裡面都是沒有的,要另外抓。sqlite3 要抓這個版本,neon 要抓這個

sqlite3 裡面有個 sqlite3.c,解開後放在 subversion/sqlite-amalgamation 底下,然後把 neon 整個放在 subversion/neon 下。這時還要解決 ld 找 library 的問題。

Solaris 下,常用 LD_LIBRARY_PATH 來取得 ld(1) 找 library 的位置,但是也可以用 crle(1) 來設定整個機器上整體的 library search path。編譯 subversion 需要 libexpat (會在 install phase 的時候用到),這個奧妙的 library 放在 /usr/sfw/lib 裡面,往裡面一看還有好多其他常用的 3rd party library。

總結一下我們需要以下幾個 LD_LIBRARY_PATH:

/usr/local/lib
/usr/local/ssl/lib
/usr/sfw/lib

PATH 裡面則必須至少含

/usr/local/bin
/usr/ccs/bin

全部準備好,就可以開始下指令了:

./configure --prefix=/opt/subversion --with-apxs=/usr/apache2/bin/apxs --enable-shared --enable-ssl

這樣編譯出來的 subversion 會自動把該有的 module 丟進 apache2 的 libexec 目錄裡面,也會把 LoadModule 的敘述行放進 /etc/apache2/httpd.conf

經過這樣下來,至少已經把 subversion/apache2 這對工具搞定了,已經可以開始提供服務了,至於 Trac,那又是另外一個我還沒寫的故事了~

2010年7月27日 星期二

Subversion + Trac on Solaris

今天為了要把 SVN + Trac系統移植到 Solaris上吃足了苦頭。

Trac 0.12 推出了,好處是可以一次使用多個 repository,但是最低要求要有 Python 2.5 or 2.6。Solaris 10u6 內建的只到 2.4,所以得要裝套件。找來找去沒有很好的套件,只好自己抓 source 來編。

自己抓來的東西有個麻煩就是不知道該放哪,於是把 --prefix 設定到 /opt/python-2.6 底下去,這樣如果要砍掉重練比較單純一點。用安裝好的 gcc-3.4.6 來編。 Python 安裝完成,抓了 setuptools, Genshi-0.6 和 Trac-0.12 下來,直接就安裝到 python 2.6 的 site-packages 裡面去。

沒想到要裝 mod_wsgi 的時候卻出了包。mod_xxx 在編譯的時候,最好使用和 apache 編譯的原始編譯器一樣,根據 /var/apache2/build 裡面的 libtool 表示,原來的 apache2 是用 /opt/SUNWspro/bin/cc 編出來的,查了一下發現是 SUN 自己的 compiler...orz,還好現在的 Sun Studio 12u1 是不要錢的,抓了放進去,才知道原來新的 cc 已經不放在 SUNWspro 裡面了,解決的方法也不難,直接把 /usr/ccs/bin/cc symlink 過來,這樣 libtool 就不會抱怨找不到正確的 compiler 了。

解決了 mod_wsgi 的編譯問題。整理一下整個的編譯過程和 flags:

Python:

export CC="cc -mt -fast"
export CFLAGS="-fast"
./configure --prefix=/opt/python-2.6 --with-threads --without-gcc --disable-ipv6 --without-fpectl --enable-shared

後面的 enable-shared 很重要,不然編譯會出錯。mod_wsgi 需要 multi-threaded python,所以 CC 那邊要加上"-mt",而且 configure 要加上 --with-threads

mod_wsgi:

./configure --with-apxs=/usr/apache2/bin/apxs --with-python=/opt/python-2.6/bin/python

SVN 用的是 CollabNet 出的安裝包,明天再來看看這樣配起來能不能動吧~

 

2010年7月12日 星期一

MacRuby, Python, Ruby 在 OS/X 下, interactive shell 中文輸入的問題

之前不管是 Ruby 或是 Python,在 OS/X 下,interactive shell 輸入中文大部分都會出現問號。今天找了一下 MacRuby 的相關資料,發現原來是 readline 的問題。

雖然說 macirb 可以用 macirb --noreadline 跳過去,可是這樣就失去了豐富的 history 功能,也無法使用 Readline module了。

網路上有些文章建議直接去抓新版的 readline 來改,但是從 MacRuby 的這個看來,是系統內的 libedit 缺乏了 multibyte 支援導致的,所以連帶 python 也會有一樣的問題。於是直接去抓了 libedit 2.6.7 下來,configure 完 make 了以後,丟到 /usr/lib 裡面取代 libedit.2.dylib (當然,要先備份),這樣不管是 python 或是 ruby interactive shell 都可以直接打中文了。

**後記**

話說太滿果然會爆炸,放進去以後有些功能就變得怪怪的,正規的作法還是要先拉 Apple 自己的 libedit-13 下來再說。

2010年6月13日 星期日

Extension for Safari

Safari 出了新版,終於出現 Extension 功能了

螢幕快照 2010-06-13 下午9.41.21.png

雖然說中文翻譯相當怪異,不過只要用 Safari 內建的工具,加上 HTML, CSS 或是 JavaScript 檔案,就可以用內建的工具把延伸功能組裝起來。

螢幕快照 2010-06-13 下午10.17.53.png

自己最常用的幾個小功能都是一些 Bookmarklet,比如 Share on Facebook 或是 Post to Echofon (這個是從 Post to Tweetie 改的),就順手把他們變成按鈕式的 extension。

螢幕快照 2010-06-13 下午2.21.50.png

不過 Plurk 的部份用的是 URL 的 status?= 的方法做上去的,所以還沒有那些 custom 動詞,接下來要把 JSON API 的部份放進來,或許 UI 上還要提供更好用一點的 form submission 畫面,這樣就可以更有彈性了。

2010年2月18日 星期四

We’re the Stupid Ones: Facebook, Google, and Our Failure as Developers

This coincides with what my initial thoughts were when I saw the iPad keynote.

These people have better things to do with their days than tweaking out the spacing in their browser toolbars. A computer for them is a utility. One that is increasingly complex, and one that is used because it’s the only option for accomplishing certain things – not because it’s a good option.

It’s kind of like the Photoshop Problem: when people want to crop a picture, we give them Photoshop. Photoshop is a behemoth application with nearly every image editing and touchup function imaginable, and it is terribly complex. Now Photoshop is an impressive tool, but only a very tiny percentage people need the power it offers. The vast majority just want to crop their ex-husband from the photo and let their friends look at it. But even iPhoto, the poster child for Apps So Easy Your Grandparents Can Use Them, continues to pile on features and complexity.

When folks need an elevator, we should give them an elevator, not an airplane. We’ve been giving them airplanes for 30 years, and then laughing at them for being too stupid to fly them right.

I think we’re the stupid ones.

[From funkatron.com : We’re the Stupid Ones: Facebook, Google, and Our Failure as Developers ]

2010年2月8日 星期一

微软亚洲研究院 电脑对联

要过年了,每年看到的对联都一样也蛮无聊的。微软亚洲研究院出了一支程式,可以用电脑帮你对对联。

[From 微软亚洲研究院 电脑对联 ]

以前有个「上海自来水来自海上」,没想到这个引擎对出了不少有趣的下联:

中国出人才人出国中

前门出租车租出门前

中山长生树生长山中

黄山落叶松叶落山黄

南岭临飞石飞临岭南

前门停车场车停门前

中山停云堂云停山中

山东落叶松叶落东山

中国长生果生长国中

西湖映月潭月映湖西

西湖灵隐寺隐灵湖西

山西飞机场机飞西山

下关交通道通交关下

黄山落叶树叶落山黄

山西过路人路过西山

北京跑马场马跑京北

2010年2月5日 星期五

Mule Design Studio's Blog: The Failure of Empathy

This is really scary upon first read.

I went back for a second helping of Avatar this Sunday. There’s a scene early on in the movie where one of the scientists walks across the lab carrying the “mobile computer slab of the future.” We’ve seen one of these in almost every sci-fi movie of the last 50 years. It comes free with a jetpack, I suppose. Except this time, one month later, my 12 year old son turns to me and whispers “Look Dad, it’s an iPad.”

[From Mule Design Studio's Blog: The Failure of Empathy]

The diagram in the passage really said it all. More computer users will appreciate what is becoming of the future of computing. Yes, you should just *IGNORE* the geeks, because after all, logic and reasoning are acquired skills, they don't belong to human nature and will remain a minority in population.

2010年2月4日 星期四

From the Archives: A Revealing Interview With Steve Jobs : Rolling Stone

That's from Steve Jobs in 1994, and look what he has done today. The hardware is a bonus, the key is really the software.

The problem is, in hardware you can't build a computer that's twice as good as anyone else's anymore. Too many people know how to do it. You're lucky if you can do one that's one and a third times better or one and a half times better. And then it's only six months before everybody else catches up. But you can do it in software. As a matter of fact, I think that the leap that we've made is at least five years ahead of anybody.

[From From the Archives: A Revealing Interview With Steve Jobs : Rolling Stone]

But in the end, OO hasn't taken over the world yet (ok, it is a tad easier to write with NS* than CF*, but that's not what he had described back then).

2010年1月26日 星期二

哼歌找歌

今天腦子裡面一直出現一首我小時候聽的歌,只記得曲調,而且是女生唱的,連伴奏和低音和弦我都記得,可是就是不記得曲名和歌詞。找來找去,終於找到這個網站,直接哼一小段進去就可以用這段聲音找音樂,哼完馬上出現,我要的就在第一首! 來聽聽老歌吧~

2010年1月14日 星期四

The Concept *is* the Execution

That's how software front-ends should be designed too, not by some database people 1,000 km away from the lusers.

To me, a great service emerges from a deep understanding of the way that people will interact with it, the way their lives work and the way that it will become part of their lives. From the way it will be useful to them, in other words. If they’re going to have to use a computer to interact with the service, it’s vital to understand what kind of computer they are going to be using, where they will be using it and, crucially, how much time they have to spend.
You cannot design a great service without an obsessional focus on the details. Deny that and I’m likely to get all executional on your ass.

[From The Concept *is* the Execution « Made by Many]

To be more specific to what I mean by "software front-end", I mean that the way we design the part that interacts with the users (not only the UI, also the data exchange, preparation part) should take the users' workflow into consideration. When 2 buttons confuse the user, we should consolidate them into a single button without ambiguous meaning, or hide enough details to let users complete a workflow without knowing too much beyond what the workflow requires them to know.

2010年1月12日 星期二

切記切記!NSString 要弄成 NSURL 一定要有這個轉換手續

NSString *stringEscaped = [stringOrig stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

2009年12月31日 星期四

Just code : Weblog

這篇寫得真好,當 programmer 還是比當 product manager 要單純得多了。

Customers don't buy technologies, they buy usable products. If product isn't usable for a customer, then it doesn't matter how good the technology behind of it, because customer will never buy the product. Look what happened with OS/2. It had a better technology behind (comparing with it's direct competitor Windows 95), but you know who won the race?

[From Just code : Weblog]

2009年11月28日 星期六

Daring Fireball: A Liberal, Accurate Regex Pattern for Matching URLs

這樣就不用每次再去寫一個判斷某字串是不是 URL 的 method/function 了

A common problem programming problem: identify the URLs in an arbitrary string of text, where by “arbitrary” let’s agree we mean something unstructured such as an email message or a tweet. I offer a solution, in the form of the following regex pattern:

\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))

[From Daring Fireball: A Liberal, Accurate Regex Pattern for Matching URLs]

2009年10月27日 星期二

Capstone projects and time management - Joel on Software

It is amazing how easy it is to sail through a Computer Science degree from a top university without ever learning the basic tools of software developers, without ever working on a team, and without ever taking a course for which you don’t get an automatic F for collaborating. Many CS departments are trapped in the 1980s, teaching the same old curriculum that has by now become completely divorced from the reality of modern software development.

[From Capstone projects and time management - Joel on Software]

I have always told my new recruits over the years that:

  • You have graduated, we are not doing term projects (ok, not exactly true, but that's what I need to say)
  • Your program is here to stay, so keep it in a good shape
  • If you don't know the answer, ask, or research, there is no credit to lose, but your job is tied to it
  • You don't get to switch partners very often, so get to know them and work with them
  • Let me know your schedule and keep them, yourself

One thing about time management is that I think it cannot really be trained at school, working on a long term project directed by the PM or group leader is more likely to cultivate the habit of doing short term check-pointing and long term goal checking.

2009年10月24日 星期六

Daring Fireball: Herd Mentality

Conformity is a powerful instinct. There’s safety in numbers. You have to be different to be better, but different is scary.

[From Daring Fireball: Herd Mentality]

Gruber nailed it again! But then the focus is only in the PC market. Who else in the workstation market does not have an OS of its own? Solaris, HP/UX, AIX. Name it and you get it. But I guess that the workstation/server market is never the 'PC Market' at all.

2009年9月21日 星期一

How to remove Trend Officescan without password?

安裝 trend officescan後,想要移除,卻發現須要密碼,如何不須密碼移除趨勢科技 trend officescan,步驟如下:
1. 打開工作管理員,強迫關掉以下程式 Tmlisten.exe NTRtscan.exe ofcpfwsvc.exe 及 暫存執行檔(前兩個字母及最後一個字母是大寫英文,第三、四、五個字母是數字)
2. 修改registry
\HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro\PC-cillinNTCorp\CurrentVersion\Misc\ 將 Allow Uninstall 值改為 1
3. 至〔控制台〕的〔新增移除程式〕中,移除 Trend Officescan。

[From huang987's Memo: 如何不須密碼移除趨勢科技officescan(How to remove Trend Officescan without password?)]

2009年9月16日 星期三

The 18 Mistakes That Kill Startups

6. Hiring Bad Programmers

I forgot to include this in the early versions of the list, because nearly all the founders I know are programmers. This is not a serious problem for them. They might accidentally hire someone bad, but it's not going to kill the company. In a pinch they can do whatever's required themselves.

But when I think about what killed most of the startups in the e-commerce business back in the 90s, it was bad programmers. A lot of those companies were started by business guys who thought the way startups worked was that you had some clever idea and then hired programmers to implement it. That's actually much harder than it sounds—almost impossibly hard in fact—because business guys can't tell which are the good programmers. They don't even get a shot at the best ones, because no one really good wants a job implementing the vision of a business guy.

In practice what happens is that the business guys choose people they think are good programmers (it says here on his resume that he's a Microsoft Certified Developer) but who aren't. Then they're mystified to find that their startup lumbers along like a World War II bomber while their competitors scream past like jet fighters. This kind of startup is in the same position as a big company, but without the advantages.

So how do you pick good programmers if you're not a programmer? I don't think there's an answer. I was about to say you'd have to find a good programmer to help you hire people. But if you can't recognize good programmers, how would you even do that?

[From The 18 Mistakes That Kill Startups]

This somewhat echoes The Problem with Design and Implementation where the author of the other article complained about the separation of the domain expert and the implementor.

Defining a 'good programmer' relies not only on the programmatic skill, but also the intellectual ability to understand and study domain-specific knowledge, you can't really program a bond calculator without knowing the underlying math that defines a bond. It would be naive to vaguely describe a bright idea and expect the programmer to 'just get it' and do it right. It is not that easy.