Skip to content

Instantly share code, notes, and snippets.

View lxneng's full-sized avatar
🎯
Focusing

Eric Luo lxneng

🎯
Focusing
View GitHub Profile
>>> class Foo(object):
... def bar(self):
... print 'hello'
...
...
...
>>> class_name = 'Foo'
>>> globals()[class_name]
<class '__main__.Foo'>
>>> _()
{% if ctx.tags %}
<p class=tags>This entry was tagged
{% for tag in ctx.tags|sort(case_sensitive=true) %}
{%- if not loop.first and not loop.last %}, {% endif -%}
{%- if loop.last and not loop.first %} and {% endif %}
<a href="{{ link_to('tag', tag=tag) }}">{{ tag }}</a>
{%- endfor %}
{% endif %}
@lxneng
lxneng / gist:1294488
Created October 18, 2011 02:41
Separate a list to a comma-separated sentence
def textList(listtext, sep1=', ', sep2=', and '):
return sep1.join(listtext[:-2]+['']) + sep2.join(listtext[-2:])
>>> from pyramid_simpleform import Form
>>> from pyramid_simpleform.renderers import FormRenderer
>>> import formencode
>>> class ForgotPWSchema(formencode.Schema):
... email = formencode.validators.Email(not_empty=True)
...
>>> form = Form(request, schema=ForgotPWSchema)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'request' is not defined
@lxneng
lxneng / gist:1280031
Created October 12, 2011 02:05
Serving Static File with Permissions using Nginx, Uwsgi
#file are located in /resources
#eg to open /resources/sample.pdf -> http://www.mysite.com/MyFiles/sample.pdf
#location configuration in nginx.conf
location ^~ /resources/ {
internal;
root /path/to/myapp;
}
@lxneng
lxneng / gist:1202765
Created September 8, 2011 06:24
Upgrading all packages with pip
pip freeze | cut -d = -f 1 | xargs echo pip install -U
@lxneng
lxneng / gist:1202606
Created September 8, 2011 04:23
uninstall all gems
for x in `gem list --no-versions`; do gem uninstall $x; done
@lxneng
lxneng / gist:1180223
Created August 30, 2011 05:04
ssh_exchange_identification: Connection closed by remote host
ssh error:
ssh_exchange_identification: Connection closed by remote host
fix:
sudo echo "sshd:ALL" >> /etc/hosts.allow
语言文件 po 和 mo 的互相转换
===========================
apt-get install gettext
1, mo to po
msgunfmt xxx.mo -o xxx.po
2, po to mo
pip install -e git://github.com/bitly/bitly-api-python.git#egg=bitly_api