终于把Apache2从我的VPS上停掉了
Gentoo, Web, Wordpress February 21st, 2010
折腾了一个上午,终于把我的 VPS 上的 Apache 跑着的相关服务,都切换到 Nginx 上了:
1. Blog 用的是 WordPress,原先是用 mod_php 跑着的,现在则换成了 php-fpm
2. Wiki 用的是 Trac,原先是用的 mod_python,现在用 tracd 直接起来,然后 Nginx 转发
3. Git 前端用的是 Gitweb,因为懒得再启一个 spawn-fcgi 了,所以干脆换成 GitPHP,同样通过 php-fpm 的方式跑着
4. Zotero 的 WebDAV 存储,由于好久都不用,直接停了,有时间再看看有没有什么轻便的替代方案吧
PS1:关于 Gentoo 上的 php-fpm 配置,见 http://bugs.gentoo.org/show_bug.cgi?id=208155 及 http://bugs.gentoo.org/show_bug.cgi?id=301279
PS2:关于 Nginx 跑 WordPress 的 Permalink 设置,可以参考 http://blog.sjinks.pro/wordpress-plugins/nginx-compatibility/
Daily Scripts: djangoat.py (for Linux) 
Django, Linux, Python June 19th, 2009
Djangoat is short for Django Auto Tester, but I often pronounce it “djan-goat”… This script does monitor Django project directory by inotify mechanism, run unit tests when file changed, and notify errors through Mumbles if tests failed. It depends on inotify and Mumbles, so runs on Linux only, Mac version comes later…
Python code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #!/usr/bin/env python # -*- coding: utf-8 -*- import commands import datetime import dbus import dbus.service import os import sys from dbus.mainloop.glib import DBusGMainLoop from pyinotify import WatchManager, ThreadedNotifier, \ ProcessEvent, IN_CLOSE_WRITE, \ ExcludeFilter FIREFOX_DBUS_INTERFACE = 'org.mozilla.firefox.DBus' FIREFOX_DBUS_PATH = '/org/mozilla/firefox/DBus' class FireFoxDBus(dbus.service.Object): def __init__(self, bus_name): dbus.service.Object.__init__(self, bus_name, FIREFOX_DBUS_PATH) @dbus.service.signal(dbus_interface=FIREFOX_DBUS_INTERFACE, signature='ss') def DownloadComplete(self, title, subject): pass # Which type of files' change should be monitor MONITOR_EXTENSIONS = ('.py', '.html') class Watcher(ProcessEvent): def process_IN_CLOSE_WRITE(self, event): global cmd global firefox_dbus for extension in MONITOR_EXTENSIONS: if event.pathname.endswith(extension): start_time = datetime.datetime.now() print start_time output = commands.getoutput(cmd) print output # If test failed, call mumbles for notification if not output.endswith('OK'): firefox_dbus.DownloadComplete(start_time.isoformat(), output) def process_default(self, event): pass if __name__ == '__main__': if len(sys.argv) < 2: print 'Please specify a path for monitoring...' sys.exit() path = sys.argv[1] cmd = "python %s/manage.py test -v 0" % path # Exclude filter object excl_file = os.path.join(os.getcwd(), 'exclude.patterns') excl = ExcludeFilter({excl_file: ('excl_lst',)}) # Add watch wm = WatchManager() notifier = ThreadedNotifier(wm, Watcher()) wm.add_watch(path, IN_CLOSE_WRITE, rec=True, \ auto_add=True, exclude_filter=excl) # Set up an event loop dbus_loop = DBusGMainLoop() name = dbus.service.BusName(FIREFOX_DBUS_INTERFACE, bus=dbus.SessionBus(mainloop=dbus_loop)) firefox_dbus = FireFoxDBus(name) try: notifier.loop() except KeyboardInterrupt: print 'Djangoat shut down...' except Exception, ex: print 'Exception in Djangoat: %s' % (ex) |
1 2 3 4 5 6 | # -*- mode: python; -*- # Exclude pattens excl_lst = ['^\.git/', '^\.svn/', ] |
Screenshoot:
![]()
Code repository:
http://git.lazytech.info/?p=daily-scripts.git
UnitTest in cakePHP
PHP, Web January 14th, 2007
1. 从 cakeforg.org 下载最新的 Test Suite.
2. 把文件解压到相应的目录.
然后可以正式开始编写测试用例了.
首先数据库建一个 g20_template 的表,
1 2 3 4 5 6 7 | CREATE TABLE "g20_template" ( "id" integer NOT NULL PRIMARY KEY AUTO_INCREMENT, "name" varchar(100) NOT NULL, "cols" varchar(100) NOT NULL, "create_date" datetime NOT NULL, "update_date" datetime NOT NULL ); |
然后是写一个简单的 model.
1 2 3 4 5 6 | <?php class Template extends AppModel { var $name = 'Template'; var $useTable = 'g20_template'; // I use g20_template table } ?> |
最后在 app/tests/app/cases/models 下编写一个 template.test.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <?php require_once LIBS . 'model/model.php'; require_once CAKE . 'app_model.php'; require_once MODELS . 'template.php'; class TemplateTestCase extends UnitTestCase { var $template = null; var $validName = '2 cols'; var $validCols = '[\'50%\', \'50%\']'; var $validCreateDate = '2007-01-14 16:56:00'; var $validUpdateDate = '2007-01-14 16:56:00'; function setUp() { $this->template =& new Template(); } function testSave() { $this->template->data = array('Template' => array('name' => $this->validName, 'cols' => $this->validCols, 'create_date' => $this->validCreateDate, 'update_date' => $this->validUpdateDate ) ); $this->assertTrue($this->template->save()); $id = $this->template->getLastInsertId(); $this->template->id = $id; $this->assertEqual($this->template->field('name'), $this->validName); $this->assertEqual($this->template->field('cols'), $this->validCols); $this->assertEqual($this->template->field('create_date'), $this->validCreateDate); $this->assertEqual($this->template->field('update_date'), $this->validUpdateDate); } ?> |