Skip to content

Instantly share code, notes, and snippets.

''' communicating to openbts through zeromq
'''
import json
import zmq
address = 'tcp://127.0.0.1:45060'
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect(address)
payload = {
# via
# https://mail.python.org/pipermail/python-list/2010-August/586080.html
import random
import timeit
with open('/usr/share/dict/words') as infile:
words = [line.strip() for line in infile]
sample = random.sample(words, 501)
@yosemitebandit
yosemitebandit / Graph.py
Last active August 29, 2015 14:11
exercises 2.2, 2.3 and 2.4 from think complexity
"""from Ch2 of think complexity."""
class Graph(dict):
def __init__(self, vertices=[], edges=[]):
for vertex in vertices:
self.add_vertex(vertex)
for edge in edges:
self.add_edge(edge)
def add_vertex(self, vertex):
# run the ubuntu setup script first
# note that this isn't quite a true shell script -- some paths will need modification
# setup and activate a venv
virtualenv /path/to/venv
source /path/to/venv/bin/activate
# order seems to matter here :|
@yosemitebandit
yosemitebandit / graph.go
Created December 18, 2014 10:02
some of the early Ch2 exercises from think complexity; now here: github.com/yosemitebandit/think-complexity
package graph
type Vertex struct {
Label string
}
type Edge struct {
Start Vertex
End Vertex
}
@yosemitebandit
yosemitebandit / plot_shp.py
Last active August 29, 2015 14:11
using tiger census data at the block level to find the population of a circular area
"""plot_shp.py
Plots a shapefile with fiona, decartes and matplotlib.
"""
import descartes
import fiona
from matplotlib import pyplot
@yosemitebandit
yosemitebandit / even_points.py
Last active August 29, 2015 14:14
SA with scipy
""" Placing points in a polygon evenly with simulated annealing.
"""
import math
import random
import descartes
from matplotlib import pyplot
import scipy.optimize
import shapely.geometry
@yosemitebandit
yosemitebandit / decode.py
Created February 26, 2015 18:04
decode and resave urlencoded files
import sys
import urllib
# Read.
with open(sys.argv[1]) as cdr_file:
cdr_data = cdr_file.read()
# Decode.
decoded_data = urllib.unquote(cdr_data).decode('utf8')
print decoded_data
@yosemitebandit
yosemitebandit / test_headers.py
Created April 24, 2015 17:52
header testing script
import requests
good_hosts = ('www.endaga.com', 'endaga.com', 'staff.endaga.com',
'staging.endaga.com')
bad_hosts = ('www.bad-host.com', 'bad-host.com')
url = 'https://staging.endaga.com'
print 'GET %s' % url
@yosemitebandit
yosemitebandit / gprs_lister.py
Created May 6, 2015 00:27
get the output of the "gprs list" command in OpenBTS for analysis purposes
"""Continuously records the output of "gprs list" from OpenBTSCLI.
Run as follows (then you can logout of the session and it'll keep going):
$ nohup python gprs_lister.py &
"""
import time
import envoy