Skip to content

Instantly share code, notes, and snippets.

View chadselph's full-sized avatar

Chad Selph chadselph

View GitHub Profile
@chadselph
chadselph / PlayAudio.scala
Created May 13, 2014 20:21
Audio Futures
import java.net.URL
import javax.sound.sampled.{AudioSystem, LineListener, LineEvent}
import scala.concurrent.{Promise, Future, Await}
import scala.concurrent.duration.Duration
object PlayAudio extends App {
val f = playUrl(
new URL("http://www.wavsource.com/snds_2014-05-05_4169601282614752/movies/airplane/wrong_week4.wav")
)
@chadselph
chadselph / Smppeezus.scala
Created May 13, 2014 20:31
smpp client to test binds
import java.net.{URL, InetSocketAddress}
import javax.sound.sampled.{AudioSystem, LineListener, LineEvent}
import scala.concurrent.{Promise, Future, Await}
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global
import akkasmpp.actors.{SmppClient, SmppClientConfig}
import akkasmpp.protocol.{Pdu, BindTransceiverResp, CommandStatus, COctetString, DeliverSm, DeliverSmResp}
import akka.actor.ActorSystem
import akka.pattern.ask
/**
* A command ID for SMPP
*/
trait FieldHelpers {
val className = getClass.getName.dropRight(1)
val missingLabel = "unknown"
for scope in path_scopes:
filter_constraints = cgi.parse_qs(scope.params.get('params', ''))
filter_keys = set(request.args.keys()) & set(filter_constraints.keys())
def arg_satisfies_filter(f):
return set(request.args[f]).issubset(set(filter_constraints[f]))
if all(arg_satisfies_filter(f) for f in filter_keys):
# if for every parameter, the values are a subset of allowed params, we good!
return True
@chadselph
chadselph / reqeusts_bug.py
Created October 20, 2011 03:22
requests gevent demo
"""
requests uses a singleton AuthManager, which when used with gevent's monkey patching
(or presumably, the threading module) can be set by one thread, and read by another.
The AuthManager maps urls to credentials which assumes for any url you will always
request it with the same credentials. This turned out to be false for us, and thus,
the bug. Here's code to reliably reproduce it.
"""
import base64
import gevent.monkey
@chadselph
chadselph / jscanary.py
Created October 20, 2011 20:49
redirect caching experiments
from flask import Flask
import flask
from gevent.pywsgi import WSGIServer
app = Flask(__name__)
app.debug = True
color = 'green'
@chadselph
chadselph / webui.py
Created February 24, 2012 17:26
simpler solution
import threading
from wsgiref.simple_server import make_server
from mylongtask import progress_status, run_task
# simple wsgi app; could replace with one from flask with templates,
# url dispatching, etc.
def simple_app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [str(progress_status)]
@chadselph
chadselph / runningwc.py
Last active December 11, 2015 21:09
Like `wc -l` but for `tail -f`. Example: tail -f some.log | grep ERROR | ./runningwc.py -i 5
#!/usr/bin/python -u
from twilio.rest import TwilioRestClient
import sys
import time
import threading
import argparse
total = 0
class Reporter(threading.Thread):
/**
* SCALA!!
*/
object DisjointGraphs extends App {
val disjoints = findThem(List((1,2), (2,3), (5,6), (7,8), (1,8)))
println(disjoints)
def findThem(edges: List[(Int, Int)]) = {
val initial = List[Set[Int]]() // empty list of int sets
object Test extends App {
trait BitPrinter[B <: BitDescription] {
def printBits(value: Long): (List[String], Long)
}
trait BitDescription
trait BitField extends BitDescription