Skip to content

Instantly share code, notes, and snippets.

View fredrik's full-sized avatar
🚀

Fredrik Möllerstrand fredrik

🚀
View GitHub Profile
don't use poetry, art or music to get into girls' pants. use it to get into their heads.
; emacsen UTF-8 glory
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
# what's the single state in america whose name does not
# have any letters in common with george w. bush?
states='Alabama
Alaska
Arizona
Arkansas
California
Colorado
Connecticut
import time
# decorator that measures execution time of a function.
def timing(func):
def wrapper(*arg):
t0 = time.time()
r = func(*arg)
elapsed = time.time() - t0
print '%s => %0.3f ms' % (func.func_name, elapsed*1000.00)
return r
#!/usr/bin/env python
# these here programming codes are licensed under the gnu fearsome dude license.
# writes 500k rows to a table, where each row represents a track in an artist's
# library for a single day. the play count is stored in the cfq 'unit:scrobbles'.
# 1: hbase(main):001:0> create '500k-test', 'unit:'
# 2: $> hbase thrift start
# 3: $> python testdata-500k.py (~500 seconds on my hackintosh)
#!/bin/bash -xe
# from http://gist.github.com/249915 by fairchild
if [ -z $1 ]; then
echo "usage: $0 INSTANCE_ID"
exit
fi
EBS_DEVICE='/dev/sdh'
INSTANCE_ID=$1
# run like so:
# $> ruby normalize.rb --run=local --input data/sizes --output data/normalized_sizes
module Normalize
class Mapper < Wukong::Streamer::LineStreamer
def process(line)
fields = line.strip.split("\t")
country = fields.reverse!.pop
data = fields.map(&:to_i)
@fredrik
fredrik / centrality.py
Created October 19, 2010 09:27
calculate centrality measures for a network using networkx
#!/usr/bin/env python
import networkx as nx
# for each node:
# + degree centrality
# + closeness centrality
# + betweenness centrality
# + eigenvector centrality
# + page rank
@fredrik
fredrik / graphite-web-0.9.7.fix.pyparsing.patch
Created March 15, 2011 14:09
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
diff --git a/cli/parser.py b/cli/parser.py
index ec1a435..7d7d48d 100644
--- a/cli/parser.py
+++ b/cli/parser.py
@@ -12,7 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""
-from graphite.thirdparty.pyparsing import *
+from pyparsing import *
#!/usr/bin/python
"""Copyright 2008 Orbitz WorldWide
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software