Skip to content

Instantly share code, notes, and snippets.

@neilalbrock
neilalbrock / atomised-truncate.xsl
Created February 20, 2009 16:06
Another take on the tolerant truncate utility.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Author: Neil Albrock
Version: 1.0
Description: Truncate by a character limit and retain HTML content.
Usage:
<xsl:call-template name="truncate">
<xsl:with-param name="data" select="path/to/your/body" />
@neilalbrock
neilalbrock / jquery.atomgallery.js
Created March 22, 2011 14:32
JQuery gallery plugin written for http://www.atomised.coop
(function($,undefined){
$.fn.atomGallery = function(options) {
//Plugin settings
var settings = $.extend(
{},
{
slideOutTime:1200,
slideOutCSS:{"opacity":"toggle","top":"+=30em"},
slideOutEasing:"easeOutSine",
slideInTime:1000,
@neilalbrock
neilalbrock / sudoku.py
Created March 30, 2011 14:40 — forked from jkk/sudoku.py
Solve Every Sudoku Puzzle in Python by Peter Norvig
## 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']
@neilalbrock
neilalbrock / gist:946239
Created April 28, 2011 12:18 — forked from padolsey/gist:500145
Faster .each() for jQuery
// 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(){
@neilalbrock
neilalbrock / example_page.xsl
Created September 5, 2011 00:55 — forked from dtan/example_page.xsl
Convert XML to JSON output
<?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" />
@neilalbrock
neilalbrock / gist:1332587
Created November 2, 2011 01:25 — forked from mikeyk/gist:1329319
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
@neilalbrock
neilalbrock / comm.py
Created December 5, 2011 17:33 — forked from ericmoritz/comm.py
Simple Redis powered chat server for hyper-local chat.
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
@neilalbrock
neilalbrock / splitmysqldump.pl
Created April 1, 2012 19:39
Split MySQL dump into a file per database
#!/usr/bin/perl -w
#
# splitmysqldump - split mysqldump file into per-database dump files.
use strict;
use warnings;
my $dbfile;
my $dbname = q{};
my $header = q{};
while (<>) {
@neilalbrock
neilalbrock / tree.md
Created April 24, 2012 08:52 — forked from hrldcpr/tree.md
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!

# 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'