Skip to content

Instantly share code, notes, and snippets.

View dahlia's full-sized avatar

Hong Minhee (洪 民憙) dahlia

View GitHub Profile
.*.swp
@dahlia
dahlia / Procfile
Created June 20, 2012 16:57
Using Wand on Heroku
web: python app.py
@dahlia
dahlia / gist:3175089
Created July 25, 2012 08:28 — forked from dinoSpeech/gist:3163386
Higher-order function test suite
(define sum (make-aggregate + 0))
(sum (list 1 2 3)) ; 6
(define product (make-aggregate * 1))
(product (list 2 3 4)) ; 24
(define sum2 (make-aggregate (lambda (a b) (+ a b)) 0))
(sum2 (list 1 2 3)) ; 6
(define product2 (make-aggregate (lambda (a b) (* a b)) 1))
(product2 (list 2 3 4)) ; 24
@dahlia
dahlia / .gitignore
Created August 9, 2012 08:13
Resizing using Wand
.*.swp
resized-*.jpg
resized-*.png
@dahlia
dahlia / cd_hook.sh
Created August 20, 2012 09:07
[virtualenvwrapper] automatic workon hook on cd
export PROJECTS_HOME="$HOME/Projects"
function has_virtualenv__() {
if [[ "$VIRTUAL_ENV" == "" ]]; then
if [[ $(dirname "`pwd`") == $PROJECTS_HOME ]]; then
venvname=$(basename "`pwd`")
if [[ -d "$WORKON_HOME/$venvname" ]]; then
workon "$venvname"
fi
fi
@dahlia
dahlia / gist:3664637
Created September 7, 2012 09:34
Mad experiments on Wand placement API
from wand.display import display
from wand.image import Image
from wand.place import place
with Image(...) as a, Image(...) as b, \
Image(...) as c, Image(...) as d, \
Image(...) as e:
with place('''
|a | |b |
|c|
@dahlia
dahlia / debugtoolbar.py
Created October 29, 2012 15:38
Flask-DebugToolbar without Flask-SQLAlchemy
""":mod:`crosspop.web.debugtoolbar` --- :pypi:`Flask-DebugToolbar` customization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Some of objects in this module are compied from :pypi:`Flask-SQLAlchemy`
extension. Most of customization is removing dependencies on
:pypi:`Flask-SQLAlchemy` and making it to use internal database modules
(:mod:`crosspop.orm` and :mod:`crosspop.web.db`) instead.
This module is full of monkey patches! :-( Although it works well anyway.
@dahlia
dahlia / urlmap.py
Created October 30, 2012 03:24
Building URLs within model objects
""":mod:`crosspop.web.urlmap` --- URL--model objects mapping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The most of model objects (e.g. :class:`~crosspop.user.User`,
:class:`~crosspop.comic.Comic`) have their own permalink urls.
Although you can link them using :func:`flask.url_for()`::
url_for('user.profile', login=user.login)
@dahlia
dahlia / gist:4161930
Created November 28, 2012 15:22
Django monkeypatch for Wand
from django.core.files import images
def get_image_dimensions(file_or_path, close=False):
if hasattr(file_or_path, 'read'):
arg_name = 'file'
file = True
filepos = file_or_path.tell() if hasattr(file_or_path, 'tell') else 0
else:
arg_name = 'filename'
def get_session():
if getattr(flask.g, 'session_got', False):
return flask.g.session
session = was.orm.Session(bind=engine)
flask.g.session = session
flask.g.session_got = True
return flask.g.session
session = werkzeug.local.LocalProxy(get_session)