Skip to content

Instantly share code, notes, and snippets.

@hjwp
hjwp / selenium_phantomjs_bug_current_url.py
Last active December 26, 2015 21:29
selenium phantomjs current_url bug minimal repro
from selenium import webdriver
import sys
if 'phantom' in sys.argv:
browser = webdriver.PhantomJS()
else:
browser = webdriver.Firefox()
browser.implicitly_wait(3)
from selenium import webdriver
import sys
if 'phantom' in sys.argv:
browser = webdriver.PhantomJS()
else:
browser = webdriver.Firefox()
browser.implicitly_wait(3)
@hjwp
hjwp / phantomjs-qunit-runner.js
Last active December 28, 2015 14:39
(yet another) phantomjs runner for qunit tests. This one produces text output that looks more like the web page.
var system = require('system');
if (!system.args[1]){
console.log('Pass path to test file as second arg');
phantom.exit();
}
var path = system.args[1];
if (path.indexOf('/') !== 0) {
path = system.env.PWD + '/' + path;
@hjwp
hjwp / get_wordcount_history_from_git.py
Created November 19, 2013 09:23
Script to go back through every single git commit and extract the current wordcount, to make a pretty graph
#!/usr/bin/env python3
from collections import namedtuple
import csv
from datetime import datetime
import os
import re
import subprocess
Commit = namedtuple('Commit', ['hash', 'subject', 'date'])
WordCount = namedtuple('WordCount', ['filename', 'lines', 'words'])
@hjwp
hjwp / test_logging.py
Created January 19, 2014 18:33
test to get django's logging set up
import logging
import sys
from unittest.mock import patch # reqs. python 3. change to from mock if p2.
from django.conf.urls import url
from django.http import HttpResponse
from django.test import TestCase
from .urls import urlpatterns
## test assumes a bare django project created called "myproj"
@hjwp
hjwp / readme.md
Created March 12, 2014 10:39
Minimal repro of LiveServerTestCase / Selenium / Windows bug

This Gist is just a minimal repro of a bug (I think) in Django's LiveServerTestCase.

Once a site has some static files (eg CSS), then clicking on a link produces an ugly uncaught exception from the LiveServer thread, like this:

Exception happened during processing of request from ('127.0.0.1', 1925)
Traceback (most recent call last):
  File "c:\Python33\lib\site-packages\django\test\testcases.py", line 1035, in _handle_request_noblock
    self.process_request(request, client_address)
  File "c:\Python33\lib\socketserver.py", line 332, in process_request
@hjwp
hjwp / tdd-webdev-draft-v1.1.diff
Created April 22, 2014 08:44
updates for python 3.4 and rewrite chap. 19
diff --git a/chapter_01.asciidoc b/chapter_01.asciidoc
index bee486f..f46cd90 100644
--- a/chapter_01.asciidoc
+++ b/chapter_01.asciidoc
@@ -265,25 +265,24 @@ Next we can add the rest of the contents of the current folder, `.`:
----
$ *git add .*
$ *git status*
-# On branch master
-#
@hjwp
hjwp / gist:455a77e21a3710c1b958
Last active August 29, 2015 14:01
"Easily" run all the tests in a particular file in Django <1.6
grep "class.\+Test" appname/tests/test_file.py | awk '{print $2;}' | awk -F"(" '{print "appname."$1}' | xargs python manage.py test
@hjwp
hjwp / Dockerfile
Created August 1, 2014 11:53
Building a postgres docker image...
FROM ubuntu:trusty
MAINTAINER [email protected]
# Add the PostgreSQL PGP key to verify their Debian packages.
# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# Add PostgreSQL's repository. It contains the most recent stable release
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main 9.4" > /etc/apt/sources.list.d/pgdg.list
@hjwp
hjwp / family.py
Created August 13, 2014 18:22
example of testing super calls
x = None
class Parent:
def foo(self):
return 'parent'
class Child(Parent):
def foo(self):
if x:
return x