Skip to content

Instantly share code, notes, and snippets.

View w0rm's full-sized avatar
🧘
ヨガの呼吸

Andrey Kuzmin w0rm

🧘
ヨガの呼吸
View GitHub Profile
@w0rm
w0rm / convert-png-to-rgba.py
Created March 28, 2014 17:02
Fix png images for compass sprite generator
#!/usr/bin/env python
#
# Script to convert png files to RGBA color space
# Requires Pillow (pip install Pillow)
#
import os
import fnmatch
from PIL import Image
for root, dirnames, filenames in os.walk('sprites'):
@w0rm
w0rm / twitter.js
Created March 19, 2014 08:38
How to use twitter widgets.js with AMD
// Usage: require(['twitter'], function (twitter) { twitter.load() })
define(function() {
var twitter = {
load: executeWhenReady('load')
}
// Return wrapped function that will
// be executed only when twttr is ready
function executeWhenReady (funcName) {
@w0rm
w0rm / callbackhell.js
Last active August 29, 2015 13:57 — forked from keriati/callbackhell.js
var AwesomeObject = function() {
this.init()
};
AwesomeObject.prototype = {
init: function() {
_.bindAll(this, 'onSuccess', 'onError', 'onComplete')
// or
this.onSuccess = $.proxy(this.onSuccess, this)
@w0rm
w0rm / web.emailerrors.log
Last active December 10, 2015 06:48
Sometimes stack trace generated by web.emailerrors is so huge that it breaks server memory limits. This happens for example when files are opened. In my case I didn't even do anything myself, but the server's filesystem went read-only, so this error caused very large email message that was turned down by gmail:
d = web.input(page_id=None, sizes=[])
File "/home/edzohogusava/lib/python2.7/web/webapi.py", line 330, in input
out = rawinput(_method)
File "/home/edzohogusava/lib/python2.7/web/webapi.py", line 303, in rawinput
a = cgi.FieldStorage(fp=fp, environ=e, keep_blank_values=1)
File "/usr/local/lib/python2.7/cgi.py", line 508, in __init__
self.read_multi(environ, keep_blank_values, strict_parsing)
File "/usr/local/lib/python2.7/cgi.py", line 637, in read_multi
environ, keep_blank_values, strict_parsing)
File "/usr/local/lib/python2.7/cgi.py", line 510, in __init__
@w0rm
w0rm / restful_app.py
Last active May 13, 2021 17:16
RESTful controller with web.py
import web
import json
from restful_controller import RESTfulController
urls = (
r'/resources(?:/(?P<resource_id>[0-9]+))?',
'ResourceController',
)
@w0rm
w0rm / SpxinxQLDB.py
Created April 23, 2012 18:41
Sphinx search (SphinxQL) database wrapper for web.py
from web.db import DB, SQLQuery, register_database
class SphinxDB(DB):
def __init__(self, **keywords):
import MySQLdb as db
if 'pw' in keywords:
keywords['passwd'] = keywords['pw']
del keywords['pw']
if 'charset' not in keywords:
@w0rm
w0rm / gist:1034547
Created June 19, 2011 18:12
Saving form state between requests in webpy
class Form(web.form.Form, object):
def __init__(self, name, *inputs, **kw):
super(Form, self).__init__(*inputs, **kw)
self.name = name
def save_state(self):
session.forms[self.name] = dict(
notes = dict((i.name, i.note) for i in self.inputs if i.note ),
values = dict((i.name, i.get_value()) for i in self.inputs ),