Skip to content

Instantly share code, notes, and snippets.

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

Andrey Kuzmin w0rm

🧘
ヨガの呼吸
View GitHub Profile
@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 ),
@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 / 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 / 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 / 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 / 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 / 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 / analytics.js
Created April 8, 2014 21:20
Wrap universal analytics in requirejs module
define(function() {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
window.ga('create', 'UA-XXXXXXXX-X')
return {
@w0rm
w0rm / background-borders.scss
Last active August 29, 2015 14:01
Draw borders with linear gradients, supports width of 0.5px for retina screens
// This mixin is used to ease workaround explained in this article
// http://n12v.com/css-retina-and-physical-pixels/
// Creates linear gradient for specified border
@function border-gradient($side, $color: currentColor, $width: 0.5px) {
@if $side == top {
@return linear-gradient(180deg, $color, $color 50%, transparent 50%) top left / 100% #{$width * 2} no-repeat;
} @else if $side == bottom {
@return linear-gradient(0, $color, $color 50%, transparent 50%) bottom right / 100% #{$width * 2} no-repeat;
@w0rm
w0rm / svgstore.html
Created August 6, 2014 15:26
Load combined svg file into body
<html>
<body>
<!-- load combined svg file (with symbols) into body-->
<script>
(function (doc) {
var scripts = doc.getElementsByTagName('script')
var script = scripts[scripts.length - 1]
var xhr = new XMLHttpRequest()
xhr.onload = function () {