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 <david@davidwatson.org>\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": "you@yours.com", "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. | |
---------------------------------------------------- |
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 [64]: lines = [] | |
In [65]: l = glob.glob('/home/watson/Downloads/attorney_master/*.png') | |
In [66]: for file in l: | |
line = '<h3>'+file+'</h3>'+'<img style="page-break-after:always;" src="' + file + '"</img>' | |
lines.append(line) | |
....: | |
In [67]: f = open('/home/watson/Downloads/attorney_master/index.html', 'w') |
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
... | |
# ==> Configuration for any authentication mechanism | |
# Configure which keys are used when authenticating a user. The default is | |
# just :email. You can configure it to use [:username, :subdomain], so for | |
# authenticating a user, both parameters are required. Remember that those | |
# parameters are used only when authenticating and not when retrieving from | |
# session. If you need permissions, you should implement that in a before filter. | |
# You can also supply a hash where the value is a boolean determining whether | |
# or not authentication should be aborted when the value is not present. | |
config.authentication_keys = [ :login ] |