Skip to content

Instantly share code, notes, and snippets.

@hrldcpr
hrldcpr / tree.md
Last active January 6, 2025 22:43
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@btimby
btimby / gravatar.py
Created March 9, 2012 05:18
Gravatar Django template tag
import urllib, hashlib
from django import template
from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage
# To use this template tag:
# 1. Add it to the templatetags/ directory of your Django app.
# 2. Then load and use it in the template like so:
#
# {% load gravatar %}
@alexvelin
alexvelin / notbash-parser.py
Created March 3, 2012 08:12 — forked from pyropeter/LICENSE
PKGBUILD parser
#!/usr/bin/env python2
# This is a parser for bash-style variable assignments.
# It fully (?) supports the syntax w/o braces, the ${}-syntax
# is implemented very hackish. (There are also detailed
# TODO-comments in various places)
# This is meant for Archlinux' AUR to be used to parse
# PKGBUILD's properly.
@chriscoyier
chriscoyier / dabblet.css
Created January 31, 2012 05:24
Ratings Stars
/*
Ratings Stars
(with as little code as possible)
*/
.rating {
unicode-bidi: bidi-override;
direction: rtl;
text-align: center;
}
.rating > span {
@amcgregor
amcgregor / insane.py
Created January 4, 2012 22:48
An example combining nested sets with adjacency lists using SQLAlchemy+Elixir.
# encoding: utf-8
from uuid import uuid4
from elixir import *
from elixir.events import *
from sqlalchemy import UniqueConstraint
from sqlalchemy.sql import and_
@quietlynn
quietlynn / 12306.user.js
Created January 3, 2012 12:01
12306 Auto Query => A javascript snippet to help you book ticket
/*
12306 Auto Query => A javascript snippet to help you book tickets online.
Copyright (C) 2011-2012 Jingqin Lynn
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
Includes Sizzle.js
anonymous
anonymous / 天涯 4000W 数据.txt
Created December 25, 2011 10:58
天涯 4000W 数据
thunder://QUFodHRwOi8veGxpc3N1ZTExMC5zYW5kYWkubmV0L+Wkqea2r+aVsOaNri5rej9maWQ9RldLYVBiYUl0WjZLVUtyTTNTdHZGNC0yMVd1amU1RVhBQUFBQUxZVTRwNmNjUm1DTE9SQnBmUEVTdWpYYm9RVyZtaWQ9NjY2JnRocmVzaG9sZD0xNTAmdGlkPTRFN0VDNzRDMkM0NDdDQjVDNjUwOUJERkY1MzdEQ0ExJnNyY2lkPTExMiZ2ZXJubz0xWlo=
@krestenkrab
krestenkrab / hindent.el
Created December 22, 2011 14:14
hindent.el: Highlight indentation of current line
;;;
;;; Copyright (C) Kresten Krab Thorup
;;; Available under Apache License, Version 2.
;;;
;;;
;;; This minor mode will highlight the indentation of the current line
;;; as a vertical bar (grey background color) aligned with the column of the
;;; first character of the current line.
;;;
@malthe
malthe / less.app
Created September 22, 2011 08:14
less.app in bash
#!/bin/bash
if [ ! -d $1 ]; then
echo "Not a directory: $1"
exit -1
fi
while read line; do
filename="$(basename $line)"
if [ "${filename##*.}" == "less" ]; then
@justquick
justquick / GFKManager.py
Created September 12, 2011 05:12 — forked from dexterbt1/GFKManager.py
django generic foreignkey manager
from django.db.models.query import QuerySet
from django.db.models import Manager
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.generic import GenericForeignKey
class GFKManager(Manager):
"""
A manager that returns a GFKQuerySet instead of a regular QuerySet.
"""