Skip to content

Instantly share code, notes, and snippets.

View ento's full-sized avatar

ento

View GitHub Profile
@ento
ento / gist:3888966
Created October 14, 2012 15:43 — forked from jkerian/gist:2305769
Comments on some of the resource questions in JL&U
@ento
ento / gist:3524077
Created August 30, 2012 08:16
Make python understand 'utf8mb4' as an alias for 'utf8'
# oursql in particular doesn't recognize utf8mb4 as a valid charset
# source: https://code.djangoproject.com/ticket/18392#comment:10
import codecs
codecs.register(lambda name: codecs.lookup('utf8') if name == 'utf8mb4' else None)
@ento
ento / gist:3168822
Created July 24, 2012 08:26
.screenrc
escape ^t^t
zombie "^d^r"
hardstatus alwayslastline I%wI
@ento
ento / gist:3090348
Created July 11, 2012 13:18
Bookmarklet: Open in Chrome
javascript:location.href="googlechrome"+location.href.slice(location.href.search("://"));
@ento
ento / gist:2477429
Created April 24, 2012 07:23
Getting the model instance from Python's fixture dataset row
import logging
import sqlalchemy as sa
from sqlalchemy import MetaData
from sqlalchemy import orm, create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from fixture import DataSet
from fixture import SQLAlchemyFixture
from fixture.style import NamedDataStyle
@ento
ento / flask_static_file_for.py
Created April 4, 2012 16:28
Given a (static) endpoint, return its actual filesystem location.
import os
from flask import current_app, request
def static_file_for(endpoint, filename=None):
if endpoint[0] == '.' and request.blueprint:
folder = current_app.blueprints[request.blueprint].static_folder
else:
folder = current_app.static_folder
return os.path.join(folder, filename) if folder else None
@ento
ento / pymongo.py
Created March 30, 2012 00:56
Flask-PyMongo datastore for Flask-Admin
# -*- coding: utf-8 -*-
from flask.ext.admin import datastore
from flask.ext.admin import util
from flask.ext.wtf import Form
from pymongo.objectid import ObjectId
from pymongo.errors import OperationFailure
class Any(object):
@ento
ento / gist:1525902
Created December 28, 2011 02:37
Calculate the total length of music/sound files in a folder
import re
import glob
import commands
duration_re = re.compile(r'(?P<hour>\d+):(?P<minute>\d+):(?P<second>\d+\.\d+),')
hour = minute = second = 0.0
for f in glob.glob("./*"):
s = commands.getstatusoutput('ffmpeg -i %s 2>&1 | egrep "Duration" | cut -d " " -f 4' % f)[1]
m = duration_re.match(s)
@ento
ento / 1st access
Created October 27, 2011 02:53
JLU Question is inacessible due to invalid utf-8 character in a title: HTTP request/response headers recorded by Google Chrome
Request URL:http://japanese.stackexchange.com/questions/1472/pronunciation-and-meaning-of-%EE%93%BB
Request Method:GET
Status Code:301 Moved Permanently
Request Headers
GET /questions/1472/pronunciation-and-meaning-of-%EE%93%BB HTTP/1.1
Host: japanese.stackexchange.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.102 Safari/535.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
@ento
ento / getting-phantomjs-working-on-centos55.md
Last active September 26, 2015 18:47 — forked from niteria/getting-phantomjs-working-on-centos55.txt
Building phantomjs on CentOS 5.5