This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
class Stack(object): | |
def __init__(self): | |
self.items = [] | |
def push(self, item): | |
self.items.append(item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(object): | |
def __init__(self, value): | |
self.value = value | |
self.next = None | |
def __repr__(self): | |
return 'Node %s' % self.value | |
class LinkedList(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Order a queryset by last_active and make null values sort last.""" | |
import datetime | |
from django.db.models.functions import Coalesce | |
from app import models | |
# Coalesce works by taking the first non-null value. So we give it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventTable(tables.Table): | |
def __init__(self, *args, **kwargs): | |
# Pop out the date_header named arg before calling super. | |
date_header = kwargs.pop('date_header', 'Date') | |
super(EventTable, self).__init__(*args, **kwargs) | |
self.base_columns['date'].verbose_name = date_header | |
class Meta: | |
model = models.Event | |
fields = ('date', 'value') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""XLS -> json converter | |
first: | |
$ pip install xlrd | |
then: | |
$ cat in.xls | |
date, temp, pressure | |
Jan 1, 73, 455 | |
Jan 3, 72, 344 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""plot_shp.py | |
Plots a shapefile with fiona, decartes and matplotlib. | |
""" | |
import descartes | |
import fiona | |
from matplotlib import pyplot | |