Skip to content

Instantly share code, notes, and snippets.

View esammer's full-sized avatar

Eric Sammer esammer

  • Decodable
  • San Francisco, CA USA
  • X @esammer
View GitHub Profile
@esammer
esammer / genpasswd.py
Created December 28, 2010 21:39
A utility to generate passwords that conform to some standards
#!/usr/bin/env python
import random
import string
from optparse import OptionParser
class GenPassword:
_CHARSET = string.letters + string.digits
[esammer@xxxxx ~]$ ls -al /mnt/
ls: cannot access /mnt/foo: Permission denied
total 8
drwxr-xr-x. 3 root root 4096 Mar 20 17:48 .
dr-xr-xr-x. 23 root root 4096 Apr 17 14:09 ..
d?????????? ? ? ? ? ? foo
@esammer
esammer / fairsim.py
Created June 19, 2012 17:58
A python Hadoop Fair Scheduler algorithm simulator
#!/usr/bin/python
def fair_share(scheduables, totalCapacity):
print "demand:%s totalCapacity:%s" % (scheduables, totalCapacity)
totalDemand = reduce(lambda a, b: int(a) + int(b), [x['demand'] for x in scheduables])
cap = min(totalDemand, totalCapacity)
weightSlotRatio = 1.0
@esammer
esammer / fix-uid-gid.py
Created July 24, 2012 19:06
Load two /etc/passwd files and find all users and groups that need to be fixed on a machine.
#!/usr/bin/python
import sys
def load_passwd(path):
lookup = { }
f = file(path)
for line in f:
line = line.rstrip()
@esammer
esammer / AvroProjectionMapFn.java
Created August 31, 2012 01:27
A Crunch MapFn that can project Avro generic record fields
public class AvroProjectionMapFn extends MapFn<Record, Record> {
private static final long serialVersionUID = 1L;
private List<String> fieldNames;
private Schema sourceSchema;
private Schema projectionSchema;
@Override
@esammer
esammer / gist:3716323
Created September 13, 2012 18:11
Eclipse template for generating fluent (builder) methods.
public ${enclosing_type} ${name:field}(${type:elemType(name)} ${name}) {
this.${name} = ${name};
return this;
}
@esammer
esammer / gist:3777642
Created September 24, 2012 19:00
Eclipse template for generating a private static final slf4j logger
// Wire this up to an eclipse template called slf4j_logger and never type it again.
private static final Logger logger = LoggerFactory.getLogger(${enclosing_type}.class);
@esammer
esammer / gist:4042578
Created November 8, 2012 23:25
No description fully describes what this is.
} catch (NullPointerException e) {
throw npe(e, " of "+schema.getFullName());
}
}
/** Helper method for adding a message to an NPE. */
protected NullPointerException npe(NullPointerException e, String s) {
NullPointerException result = new NullPointerException(e.getMessage()+s);
result.initCause(e.getCause() == null ? e : e.getCause());
return result;
/*
* A simple example of user demographic dataset generation in scala.
*
* This highlights the following scala bits:
* - Java integration
* - Annotations
* - Tail recursion optimization
* - Enums
* - Vals vs. vars
* - Working with singleton objects
@esammer
esammer / gist:4680106
Last active December 11, 2015 23:58
damn scala you busted
scala> :silent
Switched off result printing.
scala> class Bad {
| var toStringCount: Int = 0
| override def toString(): String = { toStringCount += 1 ; super.toString() }
| }
scala> val b = new Bad