Skip to content

Instantly share code, notes, and snippets.

View apg's full-sized avatar
🐢
Turtle

Andrew Gwozdziewycz apg

🐢
Turtle
View GitHub Profile
{
graphitePort: 2003
, graphiteHost: "localhost"
, port: 8125
, statusPort: 8126
, statusAddr: "0.0.0.0"
, flushBuckets: [
{
pattern: "^pagetime\.domload.*"
, flushInterval: 60000
from nyanbar import NyanBar
progress = NyanBar()
import time
for n in range(100):
time.sleep(.1)
progress.update(n)
@apg
apg / wtf8.py
Created August 19, 2011 14:09 — forked from philikon/wtf8.py
WTF-8 codec for Python
# wtf8.py
import codecs
def encode(input, errors='strict'):
return input.encode('utf-8', errors).decode('latin-1', errors).encode('utf-8', errors), len(input)
def decode(input, errors='strict'):
return input.decode('utf-8', errors).encode('latin-1', errors).decode('utf-8', errors), len(input)
class StreamWriter(codecs.StreamWriter):
@apg
apg / callcc.py
Created August 17, 2011 12:16
revised callcc python
import greenlet
class ContinuationError(Exception): pass
def callcc(f):
saved = [greenlet.getcurrent()]
def cont(val):
if saved[0] == None:
raise ContinuationError("one shot continuation called twice")
@apg
apg / gist:1147620
Created August 15, 2011 19:50 — forked from pkazmier/gist:1147588
orbitz erc-minor-mode has been revived!!
;; orbitz Mode
;; Need to add the ERC hook in emacs for it to work:
;; (add-hook 'erc-send-pre-hook 'erc-maybe-orbitz)
(define-minor-mode erc-orbitz-mode
"Toggle automatic orbitzing everything you type in ERC."
nil " orbitz")
(defun erc-maybe-orbitz (ignore)
"Change the text to orbitz text, if `erc-orbitz-mode' is non-nil."
(defun three-quarters-window ()
"Resizes current window big"
(interactive)
(let ((size (- (truncate (* .75 (frame-height))) (window-height))))
(if (> size 0)
(enlarge-window size))))
(global-set-key "\C-x7" 'three-quarters-window)
@apg
apg / continuations.py
Created August 3, 2011 13:52
one-shot continuations via python greenlets
"""
example ported to python + greenlet from Revisiting Coroutines http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.58.4017
"""
import greenlet
class ContinuationError(Exception): pass
def call_cc(f):
saved = [greenlet.getcurrent()]
@apg
apg / test_hashmap.c
Created July 29, 2011 14:22
Sample test "framework" for the first (abandoned) stab at tin in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../src/hashmap.h"
#define NUM_TESTS 1
int PASSED = 0;
@apg
apg / CompletelyUnsafe.java
Created July 29, 2011 13:45
Yes, I know it's an abomination.
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
public class FooMap {
public static <K, V> Map<K, V> map(Object ... items) {
Map<K, V> m = new HashMap<K, V>();
// potentially off by 1, but this is just a test anyway.
for (int i = 0; i < items.length; i += 2) {
#ifndef _SN_UTILS_H
#define _SN_UTILS_H
#include <stdio.h>
#include "error.h"
#define TODO(x) do {fprintf(stderr, "TODO: Didn't do that yet: %s %s:%d\n", \
x, __FILE__, __LINE__);} while (0);
#define ERROR(t, x) do { \