Skip to content

Instantly share code, notes, and snippets.

Avatar

Lars Kellogg-Stedman larsks

View GitHub Profile
@larsks
larsks / gist:111839
Created May 14, 2009
An example of using the itertools module
View gist:111839
# 2009-05-14 13:49 < spdr-:#python> hello. is there an elegant way
# to loop for at most N iterations? for a in collection: ...
# 2009-05-14 13:49 < KirkMcDonald:#python> spdr-:
for x in itertools.islice(collection, N):
pass
View gist:116168
class Person (Entity):
using_options (tablename = 'person')
full_name = Field(String)
given_name = Field(String)
sur_name = Field(String)
affiliation = Field(String)
account = OneToMany('Account')
View subqueries
Just to be painfully complete the solution was:
subquery = select([Taggable.c.id], query._criterion, from_obj= query._from_obj).as_scalar()
names.select (exists ([names.c.id], and_(names.c.id == obj_tags.c.name_id, obj_tags.c.parent_id==Taggable.c.id , Taggable.c.id.in_ ( subquery) ))
which works in 0.4.1, but not in 0.3.11
Thanks for the help!
View gist:116895
Mexican Chocolate Tofu Pudding
* Sign In to E-Mail
* Print
* Reprints
* ShareClose
o Linkedin
o Digg
o Facebook
o Mixx
View gist:118404
class Webapp:
_cp_config = {
'/static': {
'tools.staticdir.dir': os.path.join(os.path.dirname(__file__),'/static'),
'tools.staticdir.on': True
}
}
def index(self):
View gist:118421
def cp_config(cfg):
'''Add cherrypy configuration dictionary to the _cp_config
attribute of a method.'''
def decorate(f):
setattr(f, '_cp_config', cfg)
return f
return decorate
View gist:120124
wyss.harvard.edu. 10800 IN A 128.103.241.91
wyss.harvard.edu. 300 IN MX 10 magix.seas.harvard.edu.
wyss.harvard.edu. 300 IN MX 10 mirax.seas.harvard.edu.
stage.wyss.harvard.edu. 10800 IN CNAME stage2.wds-appdev.cadm.harvard.edu.
www.wyss.harvard.edu. 10800 IN CNAME prod2.wds-appprod.cadm.harvard.edu.
View gist:123101
git svn init -s $svnrepo
git svn fetch
git rebase --onto trunk --root
git svn dcommit
View gist:158331
>>> import gpgme
>>> ctx = gpgme.Context()
>>> data = open('sample.sh.asc')
>>> import sys
>>> sig = ctx.verify(data, None, sys.stdout)
#!/bin/sh
echo "Hello, world."
>>> sig[0].validity
View myquota
#!/bin/sh
cd $HOME
fs=$(df -P . | tail -1 | sed -n 's|\([^:]*:/[^/]*/[^/]*\)/.*|\1|p')
quota -s | head -2
quota -s | grep -A1 "$fs" | head -2 | sed 's|^'"$fs"'.*|'"$fs"'|'