Skip to content

Instantly share code, notes, and snippets.

View DazWorrall's full-sized avatar

Darren Worrall DazWorrall

  • UK
  • 01:02 (UTC +01:00)
View GitHub Profile
@DazWorrall
DazWorrall / listener.coffee
Created December 18, 2011 17:39
A hubot http listening server
# Inspired by http://tomb.io/posts/hubot-ci-and-deploying/
# Its probably tightly bound to the xmpp adapter, and incorrect
# in loads of ways, but its a start.
# POST a json document to /message containing 'room' (the JID of the room
# you want to talk to) and 'message' (the message you want to send)
http = require "http"
Robot = require '../src/robot'
@DazWorrall
DazWorrall / Output
Created February 9, 2012 13:06
Testing file upload handling in Flask
in upload handler
in file close
..
----------------------------------------------------------------------
Ran 2 tests in 0.021s
OK
@DazWorrall
DazWorrall / app.py
Created July 26, 2012 07:54
Flask maintenance mode
from flask import Flask, redirect, url_for, request
app = Flask(__name__)
is_maintenance_mode = True
# Always throw a 503 during maintenance: http://is.gd/DksGDm
@app.before_request
def check_for_maintenance():
@DazWorrall
DazWorrall / postactivate
Created September 6, 2012 09:43
Automatically switch to a directory with a matching name when entering a virtualenv
#!/bin/bash
# This hook is run after every virtualenv is activated.
venv=`basename "$VIRTUAL_ENV"`
if [ -d "$HOME/src/$venv" ]; then
cd "$HOME/src/$venv"
fi
@DazWorrall
DazWorrall / myflask.py
Created September 24, 2012 08:55
Subclass the Flask exception handler
'''
Original here: https://github.com/mitsuhiko/flask/blob/master/flask/app.py#L1295
'''
from flask import Flask
class MyFlask(Flask):
def log_exception(self, exc_info):
"""
Overriden to provide the full url (including scheme, hostname and query string)
@DazWorrall
DazWorrall / new_stacktrace.log
Created September 25, 2012 15:58
Taking a screenshot using selenium
Connecting
Traceback (most recent call last):
File "screenshot.py", line 16, in <module>
desired_capabilities=desired_capabilities,
File "/Users/daz/.virtualenvs/1a5c5f7263517393/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 63, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Users/daz/.virtualenvs/1a5c5f7263517393/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 105, in start_session
'desiredCapabilities': desired_capabilities,
File "/Users/daz/.virtualenvs/1a5c5f7263517393/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in execute
self.error_handler.check_response(response)
@DazWorrall
DazWorrall / shell.out
Created October 1, 2012 10:35
Raven error when client disconnects on async server
$ pip install flask blinker raven gunicorn gevent
...
$ gunicorn -k gevent test:app
2012-10-01 11:16:57 [62111] [INFO] Starting gunicorn 0.14.6
2012-10-01 11:16:57 [62111] [INFO] Listening at: http://127.0.0.1:8000 (62111)
2012-10-01 11:16:57 [62111] [INFO] Using worker: gevent
2012-10-01 11:16:57 [62112] [INFO] Booting worker with pid: 62112
2012-10-01 11:26:00 [62292] [ERROR] Error handling request
Traceback (most recent call last):
File "/Users/daz/.virtualenvs/b99e1a9fba3d9901/lib/python2.7/site-packages/gunicorn/workers/async.py", line 44, in handle
@DazWorrall
DazWorrall / brew doctor.out
Created November 15, 2012 11:02
brew install bitlbee
$ brew doctor
Your system is raring to brew.
@DazWorrall
DazWorrall / homebrew.mxcl.bitlbee.plist
Created November 15, 2012 14:12
Bitlbee launchd script
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC
"-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>mac.bitlbee</string>
<key>ProgramArguments</key>
<array>
@DazWorrall
DazWorrall / flick.py
Created November 26, 2012 13:59
Find a random image on flickr
#!/usr/bin/env python
'''
$ pip install flickrapi
....
$ FLICKR_API_KEY=mykey ./flick.py tag1[,tag2,tag3...]
'''
# http://www.flickr.com/services/api/flickr.photos.search.html
import flickrapi