Lisp

最近在用emacs,看了些lisp的东西 原来现代语言的很多特性最早是从lisp中来的 找到几篇很好的文章: 十年学会编程 Lisp之根源 1. 条件语句。当初的语言是没有if else的,goto统治世界。 2. 函数类型。函数成了语言里的类型,可以被变量指代,可以被当成参数传来传去(的一类公民的必要条件,参考SICP第一章)。这一条可以极大简化编程,让我们写出非常漂亮的程序。所以现在的流行语言纷纷加入了这个特性(可惜Java没有)。 3. 递归。这个不用说了吧。 4. 动态类型。smalltalk, python, ruby。。。连C#也有一个类似的var了。 5. 垃圾收集。不要以为GC是Smalltalk的发明哈,更不是Java的。 6. 基于表达式的编程。任何表达式都可以成为另一个表达式的一部分。不像很多语言,把表达和陈述分开。 7. 符号类型。这个在python和ruby里被采用,广受欢迎。 8. 代码即解析树。这个让LISP能方便地定义新的句法,操作程序本身,编写元程序,生成真正意义上的宏。 9. 语言无时不在。代码运行/解析可以在任何时候发生。这点和8.配合可以让语言的扩展和交流变得非常容易。 ...

June 9, 2009 · notsobad

ubuntu 9.04 的新notify的python示例

ubuntu的通知机制 参考: https://wiki.ubuntu.com/NotifyOSD https://wiki.ubuntu.com/NotificationDevelopmentGuidelines 下面是一个简单的python脚本,利用这个新的notify。 效果: https://wiki.ubuntu.com/NotificationDevelopmentGuidelines?action=AttachFile&do=get&target=icon-summary-body.png #!/usr/bin/python import sys import time import pynotify if __name__ == '__main__': if not pynotify.init ("update-notifications"): sys.exit (1) # try the icon-summary-body case n = pynotify.Notification ( "Inital notification", "This is the original content of this notification-bubble.", "notification-message-IM") n.show () time.sleep (3); # simulate app activity # update the current notification with new content n.update ("Updated notification", "Here the same bubble with new title- and body-text, even the icon can be changed on the update.", "notification-message-email") n.show (); time.sleep (6); # wait longer now # create a new bubble using the icon-summary-body layout n = pynotify.Notification ( "Initial layout", "This bubble uses the icon-title-body layout.", "notification-message-IM"); n.show () time.sleep (3); # simulate app activity # now update current bubble again, but change the layout n.update ("Updated layout", "After the update we now have a bubble using the title-body layout.") n.show ()

May 17, 2009 · notsobad

Django on londit

浪点空间上,使用django #获取django svn 版本: mkdir script && cd script svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk mkdir django-project && cd django-project django-admin startproject notsobad 最后: 设置.htaccess SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE notsobad.settings PythonPath "['/home/virtualhost/lnotsoba/script/django-trunk','/home/virtualhost/lnotsoba/script/django-project']+sys.path" PythonDebug On 参考: http://www.londit.cn/FAQ/Python http://docs.djangoproject.com/en/dev/topics/install/

May 12, 2009 · notsobad

Debugging django

怎么调试django程序呢? models还好,可以在django shell中很方便的调试 而view中只能发送httpresponse对象到浏览器,print打印的东西不会在浏览器输出 找到了这篇文章 http://simonwillison.net/2008/May/22/debugging/ 收获: 如果用的是development server,print输出到了对应的terminal中 ...

April 30, 2009 · notsobad

Using cache in django

关于 django的缓存 几篇文章 http://docs.djangoproject.com/en/dev/topics/cache/ http://www.woodpecker.org.cn/obp/django/django-faq/cache.html http://groups.google.com/group/python-cn/browse_thread/thread/917d211b25576342/d0b957e338644540?lnk=gst&q=django%E7%BC%93%E5%AD%98%E6%9C%BA%E5%88%B6# 可以用下面的view代码测试缓存是否工作 from django.views.decorators.cache import cache_page @cache_page(60 * 2) def test(request, task_id): s = datetime.datetime.now() return HttpResponse(str(s)) 另: 如果使用文件型缓存,如 CACHE_BACKEND = 'file:///tmp/django_cache' 需要注意/tmp/django_cache 必须对你的server用户是可写的,如nobody 如果你同时运行开发服务器和生产服务器,一定要注意写权限 ...

April 30, 2009 · notsobad

我的定时脚本

高亮版本看[这里 ](http://not- sobad.appspot.com/show_code/?key=aglub3Qtc29iYWRyCwsSBENvZGUY8WAM)。 作用就是 11,15,18,20,23等几个时间点执行我的脚本。 #!/bin/sh #cron.sh #浪点空间不支持crontab #blog数据同步脚本需要每隔几个小时执行一次,所以自己写了一个简单的 #usage: #nohup cron.sh &>/dev/null & get_local_hour(){ if ! date|grep UTC >/dev/null;then date +%H return 0 fi d=$(expr `date +%H` + 8) if [ $d -gt 24 ];then d=$(expr $d - 24) fi echo $d } cd $HOME/script || exit 1 while [ 1 ];do if ( (echo 11,15,18,20,23 | grep `get_local_hour` >/dev/null ) );then [ -s .rpc_end_link -a -f wp.py ] || exit 2 python wp.py 2>&1 >wp.log fi sleep 3600 done exit 0 后记:白忙了,还不如这样搞。 ...

April 30, 2009 · notsobad