Skip to content

Instantly share code, notes, and snippets.

View davidthewatson's full-sized avatar

david watson davidthewatson

View GitHub Profile
@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')
-- 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 / 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)))
@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 / fabfile.py
Created June 29, 2011 21:32
This is a copy of my current fabric configuration
from fabric.api import env, put, run, sudo
from fabric.contrib.files import upload_template
env.hosts = ['host1', 'host2']
env.password = 'your_password'
def upgrade():
run('apt-get update && apt-get -y upgrade')
reboot()
@davidthewatson
davidthewatson / gist:1447245
Created December 8, 2011 15:14
this is a test
This is a test.
@davidthewatson
davidthewatson / gist:1447389
Created December 8, 2011 15:51
This is the description.

This is the content.

@davidthewatson
davidthewatson / gist:1449507
Created December 9, 2011 00:38
python: set attributes in class given key value pairs
class a():
def set_attrs_in_class_given_key_value_pairs(**kwargs):
for k,v in kwargs.iteritems():
setattr(self, k, v)
@davidthewatson
davidthewatson / this_is_a_test.html
Created December 11, 2011 22:37
This is a test.
This is <i>only</i> a test.
With an extra file.