Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
(╯°□°)╯︵ ┻━┻

David Larlet davidbgk

💭
(╯°□°)╯︵ ┻━┻
View GitHub Profile
@davidbgk
davidbgk / current_page_middleware.py
Created Apr 28, 2010
Django: Current Page Middleware
View current_page_middleware.py
"""
Current Page Middleware.
This module provides a middleware that implements a mechanism to
highlight a link pointing to the current URL.
Thanks @davidbgk and @samueladam for improvements & optimizations
"""
import re
@davidbgk
davidbgk / classinstancemethod
Created Apr 30, 2010 — forked from ianb/Lightning talk
when you want to use both a classmethod and the function with a class instance
View classinstancemethod
# classinstancemethod, when you want to use both a classmethod and the function with a class instance
## Descriptors
## Anything with __get__ and optionally __set__:
class classinstancemethod(object):
def __init__(self, func):
self.func = func
def __get__(self, obj, type=None):
@davidbgk
davidbgk / gist:805600
Created Feb 1, 2011 — forked from adamcharnock/gist:389875
Double metaphone
View gist:805600
import re
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone
from metaphone import dm as double_metaphone
# get the Redis connection
from jellybean.core import redis
import models
# Words which should not be indexed
@davidbgk
davidbgk / data-uri.py
Created Jul 26, 2011 — forked from jsocol/data-uri.py
Give an image, get a data-uri
View data-uri.py
#!/usr/bin/env python
"""Command line script to convert a file, usually an image, into a data URI
for use on the web."""
import base64
import mimetypes
import os
import sys
@davidbgk
davidbgk / field.html
Created Nov 9, 2011 — forked from pydanny/field.html
django-uni-form + Twitter Bootstrap
View field.html
<!-- this usually goes in <project-root>/templates/uni_form/field.html -->
{% if field.is_hidden %}
{{ field }}
{% else %}
<div class="clearfix {% if field.errors %}error{% endif %}">
<label for="{{ field.auto_id }}" {% if field.field.required %}class="requiredField"{% endif %}>
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
<div class="input">
@davidbgk
davidbgk / gist:2495085
Created Apr 26, 2012 — forked from paulirish/gist:839879
requestAnimFrame() shim.
View gist:2495085
// see http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// shim layer with setTimeout fallback
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
@davidbgk
davidbgk / maximum_battery_life.md
Created May 11, 2012 — forked from asenchi/maximum_battery_life.md
maximum battery life checklist -- use before a long plane flight
View maximum_battery_life.md

Max Battery Life Checklist

Here is a checklist to follow if you want maximum battery life -- for instance if you're about to get on a long plane flight.

10 hour battery life on a non-SSD Macbook Pro 17"

Low power use checklist

With power connected:

@davidbgk
davidbgk / postsql.sql
Created May 17, 2012 — forked from tobyhede/postsql.sql
PostgreSQL as JSON Document Store
View postsql.sql
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- JSON Types need to be mapped into corresponding PG types
--
-- Number => INT or DOUBLE PRECISION
-- String => TEXT
@davidbgk
davidbgk / flaskapp.py
Created Jun 11, 2012 — forked from kennethreitz42/flaskapp.py
My typical flask app base
View flaskapp.py
# -*- coding: utf-8 -*-
import os
from flask import Flask
from flask_heroku import Heroku
from flask_sslify import SSLify
from raven.contrib.flask import Sentry
from flask.ext.celery import Celery
@davidbgk
davidbgk / data.md
Created Jun 24, 2012 — forked from jordansissel/data.md
Logstash 1.1.1 + ElasticSearch 0.19.5 compression tests
View data.md

compression tests of logstash+elasticsearch

  • logstash 1.1.1-pre (unreleased)
  • elasticsearch 0.19.5-SNAPSHOT (unreleased)
wget https://dl.dropbox.com/u/2136051/elasticsearch-0.19.5-SNAPSHOT.zip
unzip elasticsearch-0.19.5-SNAPSHOT.zip
You can’t perform that action at this time.