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
pip list | xargs pip show >output.txt |
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
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 |
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
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 |
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
In [19]: # takes string returns true if string contains balanced parens or false otherwise | |
...: # Balanced: | |
...: # >>> balanced("()") | |
...: # True | |
...: # >>> balanced("(())") | |
...: # True | |
...: # >>> balanced("()()") | |
...: # True | |
...: # Not Balanced: | |
...: # >>> balanced("(()))(") |
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 glob | |
g = glob.glob('**/*.py', recursive=True) | |
for f in g: | |
with open(f, 'r') as original: | |
data = original.read() | |
with open(f, 'w') as modified: | |
modified.write("# Copyright (C) 2016 David Watson <[email protected]>\n\n" + 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
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']) |
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
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 |
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 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 |
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
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))) |
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
-- Two dashes start a one-line comment. | |
--[[ | |
Adding two ['s and ]'s makes it a | |
multi-line comment. | |
--]] | |
---------------------------------------------------- | |
-- 1. Variables and flow control. | |
---------------------------------------------------- |