Skip to content

Instantly share code, notes, and snippets.

View nailor's full-sized avatar

Jyrki Pulliainen nailor

View GitHub Profile
# Adding a semi-dynamic field to Django ModelAdmin
#
# Motivation behind this is to see if django.conf.settings contains a
# setting of some type. I know this could be done with a factory too.
#
# django.forms.Form allows adding extra fields to forms initialization
# time by modifying self.fields dict in __init__. However, ModelAdmin
# only looks at the *class* of the form, not the instance created from
# it, to determine the fields it should draw in the admin interface.
#
#!/bin/bash
( foo="bar"; echo "Within first shell (pid: $BASHPID): \$foo=$foo" )
( unset foo; echo "Within second shell (pid $BASHPID): \$foo=$foo" )
@nailor
nailor / gist.py
Created October 24, 2011 08:07
Deaccent unicode strings
# Deaccent unicode strings.
#
# unicodedata.normalize('NFKD', unicodestring): do a compatibility
# decomposition of the unicode string
#
# unicodedata.category(somecharacter): Find the unicode category
# for a character. Category 'Mn' contains all combining accents
import unicodedata
import errno
import socket
import select
class EventLoop(object):
def __init__(self):
self.callbacks = []
self.sources = []
self.handlers = {}
@nailor
nailor / couch.ini
Created October 4, 2011 12:50
Minimum configuration to start couchdb
[couchdb]
database_dir = tmp/couch
view_index_dir = tmp/couch
[httpd]
port = 8922
bind_address = 127.0.0.1
[log]
file = tmp/couch.log
require 'sass'
module Sass::Script::Functions
def inline_image(image, type)
path = image.value
image_data = [data(path)].flatten.pack('m').gsub('\n', '')
declaration = "url('data:#{type};base64,#{image_data}')"
Sass::Script::String.new(declaration)
end
declare :inline_image, :args => [:string, :string]
@nailor
nailor / bieberizer.sh
Created September 2, 2011 15:22
Bieberizer! for Reaktor Dev Day (by @nailor and @mikharj)
#!/bin/sh
echo "Bieberizing. Please wait..."
git reset --soft `git log --pretty=oneline | tail -n 1 | awk '{ print $1 }'`; git commit --amend -m "Implemented the software as specified." --author="Justin Bieber <justin@taiste.fi>"
echo "Done & Done"
@nailor
nailor / .pdbrc
Created August 4, 2011 16:18 — forked from esamattis/.pdbrc
What every python developer should have in their ~/.pdbrc
# Enable tab completion
import rlcompleter
import pdb
pdb.Pdb.complete = rlcompleter.Completer(locals()).complete
# Sometimes when you do something funky, you may lose your terminal echo. This
# should restore it when spanwning new pdb.
import termios, sys
termios_fd = sys.stdin.fileno()
termios_echo = termios.tcgetattr(termios_fd)
#!/usr/bin/env python
import sys
import time
from tornado.ioloop import IOLoop
def printer(digit):
def _do_print():
print digit
(defun single-window-mode ()
(interactive)
(delete-other-windows)
(set-frame-size (selected-frame) 80 65))
(defun double-window-mode ()
(interactive)
(delete-other-windows)
(set-frame-size (selected-frame) 163 65)
(split-window (selected-window) 83 t))