Skip to content

Instantly share code, notes, and snippets.

View scottx611x's full-sized avatar

Scott Ouellette scottx611x

View GitHub Profile
@scottx611x
scottx611x / ps_logger.py
Last active November 20, 2017 19:23
Gather `ps` output sorted by memory usage and log to a file
import datetime
import sys
import time
from subprocess import check_output
try:
filename = sys.argv[1]
except IndexError as e:
print "Must specify a filename."
sys.exit(1)
@scottx611x
scottx611x / admin_field_populator.py
Last active August 10, 2017 19:50
Class that exposes all of a models fields in the django admin interface
class AdminFieldPopulator(admin.ModelAdmin):
"""
Wrapper around ModelAdmin that exposes all of a Model's fields in admin ui
"""
def __init__(self, model, admin_site):
super(AdminFieldPopulator, self).__init__(model, admin_site)
self.list_display = [field.name for field in model._meta.fields]
@scottx611x
scottx611x / router_combine.py
Created March 2, 2017 20:51
Django Rest Framework Router combiner
from rest_framework.routers import DefaultRouter
class RouterCombiner(DefaultRouter):
"""
Extends `DefaultRouter` class to add a method for extending url routes
from another router.
Allows for app-specific url definitions to stay inside their own apps.
"""
@scottx611x
scottx611x / spinner.py
Last active June 7, 2016 12:49 — forked from empiricalthought/spinner.py
Python 2 compatible ASCII spinner for progress feedback
import itertools
import sys
def spinner(granularity):
"""Wraps a function in an ASCII spinner display loop. granularity
represents the number of times the function should be called
before moving the spinner."""
spinner_chars = itertools.cycle("\|/-")
def make_spinner(f):
calls = {'x': 0}
__author__ = 'scott'
with open('massachusetts_municipalities.txt', 'r') as inf, open('interleaved_list2.txt', 'w') as out:
A,B,C =[],[],{}
A += [item.strip() for item in inf]
for item in A:
if not item[0] in C: C[item[0]] = []
C[item[0]].append(item)
B += [C[key] for key in sorted(C)]
while B:
if [] in B: B.remove([])
@scottx611x
scottx611x / check_Knock.py
Created June 15, 2015 23:31
Verify User Knock Data
import pifacedigitalio as pfio
import time,sys, threading, pickle
pifacedigital = pfio.PiFaceDigital()
pfio.init()
#Solenoid LOW
pfio.digital_write(5, 1)
time.sleep(.1)
@scottx611x
scottx611x / get_Knock.py
Created June 15, 2015 23:30
Get User Knock data
import pifacedigitalio as pfio
import time,sys, threading, pickle
pifacedigital = pfio.PiFaceDigital()
pfio.init()
#Blink LED to let user know they can enter knock codes
def blink_LED(PIN):
while 1:
p = PIN
@scottx611x
scottx611x / PI_Knock.py
Last active August 29, 2015 14:22
Raspberry Pi "Knocker"
import pifacedigitalio as pfio
import time,sys, threading
pifacedigital = pfio.PiFaceDigital()
pfio.init()
#Blink LED to let user know they can enter knock codes
def blink_LED(PIN):
while 1:
p = PIN
@scottx611x
scottx611x / Brainfuck.py
Last active August 29, 2015 14:22
Brainfuck interpreter
# Scott Ouellette
# Brainfuck interpreter w/ optimizations
import sys as s
import time,re
def parser(code):
open_brack = [] # contains indexes of open brackets that are found
loop = {} # dictionary mapping idx of open brackets to closed ones
@scottx611x
scottx611x / Lossy_Compress.py
Created June 9, 2015 15:59
"Lossy" text compression using a thesaurus
import nltk,re,os
from nltk.corpus import wordnet as wn
#Lossy text compression using a thesaurus
print "File size originally: " , float(os.path.getsize('Sample.txt')) / 1048576, "MB"
with open('Sample.txt','r') as f, open('Output.txt', 'w+') as O:
for line in f:
for word in line.split():
punctuation = []
l = []