Skip to content

Instantly share code, notes, and snippets.

View metatoaster's full-sized avatar

Tommy Yu metatoaster

  • Auckland Bioengineering Institute, University of Auckland
  • Auckland, New Zealand
View GitHub Profile
@metatoaster
metatoaster / .vimrc
Created August 31, 2011 04:17
Simple vimrc with copypasta from various places
set viminfo='20,\"500
set ai sw=2 expandtab
set title
set hidden
set nocompatible
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
syntax on
" From Bram:
" When editing a file, always jump to the last known cursor position.
@metatoaster
metatoaster / gist:1283396
Created October 13, 2011 04:38
Buildout jailbreaking fail (WHYYY?)
Got zope.interface 3.6.3.
Getting distribution for 'distribute==0.6.19'.
Before install bootstrap.
Scanning installed packages
Setuptools installation detected at /usr/lib/python2.6/dist-packages
Non-egg installation
Removing elements out of the way...
Already patched.
/usr/lib/python2.6/dist-packages/setuptools.egg-info already patched.
After install bootstrap.
@metatoaster
metatoaster / gist:1283507
Created October 13, 2011 05:55
Hahhahaha I thought it's going to fetch distribute-0.6.21?
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.21.tar.gz
Extracting in /tmp/tmp9_wgB5
Now working in /tmp/tmp9_wgB5/distribute-0.6.21
Building a Distribute egg in /tmp/tmpUy_zwk
/tmp/tmpUy_zwk/distribute-0.6.21-py2.6.egg
Creating directory '/home/pmr2/bbslave_pmr2/buildoutruntests/build/bin'.
Creating directory '/home/pmr2/bbslave_pmr2/buildoutruntests/build/parts'.
Creating directory '/home/pmr2/bbslave_pmr2/buildoutruntests/build/eggs'.
Creating directory '/home/pmr2/bbslave_pmr2/buildoutruntests/build/develop-eggs'.
Getting distribution for 'distribute==0.6.19'.
@metatoaster
metatoaster / .vimrc
Last active October 11, 2015 04:57
.vimrc
set viminfo='20,\"500
set ai sw=2 expandtab
set title
set hidden
set nocompatible
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
syntax on
" From Bram:
" When editing a file, always jump to the last known cursor position.
def format_reinforcement(delta_t):
hours = delta_t.seconds / 3600
days = delta_t.days
seconds = delta_t.seconds
# Don't ask. Read the test; be happy you don't have to write this.
# (WTB something simple like str(delta_t) with more control.)
# (Maybe I should just do this in javascript?)
return '%(day)s%(hour)s' % {
'day': days and '%(days)d day%(dayp)s%(comma)s' % {
@metatoaster
metatoaster / gist:6026706
Created July 18, 2013 04:24
Example pygit2 usage: create a root commit.
>>> from time import time
>>> from pygit2 import Signature
>>> from pygit2 import Repository
>>> from pygit2 import init_repository
>>> from pygit2 import GIT_FILEMODE_BLOB, GIT_FILEMODE_TREE
>>>
>>> repo = init_repository('/tmp/repodir', bare=True)
>>> tf1 = repo.create_blob('this is a test file')
>>> tf2 = repo.create_blob('some other blob')
>>> tf3 = repo.create_blob('this is a test file2')
@metatoaster
metatoaster / gist:6089625
Created July 26, 2013 15:06
Quickie flask app
"""
Instructions: (save this file as app.py or whatever)
$ virtualenv .env
$ . .env/bin/activate
(.env) $ pip install flask
(.env) $ python app.py
"""
import json
@metatoaster
metatoaster / gist:6432448
Created September 4, 2013 03:25
ZPublisher filestream_iterator example
import os
import stat
from ZPublisher.Iterators import filestream_iterator
from zope.publisher.browser import BrowserPage
class FilestreamPage(BrowserPage):
target = '/path/to/some/file'
@metatoaster
metatoaster / app.py
Last active May 10, 2024 01:45
Flask Principal Permission override demo
from flask import Flask, request, abort, g, current_app
from flask.ext.principal import Principal
from flask.ext.principal import Identity, identity_changed, identity_loaded
from flask.ext.principal import Permission, Need, RoleNeed, ItemNeed
app = Flask(__name__)
app.config['SECRET_KEY'] = 'test_secret_key'
app.config['TESTING'] = True
@metatoaster
metatoaster / gist:7077489
Created October 21, 2013 01:38
psc beta to current workflow update
import transaction
from Acquisition import aq_base, aq_inner, aq_parent
from Products.CMFCore.utils import getToolByName
from pprint import pprint as pp
catalog = getToolByName(app.cmiss, 'portal_catalog')
releases = catalog.searchResults(portal_type='PSCRelease')
o = [i.getObject() for i in releases]
pp([(i,i.workflow_history['psc_release_workflow'][-1]['review_state']) for i in o])
wftool = getToolByName(app.cmiss, 'portal_workflow')
wfdef = getattr(aq_base(wftool), 'psc_release_workflow', None)