Chen Jian's Java Blog 

Python: PIL generates an image too big?

by Chen Jian


Posted on 2016-06-12 12:00 in Non-Java Language


You've tried thumbnail(), resize(), save(quality=20),  but you still get an image too big? Maybe it's because you are generating a PNG file.  Change it to JPG and you will get a much smaller file ! It's because PNG format is a lossless...


Let Django's migration run raw SQL

by Chen Jian


Posted on 2016-06-06 12:00 in Non-Java Language


You've created a new column and you want set its value as the "id" column. What to do?  Add the following line to the generated migration file or you can create new migration file migrations.RunSQL(sql="update some_table...


Django to send JSON response

by Chen Jian


Posted on 2016-06-06 12:00 in Non-Java Language


Don't try to be smart.  You must   1. Manually convert query sets to dicts  2. Convert the dicts to JSON   Other approaches that convert query sets directly to JSON are not robust.  


Keep in mind that celery workers don't share global states

by Chen Jian


Posted on 2016-03-14 12:00 in Non-Java Language


Problem:    1. A task has a top-level variable, whose value is 1 at first  2. After run once by celery, the value is changed to 2   3. When running task with celery for the second time, you will see the value is still 1...


man.get_things() or Thing.get_things_by_man() when Active Records Pattern is used?

by Chen Jian


Posted on 2016-03-13 12:00 in Non-Java Language


There is requirement for a method to get things of a man.  Where to put it?   man.get_things() or   (static) Thing.get_things_by_man()  ?   From OO's perspective, the former sounds more natural.   I was...


Automatically reload celery worker when there is code change during development

by Chen Jian


Posted on 2016-03-10 12:00 in Non-Java Language


  Celery worker's --autoreload option seems not working for a lot of people, especially those who use OS X.   I wrote a python script to start celery worker and monitor the changes in code to reload celery worker if there is any chagne. ...


pycrypto's ciphers should be created as a new instance every time it is called

by Chen Jian


Posted on 2016-03-03 12:00 in Non-Java Language


According to my test, they are stateful objects. Reusing a single instance will lead to wrong results.  Every time you encrypt or decrypt anything, you should create a new cipher, such as  cipher = DES3.new(some_key, DES3.MODE_CFB,...


正则表达式:判断一个词是否全是汉字

by Chen Jian


Posted on 2013-07-14 12:00 in Non-Java Language


if (preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str)) { return true; }


codeIgniter默认情况下关闭浏览器不会使session过期

by Chen Jian


Posted on 2013-07-13 12:00 in Non-Java Language


codeIgniter默认情况下关闭浏览器不会使session过期。也就是说,如果你没有显式登出而只是关闭浏览器,在一定时间内(codeIgniter默认是2小时)打开浏览器重新访问这个网站,会发现你仍处于登录状态。 为了规避这个风险,应该 //config.php $config['sess_expire_on_close'] = TRUE;


php中消除用户输入的空格和标点符号

by Chen Jian


Posted on 2013-07-07 12:00 in Non-Java Language


preg_replace("/[[:punct:]\s]/",'',$str)


php + mysql时的防注入

by Chen Jian


Posted on 2013-06-11 12:00 in Non-Java Language


有两种办法,一是在写入前转义,二是使用mysqli扩展中的prepared statement 1. 写入前转义 // what's 将变成 what\'s $title = mysql_real_escape_string($_POST['title']); // 存到数据库后查看它,会变回what's 2. prepared statement 待补充


用php写一个微型的web app: 一个不错的例子

by Chen Jian


Posted on 2013-06-11 12:00 in Non-Java Language


http://www.phpro.org/tutorials/Creating-A-PHP-Application.html 教你快速地写一个博客程序


ubuntu上安装xdebug并与eclipse pdt联合调试

by Chen Jian


Posted on 2013-06-11 12:00 in Non-Java Language


安装xdebug 引用 $sudo apt-get install  php5-dev php-pear $sudo pecl install xdebug  ##装完后记下xdebug.so的位置 然后在php.ini里加上: 引用 zend_extension=/xxx/../xdebug.so [xdebug] xdebug.remote_enable=on ...


收藏: PHP 程序员的调试技术

by Chen Jian


Posted on 2013-06-06 12:00 in Non-Java Language


http://www.ibm.com/developerworks/library/os-debug/


一个php站点一般要装的东西

by Chen Jian


Posted on 2013-06-06 12:00 in Non-Java Language


1. LAMP, 这个不用说 2. php5-mysql 相当于jdbc 驱动 3. php5-gd 图形库,没有它出不来captcha 4. 本站邮箱及smtp服务器 5. php-mbstring. 有了它,才有mb_strlen()函数,对非西欧字符串进行操作时才会把一个字符的长度视为1 待续。。。