Skip to content

Instantly share code, notes, and snippets.

View davidthewatson's full-sized avatar

david watson davidthewatson

View GitHub Profile
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": "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'])
@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.
----------------------------------------------------
@davidthewatson
davidthewatson / screenshots.py
Created August 21, 2014 23:13
write a hacked index.html for a bunch of screenshots
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')
...
# ==> 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 ]