Skip to content

Instantly share code, notes, and snippets.

View apg's full-sized avatar
🐢
Turtle

Andrew Gwozdziewycz apg

🐢
Turtle
View GitHub Profile
@apg
apg / gist:bf6c46d1604ca2f535ab
Created July 7, 2014 23:52
Epigrams in Programming - Perilsisms
EPIGRAMS IN PROGRAMMING
1. One man's constant is another man's variable.
2. Functions delay binding; data structures induce binding. Moral: Structure data late in the programming process.
3. Syntactic sugar causes cancer of the semicolon.
@apg
apg / stats.el
Created July 10, 2014 15:59
stats
(let* ((values '(11152 6423 8383 7466 6759 7249 6951 8793 7949 6840 7209 8022 11493 11331 6787 5616 9175 9528 7883 7210 10142))
(sum (reduce '+ values))
(avg (/ sum (length values)))
(mini (apply 'min values))
(maxi (apply 'max values))
(dev (reduce '+ (mapcar '(lambda (x) (* (- x avg) (- x avg))) values)))
(std (sqrt (/ dev (length values)))))
(list sum avg mini maxi dev std))
@apg
apg / html2text.py
Created August 13, 2014 21:05
Handle anchors a bit better...
#!/usr/bin/env python2.7
"""html2text: Turn HTML into equivalent Markdown-structured text."""
__version__ = "2.38"
__author__ = "Aaron Swartz (me@aaronsw.com)"
__copyright__ = "(C) 2004-2008 Aaron Swartz. GNU GPL 3."
__contributors__ = ["Martin 'Joey' Schulze", "Ricardo Reyes", "Kevin Jay North"]
# TODO:
# Support decoded entities with unifiable.
@apg
apg / lines.sh
Created August 20, 2014 15:10
How many lines a day do you write?
# This inflates things pretty horribly since it's looking at
# raw lines (including comments, documentation, etc) rather
# than lines of code metrics that you might get from a tool
# like sloccount, or cloc
AUTHOR=apg
for n in {1..100}; do
PAGER=cat git log --numstat --since="$n days ago" --until="$(expr $n - 1) days ago" --author=$AUTHOR | grep '^[0-9]' | awk 'BEGIN { lines = 0 } { lines += ($1 - $2) } END { print lines }'
done
@apg
apg / hackandtell.js
Created August 28, 2014 18:29
Google app script for hack and tell. Probably a dupe.
var PENDING_INVITE = '#fff2cc';
var INVITED = '#00ff00';
var CONFIRMED = '#ffff00';
var NOT_THIS_TIME = '#00ffff';
var NOT_THIS_TIME_SENT = '#4a86e8';
function markPerson(person, newtyp) {
var nameCell = person['range'].getCell(1, 1);
nameCell.setBackground(newtyp);
};
import re, itertools
from PIL import Image
def str2pt(s):
L = len(s) - 1
x, y = 1, 1
for n in s:
y += 2**L if n in '34' else 0
x += 2**L if n in '14' else 0
L -= 1
@apg
apg / shh-listen.md
Last active August 29, 2015 14:07
shh listen poller upgrades.

Listen Poller

Overview

The listen poller is a poller that allows external sources to record metrics through a single shh instance. This means that any process that can produce output, can record metrics through shh. While this is happening, shh can concurrently collect and publish it's own metrics (from other pollers).

@apg
apg / ricon-2014.org
Last active August 29, 2015 14:08
Notes from Ricon 2014

Ricon 2014 Notes

Keynote: Marten Mickos (SVP and General Manager, HP Cloud): Open Source Wins

Started with RDBMSes and needed to “scale out”.

  • Why? Well, we couldn’t scale up anymore. (talking about MySQL)

Composibility of simple components

Distributed (not monolithic)

Design for failure (Assume everything is always going to fail)

  • Shift in trust. (> more reliable)
@apg
apg / echo.py
Created November 12, 2014 15:03
one line echo server in python.
import socket
import itertools
(lambda port, s=socket.socket(socket.AF_INET, socket.SOCK_STREAM):
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) == None and
s.bind(('', port)) == None and
s.listen(5) == None and
list(map(lambda c:
c[0].sendall(c[0].recv(1024)) and
c[0].close(),
(s.accept() for _ in itertools.count(1)))) != None and
@apg
apg / dawk.go
Created January 16, 2015 19:22
really crappy prototype of dawk
package main
import (
"bufio"
"io"
"regexp"
"strings"
"sync"
)