Skip to content

Instantly share code, notes, and snippets.

View sahib's full-sized avatar
🤘

Chris Pahl sahib

🤘
View GitHub Profile
@sahib
sahib / pre-commit
Last active August 29, 2015 14:05
Pre commit hook for rmlint - put in .git/hooks/pre-commit and chmod +x it.
#!/bin/sh
#
# Shamelessly stolen from:
# http://www.es.ele.tue.nl/sdf3/manuals/development/files/pre-commit
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
@sahib
sahib / problem.rst
Last active December 27, 2015 12:39
I haz problemz.

Folgendes Problem zu libmunin:

  • Ich hab eine Liste von Songs.
  • Um Aussagen über deren ähnlichkeit zu machen muss ich die untereinander vergleichen. Das ergibt für N Songs ((N - 1) ^ 2 / 2) Vergleiche. Für N=32k ne ganze Menge. (Abgeschätzte Zeit wären ca. 13h, also unakzeptabel.)

Es seien zwei variabel lange Listen mit variabel langen Tupeln darin: :

a = [(85, 0), (190, 2), (190, 6)]
b = [(85, 0), (190, 2, 0), (190, 2, 0), (190, 6)]

Die Listen sind stets sortiert, kleinste Werte zuerst. Es soll eine Distanzfunktion geschrieben werden die diese beiden Listen auf Ähnlichkeit untersucht. Diese Funktion soll eine Zahl zwischen 0.0 (volle ähnlichkeit) und 1.0 (volle divergenz) ergeben.

[Core]
Name = Cover
Module = movie
[Documentation]
Description = A cover plugin
Author = My very own name
Version = 0.1
Website = My very own website
@sahib
sahib / mpdlisten.c
Created September 26, 2013 18:05
Compile: gcc mpdsonglisten.c -o mpdsonglisten -lmpdclient -std=c99 Run: ./mpdsonglisten localhost 6600 <on_play_script> <on_stop_script> Example: ./mpdsong localhost 6600 'echo plays!' 'echo stopped!' It will call on_play_script once mpd starts playing, and on_stop_script once it pauses, stops or does something unknown. Error handling is done by…
/*
* Compile: gcc mpdsonglisten.c -o mpdsonglisten -lmpdclient -std=c99
* Run: ./mpdsonglisten localhost 6600 <on_play_script> <on_stop_script>
* Example: ./mpdsong localhost 6600 'echo plays!' 'echo stopped!'
*
* It will call on_play_script once mpd starts playing,
* and on_stop_script once it pauses, stops or does something unknown.
*
* Error handling is done by ignoring none-fatal erros and trying to reconnect if
* fatal errors happen.
@sahib
sahib / test
Created June 18, 2013 08:11
Test
Hello Workshop
@sahib
sahib / statusicon.py
Created June 8, 2013 10:37
Working version of a GtkStatusIcon drawn with Cairo.
#!/usr/bin/env python
# encoding: utf-8
from gi.repository import Gtk, Gdk, GLib, Pango, PangoCairo
from cairo import Context, ImageSurface, RadialGradient, FORMAT_ARGB32
from math import pi
def draw_center_text(ctx, width, height, text, font_size=15):
layout = PangoCairo.create_layout(ctx)
$ GDK_SYNCHRONIZE="1" gdb --args python swipe.py
(gdb) r
(gdb) bt
#0 0x00007ffff5b3beed in g_logv () from /usr/lib/libglib-2.0.so.0
#1 0x00007ffff5b3c0d2 in g_log () from /usr/lib/libglib-2.0.so.0
#2 0x00007ffff2f46e60 in ?? () from /usr/lib/libgdk-3.so.0
#3 0x00007ffff2f51801 in ?? () from /usr/lib/libgdk-3.so.0
#4 0x00007ffff29fd976 in _XError () from /usr/lib/libX11.so.6
#5 0x00007ffff29fabc1 in ?? () from /usr/lib/libX11.so.6
#6 0x00007ffff29fac05 in ?? () from /usr/lib/libX11.so.6
@sahib
sahib / left_right.py
Created May 7, 2013 20:28
Clutter Animation with two buttons. Reusable swipe() function!
import sys
from gi.repository import GLib, Gdk, Gtk, GtkClutter, Clutter
def _render_pixbuf(widget, width, height):
# Use an OffscreenWindow to render the widget
off_win = Gtk.OffscreenWindow()
off_win.add(widget)
off_win.set_size_request(width, height)
@sahib
sahib / clutter.py
Created May 4, 2013 19:56
Playing around with Python/Clutter/Gtk. Simple Swipe Effect.
from gi.repository import GLib, Gtk, GtkClutter, Clutter, Gdk, GdkPixbuf
import sys
from random import random
BROWSERS = 42
class ClutterBrowser(Gtk.ApplicationWindow):