Skip to content

Instantly share code, notes, and snippets.

View mmalone's full-sized avatar

Michael Malone mmalone

View GitHub Profile
@mmalone
mmalone / gist:179410
Created September 1, 2009 21:30 — forked from joestump/gist:179397
class Model(object):
keyspace = None
column_family = None
key = None
data = {}
required = []
modified = False
def __init__(self, **kwargs):
if self.key in kwargs and len(kwargs) == 1:
@mmalone
mmalone / Reviewing profiles
Created November 13, 2009 23:57
Replacement Django runserver command that does profiling... because I've rewritten this too many times.
>>> import pstats
>>> p = pstats.Stats('p.1258156459.52174278XcQE.prof')
>>> p.strip_dirs().sort_stats(-1).print_stats(5)
Fri Nov 13 15:54:20 2009 p.1258156459.52174278XcQE.prof
124278 function calls (122386 primitive calls) in 0.589 CPU seconds
Ordered by: standard name
List reduced from 1014 to 5 due to restriction <5>
"Memcached cache backend"
from django.core.cache.backends import memcached
from django.utils.encoding import smart_unicode, smart_str
MIN_COMPRESS_LEN = 150000
class CacheClass(memcached.CacheClass):
def add(self, key, value, timeout=None, min_compress_len=MIN_COMPRESS_LEN):
if isinstance(value, unicode):
@mmalone
mmalone / vipy.sh
Created March 3, 2010 03:21
Simple shell script that locates a Python module and opens it in vi.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: vipy <python module>"
exit 1
fi
MODULE_LOCATION=`python -c "import $1; print $1.__file__.rstrip('c')"`
if [ -z $MODULE_LOCATION ]; then
import random
import time
from eventlet import patcher, greenpool, pools
patcher.monkey_patch()
import simplegeo
LAYER = 'your.layer.identifier.here'
OAUTH_KEY = 'YOUR OAUTH KEY HERE'
# In-memory Cassandra-ish thingy... useful for unit tests. Maybe useful for other
# stuff too? No support for SuperColumns, but that should be easy enough to add.
import bisect
import copy
from cassandra.ttypes import NotFoundException, Column, ColumnPath, ColumnOrSuperColumn
class SSTable(object):
1568020383607837124674242424233936224366074619938054295149435080651133347159866539515828916334423825699216287430613550119009746682495526220087196369932993220993947068398348139078036223234189886410582032934294689156382470618963836853600005504402303219553800308328245464091978334255365120288597797327665191066332303969094527875543599893710346844574971075921041496871881080512503217260769624804065596751534343662438394009356717682549849813579683807411836806956417224771432950855424795916847683629888419235012414123218681592018347300549566480645820788828884670170227348048694510744364877265930061422199605236539854481131874246370399956781377830722015722886884059955236617197194789439998472191229648923258247262131755689255146886795535534537354318015385271178803608088214700126029621133594790006436889852250107606783683417339851548995227133141803484257221095744914814397064115308252464652873341285802340753454548916615332528616057502990290828900499685424871335209817720727253000270548565157264252790009718525020443966599344478805
# Requires apachelog from http://code.google.com/p/apachelog/source/browse/trunk/apachelog.py
import sys, time, re
from collections import defaultdict
from threading import Timer
import apachelog
class Parser(apachelog.parser):
from django.core.paginator import ObjectPaginator
class QuickObjectPaginator(ObjectPaginator):
max_safe_pages = 0
def __init__(self, object_list, per_page, orphans=0, max_safe_pages=0):
self.max_safe_pages = max_safe_pages
super(QuickObjectPaginator, self).__init__(object_list, per_page, orphans)
def validate_page_number(self, page_number):
@mmalone
mmalone / example.sh
Created February 12, 2019 22:14
Using `step certificate` without the online step CA
# Create a root certificate and signing key.
$ step certificate create "Root CA" root.crt root.key --profile root-ca
Please enter the password to encrypt the private key:
Your certificate has been saved in root.crt.
Your private key has been saved in root.key.
# Create an intermediate certificate & signing key. This isn't
# required; we could use the root to sign directly which is
# probably fine for local dev and removes the need to bundle later.
$ step certificate create "Intermediate CA" int.crt int.key --profile intermediate-ca --ca root.crt --ca-key root.key