Skip to content

Instantly share code, notes, and snippets.

View samuraisam's full-sized avatar

Samuel Sutch samuraisam

View GitHub Profile
"""
My dependency injection framework for Python. Using a context manager it allows
you to rewrite globals (such as imports, top-level classes and functions, whatever
you want) in a module and have them replaced at the end of the with block. This is
usually enough. `proxy` is just a dict-wrapping type class which will create a
type with "class variables" for every key you give it.
Usage:
from di import *
@samuraisam
samuraisam / NSString+Truncation.h
Created December 15, 2010 23:05
Simple, reliable word truncation whether HTML exists in the text or not.
@interface NSString (WordTruncation)
- (NSString *)substringOfHTMLToWordIndex:(NSUInteger)to appendOnTruncate:(NSString *)append softLimit:(int)leSoftLimit;
- (NSString *)substringToWordIndex:(NSUInteger)to;
@end
@samuraisam
samuraisam / deep_eq.py
Last active March 29, 2024 22:17
Deep Equality Test for Nested Python Structures
#Copyright (c) 2010-2013 Samuel Sutch [samuel.sutch@gmail.com]
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
@samuraisam
samuraisam / resize.py
Created May 11, 2011 00:14
Intelligently resize an image in python
from collections import namedtuple
from magickwand.image import Image
Size = namedtuple('Size', ['width','height'])
Point = namedtuple('Point', ['x','y'])
Rect = namedtuple('Rect', ['origin', 'size'])
class ResizeMethods:
@samuraisam
samuraisam / supervisord.sh
Created July 13, 2011 20:25 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
stream_columnfamily = pycassa.ColumnFamily(pool, 'Stream', autopack_names=True, autopack_values=False,
read_consistency_level=pycassa.ConsistencyLevel.ONE,
write_consistency_level=pycassa.ConsistencyLevel.QUORUM)
key = self.stream_key + '/' + last
column = {object_id: object_type}
print 'column', column
return self.batch.insert(key, column)
stream/public 1.545907
stream/public 0.820901
stream/public 0.607766
stream/public 1.033473
stream/public 0.821086
stream/public 0.597097
stream/public 0.600137
stream/public 0.653457
stream/public 0.587955
stream/public 0.618521
## ON EC-2 0.8.4
## java version "1.6.0_20"
## OpenJDK Runtime Environment (IcedTea6 1.9.8) (amazon-52.1.9.8.34.amzn1-x86_64)
## OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
>>> import api.cass
>>> s=api.cass.Stream(-1,'Public')
>>> x,y=s.get()
>>> t=[_[0] for _ in y]
>>> t == sorted(t)
False