Skip to content

Instantly share code, notes, and snippets.


Mike Lewis mikelikespie

View GitHub Profile
def retries(num_retries, exception_types=Exception, check_func=None, timeout=0.0):
"""retries a function ``num_retries`` times.
will catch ``exception_types`` of exceptions. This can be a tuple as well.
check_func can optionally be provided. It takes the exception as an argument.
If it returns a value that evaluates to false, the exception will be reraised.
can be used like:
View gist:358193
class Hash
alias :old_to_a :to_a
def safe_to_a
def to_a
View html.vim
" Vim indent file
" Language: html
" Maintainer: what's that? <>
" URL: hah
" Anon CVS: hah
" Release Coordinator: Mike Lewis <>
runtime! indent/javascript.vim
unlet! b:did_indent
mikelikespie / sessionize_postgres.sql
Created June 16, 2010 20:09
This is an example how to use custom aggregates and windowing functions in postgres to stitch sessions using timeouts. sessionize_postgres_output.out is what happens when you run sessionize_postgres.sql.
View sessionize_postgres.sql
drop schema sessionize_test cascade;
create schema sessionize_test;
set search_path to sessionize_test;
create type user_session as (
start_time timestamptz,
last_time timestamptz
mikelikespie /
Created August 28, 2010 10:25
A DSL for html generation in python (I am a bad person and have been around ruby developers too long). It's just a prototype and the generation can't be controlled too well yet, but it is sweet. I am pretty sure this is violating most of the Zen of pyth
import sys
from functools import partial, wraps
from contextlib import contextmanager
from cStringIO import StringIO
# Should output the following
# <html>
# <head>
mikelikespie / colors.js
Created October 22, 2010 23:01
Quick code to convert sRGB to CIE L*a*b* and back.
View colors.js
* To try it:
* c = $c.sRGB8(23,58,32);
* c.Lab();
* c.Lab().sRGB8();
var $c = {};
function () {
mikelikespie / refresh_css.js
Created October 27, 2010 18:31
This refreshes all the css on a page by changing the query string
View refresh_css.js
Add a bookmark to this
javascript:(function(){var c=document.getElementsByTagName("link");for(var d=0;d<c.length;d++){var a=c[d];if(a.rel=='stylesheet'||a.type=="text/css"){var e="css_buster_"+Math.floor(Math.random()*1000000000);var g=a.href.split("?",2);var f;if(g.length>1){var b=g[1].indexOf("&")==-1;if(b){f=e}else{f=g[1]+"&"+e}}else{f=e}a.href=g[0]+"?"+f}}})();
(function() {
var links = document.getElementsByTagName('link');
for (var i = 0; i < links.length; i++) {
var l = links[i];
if (l.rel == 'stylesheet' || l.type == 'text/css') {
mikelikespie / rpmspec.rb
Created December 7, 2010 00:10
Parses out stuff from an RPM Spec file
View rpmspec.rb
class RPMSpec
attr_reader :spec
def initialize(spec)
@tags = {|h,k| h[k] = []}
@defines = {}
@spec = spec
@sections = {|h,k| h[k] = []}
#@rpm_build_dir = rpm_build_dir
mikelikespie / hbase_clone_table.rb
Created December 8, 2010 21:03
clones a table in hbase. Optionally takes an array of strings that are the keys to create the splits on
View hbase_clone_table.rb
def clone_table(old_table_name, new_table_name, split_keys=nil)
admin =
td = admin.getTableDescriptor(old_table_name.to_java_bytes)
if split_keys.nil?
new_keys = Java::byte[][split_keys.size].new
split_keys.each_index {|i| new_keys[i] = split_keys[i].to_java_bytes}
mikelikespie / hbase_redistribute_regions.rb
Created December 9, 2010 00:15
Redistributes HBase regions by closing them
View hbase_redistribute_regions.rb
def redistribute_regions(table_name)
admin =
t =
t.getRegionsInfo().each do |r, addr|
puts "closing region #{r.getRegionNameAsString()}"
admin.closeRegion(r.getRegionNameAsString().to_java_string, [].to_java)