Skip to content

Instantly share code, notes, and snippets.

View akx's full-sized avatar
👹
rer

Aarni Koskela akx

👹
rer
View GitHub Profile
import inspect, types
verboten = set(["queryset", "initial", "error_messages"])
NotNone = object()
memo = set()
def _make_ctor_args(obj):
params = []
namesSeen = set()
allArgs = []
for cls in inspect.getmro(obj.__class__):
@akx
akx / squeeze.py
Created February 3, 2012 08:55
Squeeze - HTML5 compressor
# -- encoding: utf-8 --
""" A fairly advanced HTML/HTML5 compressor. """
from __future__ import with_statement
import re
from itertools import chain
HTML5_BLOCKS = set(
'head body title link '
'article aside nav section '
@akx
akx / gist:1878050
Created February 21, 2012 18:41 — forked from neilj/gist:1532562
Sugared DOM: Better Than Templates
# Note: This is actually Coco (http://github.com/satyr/coco), not CoffeeScript.
# I haven't tested this, just wanted to see how concise I could make of the Coco implementation.
el = let
doc = document
directProperties = {
class: \className, \className, \defaultValue,
for: \htmlFor, html: \innerHTML, text: \textContent, \value
}
booleanProperties = {+checked, +defaultChecked, +disabled, +multiple, +selected}
@akx
akx / verbatim.py
Created April 16, 2012 09:33
Django verbatim templatetag
from django import template
register = template.Library()
class VerbatimNode(template.Node):
def __init__(self, text):
self.text = text
def render(self, context):
@akx
akx / __init__.py
Created September 19, 2012 16:47
Django configuration framework idea
# This would be your settings module (settings/__init__.py)
class Setup(object):
def __init__(self, load_from=None):
self.commit(load_from)
def is_valid_key(self, key):
return (key == key.upper() and not key.startswith("_"))
def commit(self, source):
### Google cache link crawler
### Public domain and all
### requires the Requests library for Python (pip install requests / easy_install requests)
### requires Python 2.6+, maybe Python 2.7. Who knows!
###
### TL;DR:
### python gcache2.py -p somesite.shelf -a get-links some-site.fi
### (get several tons of coffee while it runs - the delays are long)
### python gcache2.py -p somesite.shelf -a list-queue
@akx
akx / AwesomeService.java
Created November 5, 2012 20:04
Abstract Singleton Cache Factory
package hurrdurrtest;
public class AwesomeService extends ServiceBase {
private String context;
@Override
public void setContext(String ctx) {
System.out.println("Yo, the context is " + ctx);
context = ctx;
}
@akx
akx / gist:4020123
Created November 5, 2012 20:20
Abstract Singleton Cache Factory, C# flavor
/* 5.11.2012 22:08 */
using System;
using System.Collections.Generic;
namespace ServiceManager
{
public static class ServiceManager
{
private static Dictionary<Type, ServiceBase> _cache = new Dictionary<Type, ServiceBase>();
@akx
akx / gist:4020282
Created November 5, 2012 20:54
Abstract Singleton Cache Factory, Coco flavor
universe = {}
purgatory = {}
summon = (type, context) -> (purgatory[type] ||= new universe[type]) <<< {context}
summonable = -> universe[it.display-name] = it
class Base
-> console.log "A new <#{@..display-name}> was born!"
#include "kiss_fft.h"
#include "kiss_fftr.h"
#define FRAMES_PER_BUFFER 2048
kiss_fft_cpx freq_data[FRAMES_PER_BUFFER];
kiss_fft_scalar audio_data[FRAMES_PER_BUFFER];
kiss_fftr_cfg fft_cfg;