自己弄了一个空间跑wordpress, 以后的文章会发布在那里 http://onetown.me

 

posted @ 2011-08-23 13:26 Stephen Leung 阅读(4) 评论(1) 编辑

最近要给客户定制一个php的论坛, 我本来是python控, 所以机器上就没有php的运行环境, 于是开始折腾, 本来在centos上配置nginx + php-fpm挺简单的, 直接一路yum install就可以了, 这下到mac上就有点麻烦, 虽然macports上有php, 但是如果安装php-fpm的话需要hack的方法, 为了不麻烦, 爬文看到有使用homebrew的方式使用第三方的formula可以安装, 下面开动。 

 

如果你没用过homebrew, 那么移步Homebrew的网站看看, 安装起来很简单, 因为它就是一堆ruby的脚本, 所以你直接在terminal里键入:

ruby -"$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)" 

既然你在玩这个, 假定你已经装了xcode, 3或者4都可以。 接下来就是下载php的formula, 

  1. curl -O https://github.com/ampt/homebrew/raw/php/Library/Formula/php.rb
  2. mv php.rb `brew --prefix`/Library/Formula

 

如果你想看php的安装选项, 可以使用

  1. brew options php

 

嗯, 现在可以安装了, 我只需要php和php-mysql, 就这样:

  1. brew install php --with-mysql --with-fpm

 这样基本上就可以了。 

posted @ 2011-04-09 16:41 Stephen Leung 阅读(136) 评论(0) 编辑

最近换了台macbook air, 升级到了10.6.6, 想想就装xcode4, 于是杀到mac store, 用了一个晚上把xcode4拖下来, 一切顺利, 但是在我配置python开发环境的时候发现easy_install总是无法正常编译带c extension的包, 例如simplejson, 出现“error writing to -: Broken pipe”错误, 经过一番google, 终于找到问题所在, 原因是xcode4的llvm gcc不支持ppc架构的cpu了, 但是python的源设置都是包含ppc的设置, 那么就只有2个解决方案了。 要么就修改easy_install的源, 要么就在编译的时候带上架构信息, 我选择了后者。 例如安装的时候使用

 

env ARCHFLAGS='-arch i386 -arch x86_64' easy_install simplejson

 

如果你觉得每次打那么长的命令挺烦的, 那就用alias把这段加进去, 例如在你的 ~/.bash_profile里加一行

alias ez_install='env ARCHFLAGS="-arch i386 -arch x86_64" easy_install'

这样下次可以直接使用sudo ez_install simplejson就可以了。

 

同样在下载的python的代码需要安装的话, 也可以使用类似的办法, 例如

alias xpython='env ARCHFLAGS="-arch i386 -arch x86_64" python'

然后可以使用sudo xpython setup.py install 

 

posted @ 2011-03-20 14:22 Stephen Leung 阅读(75) 评论(0) 编辑

昨天突发奇想, 现在google docs里的spreadsheet很强大, 如果我的网站数据不是很大, 那么我通过spreadsheet来保存我的数据不是一件很方便的事情吗, 事实上, 我的网站也只是保存一些产品的数据, 而我的产品又不可能像eBay那样有许多, 那么我就试试把数据保存在Google Spreadsheet里吧。 

目标有了, 工具呢? 去看看Google Spreadsheets API吧, 嗯, 它还躺在Google Labs里面, 不过也还不错, 那么它支持那些语言呢?因为我对Python很有爱, 而且这个API也支持Python, perfect!!! 好了, 开始动手。 如果要使用这个API, 那么第一步自然是下载一个叫Google Python Client Library东西。 使用这个client的前提是你要有Python的环境, 并且包含httplib和urllib这两个模块, 还好python2.6都内置了这两个模块, 如果你使用2.6这个版本的话, 直接从上面这个link下载, 安装就好了。 

 python setup.py install

进入python, 我们做一些简单的实验。

>>> import gdata.spreadsheet.service as service
>>> client = service.SpreadsheetsService()
>>> client.email = "yourgoogleaccount@domain.com"  #你的app帐号或者gmail帐号
>>> client.password = "********"  #这个就是密码的东西, 你当然看不见了
>>> client.source = "iMaQ-Documents-v1" #这个不好解释, 下面大概描述一下
>>> client.ProgrammaticLogin() #利用上面的信息登陆到Google

嗯, 很好, 我in了 xD, 接下来, 我要知道我的Documents里有哪些spreadsheet, 废话, 我当然知道, 我可以直接进到我的documents里去看我有哪些表格, 我们就以里面自带的一个demo的文档做实验, 那个叫做internal-Contact的东东。 首先如果要访问这个文档的话, 我们要知道这个文档的key

>>> docs = client.GetSpreadsheetsFeed()
>>> for i, entry in enumerate(docs.entry):
...     
print entry.title.text , entry.id.text
... 
internal 
- Contact http://spreadsheets.google.com/feeds/spreadsheets/private/full/blablablabla__Y1ax999C
products http:
//spreadsheets.google.com/feeds/spreadsheets/private/full/blablablablabla_Z1fSm-nXQ
>>>

 看到了吗? 列出了两个我这个帐号可以访问的文档, entry.title.text就是文档的名字, entry.id.text就是这个文档的feed地址, 是你后面调用api的时候直接访问这个文档的地址, 里面的/full/后面的一串blablabla就是这个文档的key. 有了这个key, 我们就可以直接去访问这个文档里的内容啦, 首先看看这个表格里有几个sheet。

>>> sheet = client.GetWorksheetsFeed(key)
>>> for i, entry in enumerate(sheet.entry):
...     
print entry.title.text, entry.id.text
... 
Sheet1 http:
//spreadsheets.google.com/feeds/worksheets/blablablablabla__Y1ax999C/private/full/od1
>>>

 结果给出只有一个Sheet1, 后面的那个是workbook的key和这个sheet的id, 这里是od1, 现在我们就可以去看看这个sheet里的内容了

>>> table = client.GetListFeed(key,wksht_id)
>>> for i, entry in enumerate(table.entry):
...     
for column in entry.custom:
...             
print "[%s:%s]"%(column, entry.custom[column].text)
... 
[comment:I
'm commenting on this contact form]
[timestamp:2/15/2010 8:07:30]
[name:Sarah]
[email:garsides@gmail.com]
[comment:I want to join the group.]
[timestamp:
2/15/2010 13:06:33]
[name:Larisa]
[email:info@landviser.com]
[comment:
is it wotk]
[timestamp:
2/15/2010 17:23:55]
[name:Larisa]
[email:info@landviser.com]
[comment:Test]
[timestamp:
2/16/2010 12:17:22]
[name:Jeremy]
... 
#后面的省略掉了

内容都出来了, 好多阿 - . -!

 

看来访问内容还是很容易的, 接下来, 我们就可以把内容写到可爱的mongodb里 去了, 如何使用mongodb就不是本文所涉及的主题了, 既然内容已经被都出来了, 你可以将这些内容写到你喜欢的地方去, big table, mysql, oracle, 或者txt里。 使用mongodb的前提是你已经有了mongo的环境并且装好了python driver, 叫pymongo, 那么下面就接着继续

>>> from pymongo import Connection
>>> db = Connection("localhost").test.contacts
>>> for i, entry in enumerate(table.entry):
...     obj 
= {}
...     
for col in entry.custom:
...             obj[col] 
= entry.custom[col].text
...     db.save(obj)
... 
ObjectId(
'4c2f9bad092ce508b2000000')
ObjectId(
'4c2f9bad092ce508b2000001')
ObjectId(
'4c2f9bad092ce508b2000002')
ObjectId(
'4c2f9bad092ce508b2000003')
ObjectId(
'4c2f9bad092ce508b2000004')
ObjectId(
'4c2f9bad092ce508b2000005')
ObjectId(
'4c2f9bad092ce508b2000006')
ObjectId(
'4c2f9bad092ce508b2000007')
ObjectId(
'4c2f9bad092ce508b2000008')
ObjectId(
'4c2f9bad092ce508b2000009')
ObjectId(
'4c2f9bad092ce508b200000a')
ObjectId(
'4c2f9bad092ce508b200000b')
ObjectId(
'4c2f9bad092ce508b200000c')
...

 好了, 刚才那个contacts里的内容就写到mongodb里去了, 你可以进到mongo的console里去

use test
db.contacts.find()

 

 

posted @ 2011-03-06 23:17 Stephen Leung 阅读(120) 评论(0) 编辑

是从pastbin.com上看到的, 但是不知道作者是谁. 

 

Code

 

posted @ 2009-05-06 01:44 Stephen Leung 阅读(165) 评论(1) 编辑
摘要: Windows Vista VPN Error 609 Posted on Sunday, March 09, 2008 at 2:34 PM by MalcolmIf you have problem with Windows Vista VPN with error code 609, you can try the following fix from this post. uninstal...阅读全文
posted @ 2008-11-28 01:23 Stephen Leung 阅读(83) 评论(0) 编辑
摘要: 由于windows7自带了.net framework 3.5 sp1,所以在安装visual studio 2008 sp1的时候会发生fatal error during installation的错误, 看日志, 发现是安装netfx35.exe的问题, 单独安装没反应. 于是把sp1的iso解开, 打开ParameterInfo.xml文件, 找到<Exe Name="dotnetf...阅读全文
posted @ 2008-11-21 20:45 Stephen Leung 阅读(2752) 评论(5) 编辑
摘要: 很久没来园子更新自己的blog了, 突然发现它已经支持使用word 2007来发布, 这对我来说是件好事, 因为公司和家里的机器上都部署了MOSS 2007 B2TR, 我经常把一些觉得好的文章作为blog的格式"抄袭"到word 2007上, 然后再"转载"到家里和公司里的SharePoint Weblog里, 这样, 我就经常能回顾这些文章, 我觉得非常方便, 我已经把这个作为一种kb的方式来...阅读全文
posted @ 2006-10-21 12:56 Stephen Leung 阅读(157) 评论(0) 编辑
摘要: 6月份otec上, grapecity的朋友demo了一个用sharepoint定制的站点案例, 其中就用到了自定义属性的方法。 后来我在项目中也碰到了自定义属性的问题, 后来问了ted老兄, 才把问题解决了, 非常感谢ted. 用过sharepoint的朋友可能都用到过sharepoint的dataview, 并且通过筛选来达到显示我们需要的数据的目的, 那么如何从url querystring...阅读全文
posted @ 2005-11-21 12:07 Stephen Leung 阅读(593) 评论(0) 编辑
摘要: 我尝试在virtual pc上安装vista beta1, 在选择安装路径的时候发现无法格式化磁盘, 这个问题可以在这个post里找到解决方案(http://odetocode.com/Blogs/scott/archive/2005/07/27/2000.aspx), 目前我已经在vpc上安装了vista beta1. good luck.阅读全文
posted @ 2005-08-01 09:57 Stephen Leung 阅读(1040) 评论(0) 编辑