Skip to content

Instantly share code, notes, and snippets.

import java.io.File;
import java.util.logging.Logger;
public class ThreadedDemo {
private static Logger logger = Logger.getLogger("demo");
// "Inner class" represents a single thread that runs forever, looking for
// a certain file to appear, then "processes it," for demo
// purposes just renaming it to another name
static class Worker implements Runnable {
@agleyzer
agleyzer / gist:3859749
Created October 9, 2012 16:04
Download infoq video
#!/usr/bin/env python
# Looking for MP4 videos in infoq content.
#
# <div style="width: 320px; height: 265px; float: left; margin-right: 10px;">
# <video poster="/styles/i/logo_scrubber.png" id="video" controls="controls" width="320" height="265">
# <source src="http://d1snlc0orfrhj.cloudfront.net/presentations/12-mar-lockfreealgorithms.mp4" />
# </video>
# </div>
@agleyzer
agleyzer / gist:4003771
Created November 2, 2012 19:27
mod_perl snafu
#!/usr/local/bin/perl
use CGI qw/:standard/ ;
use strict;
# demonstration how mod_perl may screw up your naive CGI code... Call
# this script passing different name parameter several times.
my $name = param('name') || "professor";
@agleyzer
agleyzer / TetrisShapes.scala
Created March 8, 2013 22:06
Calculates all possible Tetris-like shapes for a given number of squares.
// Calculates all possible Tetris-like shapes for a given number of
// squares.
object TetrisShapes extends App {
type Point = (Int, Int) // x, y
type Shape = Set[Point]
// returns a list of neighbors for a point
def neighbors(p: Point) = {
@agleyzer
agleyzer / gist:6616242
Created September 18, 2013 21:48
a script to log http connections...
#!/bin/bash
ts=$(date +%Y%m%d-%H%M%S)
tcpdump -A -s 1492 -l \
'host blahblah and tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' \
| grep HTTP -C 10 > httpdump-${ts}.log 2>&1 &
disown %1
@agleyzer
agleyzer / DnsCluster.scala
Created October 9, 2013 21:48
A Finagle Cluster that uses DNS, based on ZookeeperServerSetCluster.
import com.twitter.concurrent.Spool
import com.twitter.finagle.builder.Cluster
import com.twitter.finagle.util.DefaultTimer
import com.twitter.logging.Logger
import com.twitter.util.FuturePool
import com.twitter.util.{Duration, Future, JavaTimer, Promise, Return, Time, Timer}
import java.net.InetAddress
import java.net.UnknownHostException
import java.net.{InetSocketAddress, SocketAddress}
import java.security.Security
@agleyzer
agleyzer / finagle_demo.scala
Created October 10, 2013 18:01
NYT Code Weekly Finagle Demo
import com.twitter.conversions.time._
import com.twitter.finagle.Service
import com.twitter.finagle.builder.{ClientBuilder, Server, ServerBuilder}
import com.twitter.finagle.http.{Http, Request, Response, RichHttp}
import com.twitter.finagle.util.DefaultTimer
import com.twitter.finagle.util.DefaultTimer.{twitter => timer}
import com.twitter.util.{Await, Future, Stopwatch}
import java.net.{InetSocketAddress, SocketAddress}
import org.jboss.netty.handler.codec.http.HttpResponseStatus
import scala.util.Random
import com.twitter.conversions.time._
import com.twitter.finagle.{Addr, Name}
import com.twitter.finagle.util.DefaultTimer
import com.twitter.logging.Logger
import com.twitter.util.{Duration, Future, FuturePool, Timer, Updatable, Var}
import java.net.{InetAddress, InetSocketAddress, SocketAddress}
import java.security.Security
/**
@agleyzer
agleyzer / gist:7758128
Created December 2, 2013 20:23
my ~/.sbtconfig, works w/ SBT 0.13 and ansi-term
SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M"
# this allows sbt to be executed in Emacs terminal
if [[ -n $EMACS ]]; then
echo "Emacs detected, commencing hijacking sequence..."
# to avoid division by zero, with jline 1.0, see https://github.com/sbt/sbt/issues/714
stty columns 80
# avoid fancy colors that comint-mode won't support anyway
@agleyzer
agleyzer / akamai2graphite.py
Created January 29, 2014 21:30
Bulk loader for Akamai traffic reports CSV to Graphite
#!/usr/bin/env python
import socket
from datetime import datetime
import csv
import sys
import pickle
import struct
import threading
import urllib2