Skip to content

Instantly share code, notes, and snippets.

View mikelikespie's full-sized avatar

Mike Lewis mikelikespie

View GitHub Profile
@mikelikespie
mikelikespie / uio_test.go
Last active August 29, 2015 13:59
Read does not return when FD is closed for UIO
package foo
import (
"io"
"os"
"testing"
"time"
)
func TestReadClosed(t *testing.T) {
@mikelikespie
mikelikespie / fun.swift
Last active August 29, 2015 14:26
infinite hang in swift
public class Promise<T> {
}
/// These are basically promises that won't terminate until they hit the end
public enum MoreOrEnd<T> {
public typealias ValueTuple = (T, Promise<MoreOrEnd<T>>)
case More(ValueTuple)
case End
}
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:
class Hash
alias :old_to_a :to_a
def safe_to_a
old_to_a.sort
end
def to_a
safe_to_a
end
" Vim indent file
" Language: html
" Maintainer: what's that? <lol@lol.com>
" URL: hah
" Anon CVS: hah
" Release Coordinator: Mike Lewis <mikelikespie@gmail.com>
"
runtime! indent/javascript.vim
unlet! b:did_indent
@mikelikespie
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.
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
mikelikespie / cheeseburger.py
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
mikelikespie / refresh_css.js
Created October 27, 2010 18:31
This refreshes all the css on a page by changing the query string
/*
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
mikelikespie / rpmspec.rb
Created December 7, 2010 00:10
Parses out stuff from an RPM Spec file
class RPMSpec
attr_reader :spec
def initialize(spec)
@tags = Hash.new {|h,k| h[k] = []}
@defines = {}
@spec = spec
@sections = Hash.new {|h,k| h[k] = []}
#@rpm_build_dir = rpm_build_dir
@mikelikespie
mikelikespie / hbase_redistribute_regions.rb
Created December 9, 2010 00:15
Redistributes HBase regions by closing them
def redistribute_regions(table_name)
admin = HBaseAdmin.new(HBaseConfiguration.new())
t = HTable.new(table_name.to_java_string)
t.getRegionsInfo().each do |r, addr|
puts "closing region #{r.getRegionNameAsString()}"
admin.closeRegion(r.getRegionNameAsString().to_java_string, [].to_java)
end
end