Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
## Solve Every Sudoku Puzzle | |
## See http://norvig.com/sudoku.html | |
## Throughout this program we have: | |
## r is a row, e.g. 'A' | |
## c is a column, e.g. '3' | |
## s is a square, e.g. 'A3' | |
## d is a digit, e.g. '9' | |
## u is a unit, e.g. ['A1','B1','C1','D1','E1','F1','G1','H1','I1'] |
// The `quickEach` method will pass a non-unique jQuery instance | |
// to the callback meaning that there will be no need to instantiate | |
// a fresh jQuery instance on each iteration. Most of the slow-down | |
// inherent in jQuery's native iterator method (`each`) is the constant | |
// need to have access to jQuery's methods, and so most developers | |
// see constructing multiple instances as no issue... E.g. | |
// $(...).each(function(){ $(this)... $(this)... $(this)... }); | |
// A better approach would be `quickEach`. | |
jQuery.fn.quickEach = (function(){ |
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:json="http://json.org/" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<!-- this is in the context of Symphony CMS, hence ../utilities --> | |
<xsl:import href="../utilities/xml2json.xsl"/> | |
<xsl:output omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> |
#! /usr/bin/env python | |
import redis | |
import random | |
import pylibmc | |
import sys | |
r = redis.Redis(host = 'localhost', port = 6389) | |
mc = pylibmc.Client(['localhost:11222']) |
import redis | |
import simplejson as json | |
import logging | |
import settings | |
import math | |
log = logging.getLogger(__name__) | |
# | |
# The following formulas are adapted from the Aviation Formulary |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
# autocomplete.py - Redis autocomplete example | |
# download female-names.txt from http://antirez.com/misc/female-names.txt | |
# Ruby original: http://gist.github.com/574044 | |
# Requires http://github.com/andymccurdy/redis-py/ | |
from redis import Redis | |
r = Redis() | |
KEY = 'compl' |
# Dynamically load virtualenvwrapper functions to reduce shell startup | |
# time. | |
# | |
# Copyright 2012 Aron Griffis <[email protected]> | |
# Released under the GNU GPL v3 | |
####################################################################### | |
# Python virtualenvwrapper loads really slowly, so load it on demand. | |
if [[ $(type -w workon) != "workon: function" ]]; then | |
virtualenv_funcs=( workon deactivate mkvirtualenv ) |
import logging | |
import redis # http://pypi.python.org/pypi/redis | |
class RedisHandler(logging.Handler): | |
def __init__(self, lname, conn, *args, **kwargs): | |
logging.Handler.__init__(self, *args, **kwargs) | |
self.lname = lname | |
self.channel = lname + ":chan" | |
self.redis_conn = conn |
from flask import Flask | |
from flask.ext.sqlalchemy import SQLAlchemy | |
from flask.ext import admin, wtf | |
from flask.ext.admin.contrib import sqlamodel | |
app = Flask(__name__) | |
app.config['SECRET_KEY'] = '123456790' | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.sqlite' | |
db = SQLAlchemy(app) |