Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / rst-vim.md
Last active March 19, 2021 09:06
ReStructuredText + vim = ?

A list of interesting GH repos:

@mgedmin
mgedmin / group-traceback-emails.py
Created November 19, 2014 08:42
procmail filter to group emails by traceback
#!/usr/bin/python
"""
Parse email messages with Python tracebacks, add email headers to group them.
Usage with procmail:
# Traceback emails!
:0 fw
* ^From: [email protected]
* ^TO_.*[email protected]
style "menu_item"
{
xthickness = 2
ythickness = 4
# HACK: Gtk doesn't actually read this value
# while rendering the menu items, but Libreoffice
# does; setting this value equal to the one in
# fg[PRELIGHT] ensures a code path in the LO theming code
# that falls back to a dark text color for menu item text
@mgedmin
mgedmin / gist:3a01f7ac2f16d178d674
Last active August 29, 2015 14:08
Debug session of the overlay-scrollbars bug with Gtk+ 3.14
<mgedmin> I'm seeing very weird segfaults in glib
in g_closure_invoke(), to be precise
this is on ubuntu gnome 14.10 with their gnome3-staging ppa enabled, so who knows what got broken where
but basically all the apps are segfaulting left and right when widgets lose focus
the stack trace is this: https://gist.github.com/0c80f6e81d9dfc4a4fd7
I have a core dump and I can poke around it with gdb
and gdb tells me closure->marshal is 0x7fd4ba283040 <g_cclosure_marshal_VOID__BOOLEAN>
and real_closure->meta_marshal is 0x7fd4ba27fb10 <g_type_class_meta_marshal>
the segfault is here: https://github.com/GNOME/glib/blob/glib-2-42/gobject/gclosure.c#L768
it's invoking a local variable 'marshal' which is "optimized out" in the stack trace's locals
@mgedmin
mgedmin / gist:6c8cf74559b33f14c200
Last active August 29, 2015 14:08
Valgrind session of gnome-calculator crashing due to the overlay-scrollbars bug with GTK+ 3.14
mg@platonas: ~/src/apt-sources/glib2.0-2.42.0 $ valgrind gnome-calculator
==9270== Memcheck, a memory error detector
==9270== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==9270== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==9270== Command: gnome-calculator
==9270==
==9270== Conditional jump or move depends on uninitialised value(s)
==9270== at 0x7871324: composite_traps (cairo-xlib-render-compositor.c:1882)
==9270== by 0x78591AE: composite_traps (cairo-traps-compositor.c:1098)
==9270== by 0x78591AE: composite_mask_clip (cairo-traps-compositor.c:2029)
@mgedmin
mgedmin / gist:a8d9006166e301cee534
Created September 11, 2014 14:41
Zope 2 is wonderful
# This is what I need to do if I want to import a .zexp from Zope 2.12 because there's apparently some object in the ZODB that got removed in 2.11 days
import mock
sys.modules['Products.PluginIndexes.TextIndex'] = mock.Mock()
sys.modules['Products.PluginIndexes.TextIndex.Splitter'] = mock.Mock()
sys.modules['Products.PluginIndexes.TextIndex.Splitter.ZopeSplitter'] = mock.Mock()
from persistent import Persistent
sys.modules['Products.PluginIndexes.TextIndex.Splitter.ZopeSplitter'].ZopeSplitter = type('ZopeSplitter', (Persistent,), {'__module__': 'Products.PluginIndexes.TextIndex.Splitter.ZopeSplitter'})
@mgedmin
mgedmin / gist:0cd9e0ab5cb51d833289
Created September 8, 2014 14:57
Using g_application_add_main_option_entries() with PyGObject
from gi.repository import GLib, Gtk
def make_option(long_name, short_name=None, flags=0, arg=GLib.OptionArg.NONE,
arg_data=None, description=None, arg_description=None):
# surely something like this should exist inside PyGObject itself?!
option = GLib.OptionEntry()
option.long_name = long_name.lstrip('-')
option.short_name = 0 if not short_name else short_name.lstrip('-')
option.flags = flags
option.arg = arg
@mgedmin
mgedmin / which-bootstrap.sh
Created April 7, 2014 12:13
zc.buildout's bootstrap.py changes all the time yet it doesn't have an embedded version number. It's also copied a lot into the source trees of other projects.
#!/bin/sh
filename=${1:-bootstrap.py}
test -f "$filename" || {
echo "there is no $filename here"
exit 1
}
checksum=$(sha1sum "$filename")
case "$checksum" in
0b63906b1c5d2eccbc9f727b0c1374c7c29f06a2*)
echo "you've got the obsolete v1.x bootstrap.py"
@mgedmin
mgedmin / transset.sh
Created April 2, 2014 17:37
Fake transset that works in GNOME
#!/bin/bash
echo "Using ~/bin/transset instead of the broken /usr/bin/transset"
echo "See https://bugs.freedesktop.org/show_bug.cgi?id=76958"
opacity=${1:-0.75}
scaled=$(echo "$opacity*4294967295"|bc)
hex=$(printf "0x%x" ${scaled%.*})
echo "Setting opacity to $opacity"
xprop -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $hex
@mgedmin
mgedmin / buildout-grep.sh
Last active August 29, 2015 13:57
Grep for a string in all the Python packages in the buildout/virtualenv path
#!/bin/bash
# Grep for a string in 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)
# Based on buildout-tags, which lives at https://gist.github.com/mgedmin/5152189
progname=${0##*/}