How to use google form as a simple survey system

July 20th, 2009

Preview

  • A google form is a simple generally form system. You can use it to generate a form to ask your user some questions and collect the answers into a google spreadsheet automatically. And then you can do farther data analytics with that spreadsheet.
  • Actually, the google form can be used directly. But in some cases, the user want to change the google form’s default behavior to meet their requirements, such as they don’t want it to be redirected to google’s response page which have google’s logo there, they want to customize the design of the google form, etc
  • This scripts is used to focus on these special cases, also it can’t cover all of these cases, but it’s a beginning.

Design

  • I used a iframe to handle the google form’s default response.
  •   <form target="gsurvey_result"></form>
      <iframe name="gsurvey_result" height="1" style="display:none;"></iframe>
  • I used javascript to replace all of the radio button with a image, when the user clicks the image, the value of the radio will be synced directly. The image can be changed with css.
  • I used the javascript to check if the required field has a value. But now there’s nothing to do with the required field without a value.
  • User can define the response text by themselves.

An example

  • Generate a google form with your own google account.
  • Create a new html file, load the script gsurvey.js, gsurvey.css in the html file.
  • <html>
    <head>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <link rel="stylesheet" media="screen" href="/static/css/gsurvey.css" />
      <script type="text/javascript" src="/static/js/jquery.gsurvey.js"></script>
    </head>
    <body>
    </body>
    </html>
  • Insert the html code of the google form. You can also define a element holds response text. You can check the code in the attachments.

javascript

Performance of str+str and ‘‘.join()

April 28th, 2009
>>> a = 'a' * 100000
>>> def t(a):
>>>     b = ''
>>>     for i in a:
>>>         b = b + '|' + i
>>>     return b
>>> 
>>> time c = t(a)
>>> time c = '|'.join(a)

In my notebook ( Intel(R) Core(TM)2 CPU T5200 @ 1.60GHz, 1.5G Mem):

The result of time c=t(a):
CPU times: user 2.90 s, sys: 0.00 s, total: 2.90 s
Wall time: 3.07 s

The result of time c = ‘|’.join(a):
CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s
Wall time: 0.01 s

If I changed a from 100000 to 1000000, c=t(a) can’t give me a result in more than 5 minutes while the other one give me the result in 0.09s.

join is much faster than str + str. str + str need to create new strings all the time, but join doesn’t. I guess “join” maybe do something on the memory level.

Developer, Python

“Resource temporarily unavailable” on the whm host

April 4th, 2009

Today, following a document to tune the security of our whm hosting, I enabled “Shell fork bomb protection” in “Security Center”. But I’m 100% sure what I did. Then when I try to run the apache process of the user, the exception “bash: fork Resource temporarily unavailable” raised. It took me a lot of time to find why this happen. Finally I got this document: http://www.eddieoneverything.com/linux/linux-whm-cpanel-resource-temporarily-unavailable.php

It’s because “Shell fork bomb protection” will enable the limitation for each user, the limitation is defined with ulimit command. The default limitation is 100 open files with 20 processes.

Linux

来自 “The Federated States of Micronesia” 的顾客

April 1st, 2009

今天我们站点上出现了个跟国名有关的错误。一个来自”The Federated States of Micronesia”的老兄试图给我们站点留言。我们的IP2Location解析了他的ip并且得到了正确的国家名称”MICRONESIA, FEDERATED STATES OF”。可是我们的数据库country字段的限制是20,最终还是把这位老兄的留言拒之门外了。。。(小国家真不容易,这样也能被拒绝,我估计这老兄一定这么想。)

这让我想起了个问题,不知道世界上最长的国家名称能有多少个字符?
写个blog纪念一下这位老兄的国家吧,也算长见识了。

http://en.wikipedia.org/wiki/Federated_States_of_Micronesia

Python , ,

分析日志常用到的几个shell工具

March 31st, 2009

一个不错的例子: http://nunojob.wordpress.com/2008/04/12/history-awk-print-2-sort-uniq-c-sort-rn-head/

httpd.log | awk '{print $2}' \  | sort | uniq -c | sort -rn | head

解释:
httpd.log : 要分析的日志
awk : 用来取出某一特定的列。简单的也可以用cut来代替
sort : 用来排序(第一次排序是用来为后面的uniq服务的。uniq对于没有排序的内容工作不正确)
uniq : 用来uniq有序的内容,-c参数会把重复次数带上
sort -rn : 用来安重复次数倒序排列
head : 用来去前几条数据,默认是10.

Python ,

Satchmo 新体验

March 30th, 2009

今天checkout最新的satchmo看了一下,发现变化还是很大的。看样子我们的BE是没法升级到最新的satchmo了…

还没有时间仔细研究,不过发现有几个satchmo用到的第三方的app值得注意一下:
1. django-registration

http://code.google.com/p/django-registration/

这个已经用过几次,感觉不错,而且感觉它的生命力很强。
2. django-values

http://code.google.com/p/django-values/

satchmo用这个替换了原来自己写的configuration模块。我一直认为satchmo的configuration模块有设计上的缺陷,结果这次被彻底换掉了,不错。有时间研究一下这个。
3. threaded_multihost

http://gosatchmo.com/apps/django-threaded-multihost/

multi-site aware features, 不是很懂,还得看看代码。

Python ,

[八卦] google music, 爽!

March 30th, 2009

今天看新闻发现google出了music搜索,于是试用了一把。 (http://www.google.cn/music/homepage)

搜歌,听歌,下载,一应俱全。
尤其是它的web播放器,用起来很舒服。

对于google的music搜索,有几个疑问:
1. 歌曲的下载地址不是链接到其他网站,而是统一链接到top100.cn
2. 上面可以下载的歌曲很新,不知道版权问题是如何解决的?

Python

Normal method, @staticmethod, @classmethod of python

March 18th, 2009

Reference:
http://snippets.dzone.com/posts/show/1679
http://www.geocities.com/foetsch/python/new_style_classes.htm

Check the doctest in these code bottom.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test the variable methods in class
"""
 
class K(object):
    """
    Test the variable methods in class
    >>> k_obj = K()
    >>> k_obj.method1()
    Normal method: obj.method1() becomes method1(obj)
    >>> K.method2()
    classmethod: K.method2() becomes method2(klass: <class '__main__.K'>)
    >>> k_obj.method2()
    classmethod: K.method2() becomes method2(klass: <class '__main__.K'>)
    >>> K.method3()
    staticmethod: K.method3() become just method3(None)
    >>> k_obj.method3()
    staticmethod: K.method3() become just method3(None)
    """
    # normal method (instance method)
    def method1(self):
        print 'Normal method: obj.method1() becomes method1(obj)'
 
    # class method
    @classmethod
    def method2(cls):
        print 'classmethod: K.method2() becomes method2(klass: %s)' % cls
 
    # static method
    @staticmethod
    def method3():
        print 'staticmethod: K.method3() become just method3(None)'
 
class KK(K):
    """
    Test the variable methods' behavior in the subclass.
    >>> kk_obj = KK()
    >>> kk_obj.method1()
    Normal method: obj.method1() becomes method1(obj)
    >>> KK.method2()
    classmethod: K.method2() becomes method2(klass: <class '__main__.KK'>)
    >>> kk_obj.method2()
    classmethod: K.method2() becomes method2(klass: <class '__main__.KK'>)
    >>> KK.method3()
    staticmethod: K.method3() become just method3(None)
    >>> kk_obj.method3()
    staticmethod: K.method3() become just method3(None)
    """
    pass 
 
if __name__ == "__main__":
    import doctest
    doctest.testmod()

Python

Convert MP3 Id3 tag encoding

March 12th, 2009

It’s a long time pain for my mp3 files. I tried a lot of kinds way to convert my mp3 files’ id3 tag encoding. But every time when I need to convert the tag, I can’t remembered what I did last time. Now I’m going to record some way to do this.

I used amarok. Since the developers os amarok hate to deal with various kinds of encoding, they determined to use unicode which required id3v2.4 tag. This decision makes a lot of Chinese music displayed like a mess in the amarok because most of Chinese music used old version, different encode id3 tags.

I found some good ways to convert your music id3 tags here: http://wiki.linuxmce.org/index.php/Converting_MP3_Tags_To_UTF-8

The most way I like is mid3iconv

I used it like this:

For a single file

$mid3iconv -e gb2312 a.mp3 --remove-v1 -dp

For a directory

$find . -name "*.mp3" -exec mid3iconv -e gb2312 --remove-v1 -dp "{}" \;

-p option means dry-run, so if you really want to convert, remove this option.

Linux , ,

Install google toolbar in archlinux’s firefox

March 12th, 2009

I can’t install google toolbar in archlinux firefox3 for a long time. Today I resolved this issue by searched archlinux forum.

Reference:

http://bugs.archlinux.org/task/13759

Why I can’t install google toolbar?

Google can’t recogonized my firefox version correct, that’s because archlinux mark firefox as “GranParadiso”.

How to change that?
1. Type “about:config” in the url bar of firefox.
2. Search “general.useragent.extra.firefox” key, and change the value from “GranParadiso/3.0.x” to “Firefox/3.0.x”
3. Then go to google toolbar install page and click install.

Linux ,

FireStats icon Powered by FireStats