Skip to content

Instantly share code, notes, and snippets.

View lxneng's full-sized avatar
🎯
Focusing

Eric Luo lxneng

🎯
Focusing
View GitHub Profile
sudo apt-get install postgresql-contrib-9.1
def paginate(self, items, items_per_page=20):
"""https://bitbucket.org/bbangert/webhelpers/src/acfb17881c1c/webhelpers/paginate.py"""
current_page = self.request.GET.get('page') or 1
def page_url(page):
params = self.request.params.copy()
params['page'] = page
return self.request.current_route_url(_query=params)
@lxneng
lxneng / gist:2768166
Created May 22, 2012 10:20
将ubuntu文件夹中文名改为英文
export LANG=en_US
xdg-user-dirs-gtk-update
export LANG=zh_CN.UTF-8
import os
from os.path import dirname
install_dir = dirname(dirname(__file__))
# Load the application
from paste.deploy import loadapp
application = loadapp('config:' + os.path.join(install_dir, 'production.ini'))
export LANG="en_US.UTF-8"
/*
title: reset css
Based on http://meyerweb.com/eric/tools/css/reset/
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
from sqlalchemy import Date, cast
from datetime import date
my_data = session.query(MyObject).\
filter(cast(MyObject.date_time,Date) == date.today()).all()

Installing vim with ruby support (+ruby)

sudo apt-get install vim-nox;

Some package provides vim-ruby on Ubuntu, for example vim-nox.

simply:

sudo apt-get install vim-nox; will get you vim with ruby, as well as compiled in "support for scripting with Perl, Python, Ruby, and TCL but no GUI."

def get_random_word(wordLen):
word = ''
for i in xrange(wordLen):
word += random.choice(('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs'
'tuvwxyz0123456789/&='))
return word
~ sudo -u postgres sh
$ createuser -P eric
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y
$ psql postgres
psql (9.1.3)
Type "help" for help.
postgres=# create database eric encoding 'UTF-8';