Skip to content

Instantly share code, notes, and snippets.

View davidthewatson's full-sized avatar

Dave davidthewatson

View GitHub Profile
@davidthewatson
davidthewatson / list_pip_dependencies.sh
Last active November 13, 2017 22:26
For a given python repo on github, output a list of dependencies for a virtualenv, then read that list and generate a CSV describing licenses
pip list | xargs pip show >output.txt
@davidthewatson
davidthewatson / halloween_lightify.py
Created November 2, 2017 02:11
Flash the house lights like an insane asylum for halloween
from lightify import Lightify
lightify = Lightify('192.168.1.10')
lightify.update_all_light_status()
lights = lightify.lights()
ls = {light.name(): light for light in lights.values()}
def rainbow():
r, g, b = 255, 0, 0
for g in range(256):
yield r, g, b
def encode(input_filename, output_bytearray):
with open(input_filename, 'rb') as f:
output_bytearray.extend(f.read())
def decode(input_bytearray, output_filename):
with open(output_filename, 'a+b')as f:
f.write(input_bytearray)
# test encode
In [19]: # takes string returns true if string contains balanced parens or false otherwise
...: # Balanced:
...: # >>> balanced("()")
...: # True
...: # >>> balanced("(())")
...: # True
...: # >>> balanced("()()")
...: # True
...: # Not Balanced:
...: # >>> balanced("(()))(")
import requests
import requests_jwt
import json
# email and password auth through postgrest
resp = requests.post('http://localhost:3000/rpc/login', json={"email": "[email protected]", "pass": "dog"})
print resp # <Response [200]>
# JWT token-based auth through postgrest using the returned token from above
auth = requests_jwt.JWTAuth(json.loads(resp.text)['token'])
@davidthewatson
davidthewatson / precise_crouton_i3.sh
Created December 9, 2015 19:11
Install Ubuntu Precise on Chromebook, crouton, with i3
wget -O ~/Downloads/crouton http://goo.gl/fd3zc
sudo sh -e ~/Downloads/crouton -t x11,audio,keyboard,extension -n i3precise
sudo enter-chroot -n i3precise
sudo apt-get install i3
echo "exec i3" > ~/.xinitrc
sudo apt-get install git vim python python-pip python-dev python-software-properties sshfs
sudo pip install virtualenv virtualenvwrapper
@davidthewatson
davidthewatson / getviews.py
Created June 25, 2015 16:09
Get all the view classes for the django sql explorer plugin
import inspect
import types
import explorer.views
for name, fn in inspect.getmembers(explorer.views):
if name[-4:] == 'View':
print name
if isinstance(fn, types.UnboundMethodType):
#setattr(Something, name, decorator(fn))
print fn
@davidthewatson
davidthewatson / fizzbuzz.py.py
Created April 4, 2015 02:29
fizzbuzz.py.py
from __future__ import print_function
def fbn(n, d, s):
for i,j in enumerate(d):
if n % j == 0:
return s[i]
return n
print(*(fbn(i, (15, 5, 3), ('fizzbuzz', 'buzz', 'fizz')) for i in range(1, 101)))
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------