Skip to content

Instantly share code, notes, and snippets.

View hoffrocket's full-sized avatar
👋

Jon Hoffman hoffrocket

👋
  • Anomaly
  • New York, NY
View GitHub Profile
@hoffrocket
hoffrocket / Histogram.java
Created November 20, 2013 05:48
Java 8 Histogram
import java.util.Map;
import java.util.Random;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Histogram {
public static <T> Map<T, Integer> histogram(Stream<T> stream) {
return stream.collect(
Collectors.groupingBy(Function.<T>identity(),
@hoffrocket
hoffrocket / processpiping.py
Created November 13, 2013 01:29
process bytes in a forked process from python
#!/usr/bin/env python
import sys
from multiprocessing import Process, Pipe
POLL_TIMEOUT = 5
def hdfs_hadoopbin_upload(conn, dstpath, hdfs_user):
print("Uploading to %s as %s" % (dstpath, hdfs_user))
chunk_count = 0
@hoffrocket
hoffrocket / README.md
Last active December 27, 2015 12:49 — forked from miku/README.md

Example outputs:

$ python dynamic.py DynamicRequirements --a 4 --b 8

DEBUG: Checking if DynamicRequirements(a=4, b=8) is complete
INFO: Scheduled DynamicRequirements(a=4, b=8)
DEBUG: Checking if SomeTask(number=4) is complete
INFO: Scheduled SomeTask(number=4)
INFO: Done scheduling tasks

DEBUG: Asking scheduler for work...

import org.apache.commons.lang.StringUtils;
public class ReplaceTime
{
static final int LOOPS = 100000;
static void timeReplace() {
long start = System.nanoTime();
for (int i = 0; i < LOOPS; i++) {
"foo;bar;car".replace(";", "%3B");
@hoffrocket
hoffrocket / LiveLockExample.java
Created March 29, 2013 16:24
demonstrate livelock on java ThreadPoolExecutor
package jon;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@hoffrocket
hoffrocket / fourstalgia.nginx.conf
Created March 11, 2013 22:01
basic nginx proxy configuration
user nginx nginx;
worker_processes 2;
pid /var/run/nginx.pid;
error_log /var/log/nginx/error_log info;
worker_rlimit_nofile 8192;
events {
worker_connections 8192;
@hoffrocket
hoffrocket / QueueSim.scala
Created March 6, 2013 23:05
Distributed Applicaiton Simulator (may be buggy and/or completely incorrect)
object QueueSim {
class QueuedProcessor extends Processor {
var lastClock: Int = 0
var remainingWork: Int = 0
def advanceClock(currentTime: Int) {
remainingWork = math.max(0, remainingWork - (currentTime - lastClock))
lastClock = currentTime
}
def process(request: Request): Response = {
@hoffrocket
hoffrocket / .pylintrc
Created March 1, 2013 16:49
pylintrc
[MESSAGES CONTROL]
# Brain-dead errors regarding standard language features
# W0142 = *args and **kwargs support
# W0403 = Relative imports
# Pointless whinging
# R0201 = Method could be a function
# W0613 = Unused argument
# W0232 = Class has no __init__ method
# R0903 = Too few public methods
@hoffrocket
hoffrocket / FileTailer.scala
Last active December 14, 2015 02:59
Buffered FileTailer in scala.
import java.io.{File, RandomAccessFile}
import java.nio.{ByteBuffer, CharBuffer}
import java.nio.charset.Charset
/**
* Read lines from the end of a file.
*
* Partial lines that don't terminate with a newline will be lost
* Lines bigger than the buffer size will also be lost
*/
@hoffrocket
hoffrocket / disable-java.applescript
Last active December 14, 2015 00:18
Applescript to disable java in safari
#!/usr/bin/osascript
activate application "Safari"
tell application "System Events"
tell process "Safari"
click menu item "Preferences…" of menu 1 of menu bar item "Safari" of menu bar 1
click button "Security" of tool bar 1 of window 1
set theCheckbox to checkbox "Enable Java" of group 1 of group 1 of window "Security"
tell theCheckbox
if (its value as boolean) then click theCheckbox