Skip to content

Instantly share code, notes, and snippets.

@jerrykan
jerrykan / dict_diff.py
Last active December 14, 2015 07:59
Given two dicts return another two dicts that contain only the differences between the original dicts
import unittest
def dict_diff(a, b):
if a == b:
return ({}, {})
diff = ({}, {})
keys = set(a.keys() + b.keys())
for k in keys:
@jerrykan
jerrykan / test_exception.py
Created March 11, 2013 03:07
Test exceptions are raised and the exception message is correct.
import unittest
def raise_exception(yup=True):
if yup:
raise ValueError('Yup, exception raised.')
class ExceptionMessageTestCase(unittest.TestCase):
def assertRaisesMessage(self, exception, msg, func, *args, **kwargs):
@jerrykan
jerrykan / liveserver.py
Created March 15, 2013 07:20
A basic wsgi http server to help with running selenium test cases
import multiprocessing
import socket
import time
import unittest
from wsgiref.simple_server import make_server, WSGIRequestHandler
class QuietHandler(WSGIRequestHandler):
def log_request(*args, **kwargs):
pass
#!/bin/bash
#
# Loosely based on the manual steps outlined at:
# https://kb.berkeley.edu/page.php?id=27401
# and:
# http://hodza.net/2011/06/15/howto-install-tsm-backup-client-in-debian-squeeze-ubuntu-64bit/
#
# This script assumes it is being run on a Debian host that has the alien
# package installed.
#
@jerrykan
jerrykan / git-remote-hg
Created September 23, 2013 03:19
A wrapper script to invoke git-remote-hg on Debian. Debian includes the Mercurial helper script in the git package but it is not placed in the $PATH by default and does not have execute permissions. This short script is a work-around for both of this issues.
#!/bin/sh
#
# Create this shell script in:
#
# /usr/local/bin/git-remote-hg
#
# Set the correct file permissions on the script:
#
# chmod 755 /usr/local/bin/git-remote-hg
#
@jerrykan
jerrykan / activate
Last active December 31, 2015 21:49
Simple wrapper around virtualenv activate to set/unset environment variables
# Wrapper around virtualenv activate to set/unset environment variables
#
# Update the location of the virtualenv (VENV_DIR) and the environment variables
# to be set at the end of the script. Then use this script to init the
# virtualenv instead of the virtualenv version:
#
# $ source activate
#
# Virtualenv location
---- Attempting to restart gogs ----
==> /var/log/gogs/gogs.log <==
2016/08/02 15:14:46 [I] Log Mode: File(Trace)
2016/08/02 15:14:46 [I] Cache Service Enabled
2016/08/02 15:14:46 [I] Session Service Enabled
2016/08/02 15:14:46 [I] Git Version: 2.1.4
==> /var/log/gogs/xorm.log <==
[xorm] [info] 2016/08/02 15:14:46.405516 [sql] SELECT tablename FROM pg_tables WHERE tablename = $1 [args] [version]
[xorm] [info] 2016/08/02 15:14:46.417816 [sql]SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = $1 AND column_name = $2[version id]
@jerrykan
jerrykan / sqlite3.php
Created December 28, 2011 03:33
sqlite3 driver for roundcube password plugin
<?php
/**
* sqlite3 Password Driver
*
* Driver for passwords stored in sqlite3 database
*
* @version 0.8
* @author John Kristensen <john@jerrykan.com>
*
@jerrykan
jerrykan / .travis.yml
Created March 17, 2015 00:45
.travis.yml file for roundup
language: python
python:
- "2.6"
- "2.7"
before_install:
# workaround mysql bug: http://bugs.mysql.com/bug.php?id=74901
# needed for test_mysql.mysqlDBTest.testFilteringSpecialChars
- sudo sed -i 's/utf8_unicode_ci/utf8_general_ci/' /etc/mysql/my.cnf
- sudo restart mysql
@jerrykan
jerrykan / git-diff-flake8.py
Created September 4, 2015 08:05
A very simplistic script to check for flake8 errors in the lines of a diff produced from `git diff`
#!/usr/bin/env python
"""
A very simplistic script to check for flake8 errors in the lines of a diff
produced from `git diff`. This is useful if you have files with lots of flake8
errors, but you only want to know about the errors in the lines you have
altered.
"""
import sys
import subprocess