Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / gist:d6d271f4ee6ae82d9a86
Created March 5, 2015 07:32
Jenkins groovy script to print scheduling rules for all the jobs
import hudson.triggers.*;
for (item in Jenkins.instance.getItems(Project)) {
println("--- Scheduling for " + item.name + " ---")
def trigger = item.triggers.get(Jenkins.instance.getDescriptor(TimerTrigger.class));
if (trigger) {
println trigger.spec;
}
}
@mgedmin
mgedmin / multiping.py
Last active May 20, 2020 17:05
ping a host once a second and visualize the results
#!/usr/bin/python
"""
Multiping version ${version} by Marius Gedminas <marius@gedmin.as>
Licence: GPL v2 or later
Syntax: multiping hostname
Pings a host every second and displays the results in an ncurses window.
Legend:
# ping OK
@mgedmin
mgedmin / interfaces
Created May 11, 2020 18:23
/etc/network/interfaces with static IPv6
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address X.X.X.X
pointopoint X.X.X.Y
netmask 255.255.255.255
gateway X.X.X.Y
dns-nameservers A.B.C.D A.B.C.E A.B.C.F
@mgedmin
mgedmin / rebuild-vim.sh
Last active December 31, 2019 13:56
Script I use to build the latest Vim on Ubuntu
#!/bin/sh
set -e
COMPILED_BY="Marius Gedminas <marius@gedmin.as>"
FEATURES=
FEATURES="$FEATURES --with-features=huge" # yum, features
FEATURES="$FEATURES --enable-multibyte" # vim is *crippled* without this!
# (BTW 'big' implies this)
FEATURES="$FEATURES --enable-pythoninterp" # most of my plugins use this
FEATURES="$FEATURES --enable-rubyinterp" # Command-T wants this
@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 / askpass.py
Last active October 21, 2019 13:32
[ansible] vault_password_file = askpass.py
#!/usr/bin/env python
import sys
import getpass
import argparse
try:
# Suppress PyGI warning (LP: #1510392)
import gi
gi.require_version('GnomeKeyring', '1.0')
except (ImportError, ValueError):
@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 / MAGIC_BROWSER.md
Created October 8, 2019 15:13
How to make your desktop open different URLs in different browsers, depending on the URL

How to make your desktop open different URLs in different browsers, depending on the URL

  • vim ~/bin/open-the-right-browser

    #!/bin/sh
    case "$1" in
      *git.example.com*) browser=firefox;;
      *) browser=chromium-browser;;
    esac
    

exec $browser "$@"

@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)
@mgedmin
mgedmin / compare_reportgen_output.py
Created September 6, 2019 06:05
A script we use to compare a bunch of PDFs pairwise
#!/usr/bin/env python
"""
Compare PDF reports pixel-wise.
When reportgen functional tests fail, you may want to see visually what
exactly changed. To do that:
(1) set your changes aside, e.g.
git stash