Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / buildout-tags.sh
Last active December 14, 2015 21:38
Create ctags for the current virtualend or buildout
#!/bin/bash
# Build a vim tags file for all the Python packages in the buildout path
# Assumes . is the directory with a buildout.cfg
# Note: there is no one true buildout path -- every part has its own. So
# we look for a python interpreter in bin/python (or bin/py) and use its path.
# If that fails, we try to find a bin/test script and scrape the path from it.
# Should also work with virtualenv (just run it somewhere with a bin/python)
# Published at https://gist.github.com/mgedmin/5152189
progname=${0##*/}
@mgedmin
mgedmin / plot-test-failures-with-gnuplot.md
Last active December 15, 2015 05:59
Hack to plot number of failing tests while working

I was trying to see how hard it would be to port Paste to Python 3.

Paste uses nose. nosetests prints something like

FAILED (errors=90, failures=5)                                                   

at the end of the test run. I wanted to plot the number of failures to see how I was progressing:

./run32

vi ...

@mgedmin
mgedmin / virtual-bootstrap.sh
Created March 22, 2013 10:30
Shell script to bootstrap a package that uses zc.buildout, wrapped in a virtualenv for site isolation
#!/bin/bash
if [ "${0##*/}" == "virtual-bootstrap-py3" ]; then
python=python3.3
else
python=python2.7
fi
if [ -n "$(netstat -tnl | grep ':3128 ')" ]; then
export http_proxy=http://localhost:3128
echo "Using a local Squid proxy."
fi
@mgedmin
mgedmin / .gitignore
Last active December 17, 2015 17:19
Exploring a data loss failure with OOBTrees on Python 3.3
.tox/
dist/
*.egg-info/
*.fs
*.fs.index
*.fs.lock
*.fs.tmp
@mgedmin
mgedmin / gist:5669877
Created May 29, 2013 12:20
tcp dump of a failing bin/buildout
mg@platonas: ~/tmp/vagrantbox $ vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)
* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Wed May 29 08:18:42 2013 from 10.0.2.2
vagrant@precise64:~$ sudo ngrep . tcp and port 80
interface: eth0 (10.0.2.0/255.255.255.0)
filter: (ip or ip6) and ( tcp and port 80 )
match: .
@mgedmin
mgedmin / diff
Last active December 19, 2015 12:48
See linux-thinkpad@ thread http://mail.matrix.de/pipermail/linux-thinkpad/2013-July/051476.html and the previous thread where lspci -vvv output was requested: http://mail.matrix.de/pipermail/linux-thinkpad/2013-June/051427.html
--- x220-high-temperature.lspci.txt 2013-07-09 15:09:49.935830871 +0200
+++ x220-normal-temperature.lspci.txt 2013-07-10 12:43:18.789197038 +0200
@@ -23,19 +23,20 @@
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 0
- Interrupt: pin A routed to IRQ 47
+ Interrupt: pin A routed to IRQ 42
Region 0: Memory at f2525000 (64-bit, non-prefetchable) [size=16]
Capabilities: <access denied>
@mgedmin
mgedmin / floats_in_doctests.py
Last active December 19, 2015 18:29
A solution for dealing with str(some_float_value) differences in doctests, when you want your codebase to support both Python 2.6 and 2.7.
import re
from zope.testing.renormalizing import RENormalizing
FLOAT_CHECKER = RENormalizing([
(re.compile(r'-?\d+[.]\d+'),
lambda m: '%.6g' % float(m.group(0))),
])
... DocTestSuite(..., checker=FLOAT_CHECKER) ...
@mgedmin
mgedmin / conf.py.rst
Created July 22, 2013 10:37
HOWTO add "Show on GitHub" and "Edit on GitHub" links to the Sphinx sidebar

Edit on GitHub links for Sphinx

Create _ext/ and _templates/ subdirectories.

Move edit_on_github.py into the _ext/ subdirectory.

Move sourcelink.html into the _templates/ subdirectory.

Add the following after the import sys, os line

@mgedmin
mgedmin / pov-ppa-copy-packages.py
Last active September 5, 2019 15:59
Automate PPA package copies.
#!/usr/bin/python
"""Copy published precise PPA packages to lucid.
We build a few packages containing scripts (architecture: all), upload them to
the PPA targeting the current Ubuntu LTS (precise). But we also want them to
be available for the previous LTS (lucid). This script automates the copying
process I used to do manually over the web.
"""
import optparse
@mgedmin
mgedmin / pipeline.py
Created September 17, 2013 12:20
pipeline() helper for chaining subprocess.Popen() instances conveniently
import subprocess
def pipeline(*commands):
"""Chain several commands into a pipeline.
E.g. to get the equivalent of
$ zcat foo | grep bar | less