Skip to content

Instantly share code, notes, and snippets.

View mmalone's full-sized avatar

Michael Malone mmalone

View GitHub Profile
@mmalone
mmalone / diskstats.py
Created July 14, 2011 00:10
python diskstats parser
def diskstats():
file_path = '/proc/diskstats'
# http://lxr.osuosl.org/source/Documentation/iostats.txt
columns_disk = ['major_dev_num', 'minor_dev_num', 'device', 'reads', 'reads_merged', 'sectors_read', 'ms_reading', 'writes', 'writes_merged', 'sectors_written', 'ms_writing', 'current_ios', 'ms_doing_io', 'weighted_ms_doing_io']
columns_partition = ['major_dev_num', 'minor_dev_num', 'device', 'reads', 'sectors_read', 'writes', 'sectors_written']
result = {}
for line in (l for l in open(file_path, 'r').xreadlines() if l != ''):
parts = line.split()
ARG FUNCTION_RUNTIME
FROM mikesir87/aws-cli as code
ARG FUNCTION_NAME
ARG AWS_DEFAULT_REGION
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
RUN wget -O function.zip `aws lambda get-function --function-name $FUNCTION_NAME --query 'Code.Location' --output text`
@mmalone
mmalone / readutf.java
Created February 24, 2010 22:10
Java vs. Python
/**
* Reads from the
* stream <code>in</code> a representation
* of a Unicode character string encoded in
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
* this string of characters is then returned as a <code>String</code>.
* The details of the modified UTF-8 representation
* are exactly the same as for the <code>readUTF</code>
* method of <code>DataInput</code>.
*
@mmalone
mmalone / README.md
Created November 5, 2015 04:10 — forked from mbostock/.block
Line Chart
>>> x = 'abcdefghijklmnopqrstuvwyz1234567890'
>>> for i in xrange(len(x) + 1):
... y = (x[:i] + 'x' * len(x))[:len(x)]
... print timeit.Timer('x == y', 'from __main__ import x, y').timeit()
...
0.0604889392853
0.0732460021973
0.069344997406
0.0671350955963
0.0664479732513
import math
import random
class Statistic(object):
"""
Hookin' it up with the seven descriptive statistics.
"""
def __init__(self, sample):
class Outer {
public Outer() {
}
public class Inner {
public Inner() {
}
public void doit() {
System.out.println("Sup.");
import random
import itertools
def find_collision(rng):
d = {}
for iteration in itertools.count():
nonce = rng()
if nonce in d:
return iteration
"""
Some simple utilities to read the magic bytes from the beginning of a
file and determine whether the file meets certain criteria (e.g., contains
JPEG image data).
"""
import array
from operator import eq
IMAGE_MAGIC_DATA = (
@mmalone
mmalone / models.py
Created September 3, 2009 01:05
hateoasis
import datetime
from django.db import models
class Frob(models.Model):
name = models.CharField(max_length=255)
created = models.DateTimeField(default=datetime.datetime.now)
class Fritz(models.Model):
age = models.IntegerField(default=5)