Skip to content

Instantly share code, notes, and snippets.

(defun flatten (lst)
(cond ((atom lst) lst)
((listp (car lst))
(append (flatten (car lst)) (flatten (cdr lst)))
)
(t (append (list (car lst)) (flatten (cdr lst))))))
import codecs
import tempfile
import doctest
def test_open(fn):
r"""
Test codecs.open to see if it actually opens a file
with an implicit binary mode and does not mess up the
newlines on Win32.
@EnigmaCurry
EnigmaCurry / __init__.py
Created September 17, 2009 20:44
How a single file python libary might use setuptools
from one_file import *
function alternate(id){
if(document.getElementsByTagName){
var table = document.getElementById(id);
var rows = table.getElementsByTagName("tr");
for(i = 0; i < rows.length; i++){
if(i % 2 == 0){
rows[i].className = "even";
}else{
rows[i].className = "odd";
}
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
response.sendRedirect("URL");
@EnigmaCurry
EnigmaCurry / category_index.mako
Created November 29, 2009 06:39
Blogofile template for generating a index of posts for each category
<%inherit file="_templates/site.mako" />
These are all the categories:
<ul>
% for category, link in category_link_map.items():
<li><a href="${link}">${category}</a></li>
% endfor
</ul>
@EnigmaCurry
EnigmaCurry / category_post_listing.mako
Created November 29, 2009 06:42
A single page indexing all the categories and posts
<%inherit file="_templates/site.mako" />
<%
# Generate a map of categories to posts
category_post_map = {}
for p in bf.posts:
for c in p.categories:
try:
category_post_map[c.name].add(p)
except KeyError:
@EnigmaCurry
EnigmaCurry / tag_cloud.py
Created June 17, 2010 18:40
Blogofile tag cloud filter
import blogofile_bf as bf
import math
# A Blogofile based tag cloud with linear distribution.
# This works for either tags or categories.
# Ryan McGuire - www.blogofile.com
# Usage:
# In your template, add the following:
# ${bf.filter.run_chain("tag_cloud","categories")}
@EnigmaCurry
EnigmaCurry / pylons_jsonify.py
Created September 20, 2010 14:07
Pylons jsonify decorator
# A fixed @jsonify decorator for Pylons that allows for
# class implemented __json__ serializers
from decorator import decorator
from pylons.decorators.util import get_pylons
import warnings
import json
import logging
log = logging.getLogger(__name__)
import md5
import sys
def sumfile(fobj):
'''Returns an md5 hash for an object with read() method.'''
m = md5.new()
while True:
d = fobj.read(8096)
if not d:
break