Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / github_mirror.py
Last active May 27, 2024 06:00
Mirror all my github repositories and gists
#!/usr/bin/env python3
# See http://stackoverflow.com/questions/3581031/backup-mirror-github-repositories/13917251#13917251
# You can find the latest version of this script at
# https://gist.github.com/4319265
import os
import sys
import json
import urllib.request
import subprocess
@mgedmin
mgedmin / watchpos.py
Created December 17, 2012 18:16
Hack to monitor file position of an app that doesn't have any built-in progress indication
#!/usr/bin/python
"""
Usage: watchpos {filename|pid fd}
Watches the file pointer of an opened file on Linux. Use it to provide a
progress bar to a command that doesn't have one, assuming the program reads
this file from start to end without jumping around.
Copyright (c) 2011 Marius Gedminas <[email protected]>
@mgedmin
mgedmin / timeline.py
Last active October 10, 2019 12:34
Visualize a Zope trace.log with d3.js
#!/usr/bin/python3
"""
Show recent requests on a timeline
Parses a ZServer trace.log file. The format is documented at
https://pypi.python.org/pypi/zc.zservertracelog
"""
import json
import re
@mgedmin
mgedmin / pov-update-ztk-py3-status.sh
Last active October 23, 2019 15:34
Daily cron script that updates dynamic data at https://zope3.pov.lt/py3/
#!/bin/sh
# update dynamic files in /var/www/zope3.pov.lt/py3/
# /opt/ztk-py3-status/ is a checkout of https://github.com/mgedmin/ztk-py3-status
# /opt/ztk-py3-status/*.py require python3
# sponge requires moreutils
# convert requires imagemagick
# dot and neato require graphviz
cache_dir=/stuff/pypi-cache
@mgedmin
mgedmin / convert-zope-svn-to-git.rst
Last active December 13, 2015 16:59
Instructions for converting Zope SVN repositories to Git

Converting Zope SVN repositories to Git

This process has one critical flaw and you probably don't want to use it. git-svn is simpler.

You need:

  • svn-all-fast-export (from the Debian/Ubuntu package of the same name;
@mgedmin
mgedmin / helpful_advice.py
Last active December 13, 2015 17:58
Today's best Python code (from ZConfig/components/logger/tests/test_logger.py)
class CustomFormatter(logging.Formatter):
def formatException(self, ei):
"""Format and return the exception information as a string.
This adds helpful advice to the end of the traceback.
"""
import traceback
sio = StringIO.StringIO()
traceback.print_exception(ei[0], ei[1], ei[2], file=sio)
return sio.getvalue() + "... Don't panic!"
@mgedmin
mgedmin / strace_process_tree.py
Last active January 13, 2021 15:02
Tool to help me make sense out of `strace -f` output.
in/python
# -*- coding: UTF-8 -*-
"""
Usage:
strace-process-tree filename
Read strace -f output and produce a process tree.
Recommended strace options for best results:

zope-test-janitor

This is a script that analyzes Zope test summary emails and produces an HTML report.

Mutt users: pipe (|) the email to zope-test-janitor, enjoy output in your browser.

screenshot.png

@mgedmin
mgedmin / timeit-from-pdb-hack.md
Last active September 27, 2019 16:32
using timeit.timeit from pdb with access to a subset of local vars

= Problem =

timeit.timeit() doesn't let you pass local vars to the code to be timed.

= Solution =

(pdb) !import sys, timeit
(Pdb) !dv = (lambda sys=sys: (lambda **kw: setattr(sys.modules['__main__'], 'VARS', kw)))()
(Pdb) !tt = lambda s, sys=sys: sys.stdout.write('%.3g ms\n' % timeit.timeit(s, 'import sys; self = sys.modules["__main__"].SELF', number=10)/10.*1000)
#!/usr/bin/python3
import json
import os
import subprocess
import urllib.request
import sys
from operator import itemgetter