django 调试

django 调试 http://www.slideshare.net/simon/debugging-django 总结了几条: 1 使用断言 assert False assert False, variable 2 打印到终端 print “test” 3 使用logging模块 4 使用debugger 在view中: import pdb pdb.set_trace() 可以在运行时调试代码. python -i ./manage.py # import pdb;pdb.pm() 5 产品环境下, 将500,404之类的错误用email发给自己 6 使用xmpp,将产生的错误即时发给自己的msn,gtalk ...

December 30, 2009 · notsobad

备忘

备忘: django admin界面报模板错误, 说是下面这一行有问题: {% url django-admindocs-docroot as docsroot %}. 排查发现是url.py里配置有问题导致的,错误信息很不明显。 (The error is showing up where it is because the admin uses {% url django- admindocs-docroot as docsroot %} to conditionally include a Documentation link on each admin page, based on whether the admindocs urls have been configured. This template tag will result in all of your url patterns being evaluated, and problems with any will be reported. You need to find the app you are running that has a registration/views.py file that imports oldforms and upgrade it to use current forms.) ...

December 30, 2009 · notsobad

javascript字符转为数字

以前一直用的parseInt,今天终于遇到了问题了,查了半天发现是parseInt的问题 我处理坐标top,left,这些是float型的数据,parseInt转为整数了,细微的差别导致问题了。 所以如果要把字符型转为数字,首选的应该是parseFloat,取整的话才用parseInt。 ...

December 29, 2009 · notsobad

php中的unset

php中unset只是清除掉一个变量,并不意味着内存会被立即清理,会交给GC来处理。 如果把一个变量置为null,意味着覆写了变量,内存会被更快清理,但是会导致cpu运算,导致执行时间变长。 参考 unset() does just what it’s name says - unset a variable. It does not force immediate memory freeing. PHP’s garbage collector will do it when it see fits - by intention as soon, as those CPU cycles aren’t needed anyway, or as late as before the script would run out of memory, whatever occurs first. If you are doing $whatever = null; then you are rewriting variable’s data. You might get memory freed / shrunk faster, but it may steal CPU cycles from the code that truly needs them sooner, resulting in a longer overall execution time. ...

December 24, 2009 · notsobad

php的Copy-on-write

参考Be wary of garbage collection 先看段代码: echo "Stage 1: Mem usage is: ", memory_get_usage(), "\n"; $arr = array(); for ($i = 0; $i < 1000000; ++$i) { $arr[] = rand(); } echo "Stage 2: Mem usage is: ", memory_get_usage(), "\n"; $foo = 1; $bar = 2; echo "Stage 3: Mem usage is: ", memory_get_usage(), "\n"; $foo = $arr; $bar = $arr; echo "Stage 4: Mem usage is: ", memory_get_usage(), "\n"; $arr = array(); echo "Stage 5: Mem usage is: ", memory_get_usage(), "\n"; $bar[] = "hello, world"; echo "Stage 6: Mem usage is: ", memory_get_usage(), "\n"; $foo = array(); echo "Stage 7: Mem usage is: ", memory_get_usage(), "\n"; 运行结果: Stage 1: Mem usage is: 37712 Stage 2: Mem usage is: 60232136 Stage 3: Mem usage is: 60232248 Stage 4: Mem usage is: 60232248 Stage 5: Mem usage is: 60232288 Stage 6: Mem usage is: 104426704 Stage 7: Mem usage is: 60242672 看stage 4, ...

December 24, 2009 · notsobad

Mockingbird 在线原型设计工具

从这里看到一个在线原型设计工具 Mockingbird 是基于 Cappuccino 开发的一个在线原型设计工具。 确实很酷,280 Slides也是用这个工具做的。 研究了下,它是用Objective- J来做的,好像是类似GWT一样的东西,挺麻烦的 Cappuccino is an open source application framework for developing applications that look and feel like the desktop software users are familiar with. Cappuccino is built on top of standard web technologies like JavaScript, and it implements most of the familiar APIs from GNUstep and Apple’s Cocoa frameworks. When you program in Cappuccino, you don’t need to concern yourself with the complexities of traditional web technologies like HTML, CSS, or even the DOM. The unpleasantries of building complex cross browser applications are abstracted away for you. Cappuccino was implemented using a new programming language called Objective-J, which is modelled after Objective-C and built entirely on top of JavaScript. Programs written in Objective-J are interpreted in the client, so no compilation or plugins are required. Objective-J is released alongside Cappuccino in this project and under the LGPL. ...

December 21, 2009 · notsobad

php中的allow_url_include

allow_url_include 如果打开,则可以include远程文件 这是个很古老的安全问题了,今天做了下实验,才意识到危害性。 以前一位include 只是取到静态html内容,把它原样输出,没想到它会对获取倒内容中的php代码进行解释执行,很危险。 机器a上: wang@wang-desktop:~/www$ cat inc.php EOF ?> 然后在另一台机器b上: ...

December 17, 2009 · notsobad

使用lynx来获取网页文本

使用lynx来获取网页文本, 效果就相当于在一个网页上面输入ctrl+a ctrl+c,然后ctrl+v保存到一个文本文件中,当然写到脚本里就可以自动化操作了。 lynx -notitle -nomargins -nolist -width=4096 -verbose -display_charset=gb2312 -dump http://baike.baidu.com/view/396668.htm?hh=255 | iconv -f gb2312 -t utf8//IGNORE 排下版 wang@wang-desktop:~/script/notsobad/shell/tool$ cat get_url.sh #!/bin/sh # File: get_url.sh # Author: notsobad # Description: # Created: 2009-12-14 15:53:02 # Last modified: 2009-12-14 15:53:02 url=$1 lynx -notitle\ -nomargins\ -nolist\ -width=4096\ -verbose\ -display_charset=gb2312\ -dump\ "$url"\ | iconv -f gb2312 -t utf8//IGNORE

December 14, 2009 · notsobad

Joel on software

几篇很不错的文章 1 易用的界面,简单的一步 2 主次分明 3 每日构建(daily build)是你的朋友 4 第四战略篇:膨胀软件与80/20的谣传 5 行进中开火 6 看起来简单, 实际上复杂 7 给计算机系学生的建议 8 轻松面试找到理想员工-非官方的面试技术指南 9 The Joel Test: 软件开发成功 12 法则 10 《微独立软件供应商:从理想到现实》序 11 抽象渗漏法则 原文:Joel on software ...

December 7, 2009 · notsobad

linux在脚本中重定向输出

关于linux下io重定向的几篇文章 A Detailed Introduction to I/O and I/O Redirection [Advanced Bash- Scripting Guide I/O Redirection](http://www.faqs.org/docs/abs/HTML/io- redirection.html) linux下三种文件是默认打开的,stdin(键盘), stdout(屏幕), stderr(错误信息,输出到屏幕),这三个和其它的打开文件都是可以被重定向的。 有一个脚本a.sh,我想把它的输出全部重定向到一个文件中去,如何做呢? 通常我们会在调用时做 sh a.sh >/tmp/out.txt 2>&1 但是如果调用是程序没办法控制的,如何在这个脚本内部做呢? 写一个测试脚本看下 #cat a.sh ...

November 30, 2009 · notsobad