Skip to content

Instantly share code, notes, and snippets.

View davidthewatson's full-sized avatar

Dave 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')
...
# ==> 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 ]
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
#!/usr/bin/env python
'''
Based on http://ginstrom.com/scribbles/2012/05/10/continuous-integration-in-python-using-watchdog/
Dependencies: ``watchdog`` (pip install watchdog)
Montiors the whole tree for changes.
Check for all changes to any files and test the associated package; we might want to test changes to a pyramid test.ini, say, or a file rename as part of a refactor.
@davidthewatson
davidthewatson / sendmail_from_python.py
Created December 11, 2012 16:03
sendmail from python
from email.mime.text import MIMEText
from subprocess import Popen, PIPE
msg = MIMEText("You don't have to have password access to someone's email account to send email as them.")
msg["From"] = "FirstName LastName <[email protected]>"
msg["To"] = "FirstName LastName <[email protected]>, FirstName LastName <[email protected]>"
msg["Subject"] = "This is the subject."
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
p.communicate(msg.as_string())
@davidthewatson
davidthewatson / node-on-ec2-port-80.txt
Created November 8, 2012 19:44 — forked from kentbrew/node-on-ec2-port-80.md
How I Got Node.js Talking on EC2's Port 80
## The Problem
Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)
## The temptingly easy but ultimately wrong solution:
Alter the port the script talks to from 8000 to 80:
}).listen(80);
@davidthewatson
davidthewatson / phpbb_extauth.py
Created September 27, 2012 14:40 — forked from SalemHarrache/phpbb_extauth.py
Ejabberd extauth : Authenticate phpbb users against PostgreSQL with Peewee
#!/usr/bin/env python
# Ejabberd extauth : Authenticate phpbb users against PostgreSQL with Peewee
# Original Author: Lukas Kolbe <[email protected]>
import sys
import logging
import struct
from hashlib import md5
@davidthewatson
davidthewatson / gist:3152909
Created July 20, 2012 20:06 — forked from igrigorik/gist:3148848
Convert any YouTube video into an audio file you can listen to on the go...
# Convert any YouTube video into an audio file you can listen to on the go, using:
# http://rg3.github.com/youtube-dl/
{ ~ } > brew install ffmpeg
{ ~ } > wget https://raw.github.com/rg3/youtube-dl/2012.02.27/youtube-dl
{ ~ } > chmod u+x youtube-dl
# Pick which video format you want to download.. (use any YT video link)
{ ~ } > ./youtube-dl -s -F http://www.youtube.com/watch?v=vT1KmTQ-1Os
@davidthewatson
davidthewatson / gist:2163806
Created March 22, 2012 20:34
d3py with numpy, pandas
import d3py
import numpy as np
import pandas
T = 10
df = pandas.DataFrame({
"time" : range(T),
"pressure": np.random.rand(T),
"temp" : np.random.rand(T)
})
print df
@davidthewatson
davidthewatson / git-merged.rb
Created March 19, 2012 23:17 — forked from jcromartie/git-merged.rb
Git command to list merged (or unmerged with -u) branches
#!/bin/ruby
show_unmerged = ARGV[0] == '-u'
branches = `git branch -r`.split("\n")
branches.each do |branch|
is_merged = `git branch --contains #{branch}` =~ /master/
puts branch if show_unmerged ^ is_merged
end