Skip to content

Instantly share code, notes, and snippets.

@lomereiter
lomereiter / clem_info.vala
Created June 13, 2011 12:01
getting info from clementine for conky via dbus
/* to compile:
valac --pkg gio-2.0 clem_info.vala
example of usage:
clem_info '${artist} - ${title}; elapsed: ${elapsed}/${time}'
*/
[DBus (name = "org.freedesktop.MediaPlayer")]
interface Player : Object {
public abstract HashTable<string, Variant> GetMetadata() throws IOError;
@lomereiter
lomereiter / factorial.rb
Created July 31, 2011 16:35
fast factorial calculation in ruby
require 'numtheory' # gem install ruby-numtheory
def product(arr)
def rec_product(n, step, arr)
return arr[n] if step > n
newstep = step << 1
t = rec_product(n, newstep, arr) *
rec_product(n-step, newstep, arr)
return t
end
@lomereiter
lomereiter / priem_spbu.py
Created August 1, 2011 15:32
script for spbu applicants
# -*- coding: utf-8 -*-
from urllib2 import urlopen
import re
import time
class DegreeProgramInfo:
regexp = re.compile(
r"\d</td>\s*<td>\s*(\d+)</td>\s*(?:<td>[^<]*</td>\s*){5}<td>([^<]+)</td>",
re.MULTILINE | re.UNICODE)
def __init__(self, id, name, url, places):
@lomereiter
lomereiter / gist:1407085
Created November 29, 2011 23:13
flattening (C++11)
template <typename... T> struct type {};
struct A{}; struct B{}; struct C{}; struct D{}; struct E{}; struct F{};
struct G{}; struct H{}; struct I{}; struct J{}; struct K{}; struct L{};
struct M{}; struct N{}; struct O{}; struct P{};
typedef type<A, B, type<C, D>, type<E, F, type<G, H>, I, J>,
type<type<type<K, type<L>>, M>, N>, O, P> init;
typedef type<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> expected;
@lomereiter
lomereiter / make_vapi.py
Created December 30, 2011 19:44
libmusicbrainz4: converting cinterface.xml to .vapi file
#!/usr/bin/env python
import xml.etree.ElementTree
# in order for this script to work, manually do the following:
# 1) delete extraneous 'uppername="PUID"' at line 205 of cinterface.xml
# 2) delete '------------ ... ----' lines (there're 2 of them)
def un_camel(text): # slightly modified piece of code from StackOverflow.com
result, length = "", len(text)
for pos in range(length):
// It turns out that combination of std.conv.emplace and FFI::MemoryPointer.new
// can make our life much easier (at least, for structs).
// See example at https://gist.github.com/2337729
extern (C) void* malloc(size_t sz);
extern (C) void free(void *p);
class DefaultMemoryManagement {
mixin template memoryManagement() {}
}
@lomereiter
lomereiter / Makefile
Created April 8, 2012 14:55
howto: d & ruby ffi
test: test_c.o test_d.o
cc -shared -m32 test_c.o test_d.o -o test.so -lphobos2
test_c.o: test.c
gcc -c -m32 test.c -o test_c.o
test_d.o: test.d
dmd -c -m32 test.d -oftest_d.o
@lomereiter
lomereiter / Makefile
Created April 12, 2012 11:23
d & ruby: segfault
test: test_c.o test_d.o
gcc -m32 -g test_d.o test_c.o -o test.so -lphobos2 -lrt -shared -lpthread
test_c.o: test.c
gcc -c -g -m32 test.c -o test_c.o -fPIC
test_d.o: test.d
dmd -c -m32 -g test.d -oftest_d.o -fPIC
@lomereiter
lomereiter / cinterface.d
Created April 24, 2012 07:28
d compile-time binding generation
module cinterface;
import std.traits;
import std.string;
import std.conv;
import std.range;
import std.typetuple;
import std.algorithm;
import std.ascii;
@lomereiter
lomereiter / bgzfrange.d
Created April 25, 2012 11:17
BGZF block range in D
module bgzfrange;
import std.stream;
struct BgzfBlock {
// field types are as in the specification
// ushort ~ uint16_t, char ~ uint8_t, uint ~ uint32_t
public ushort bsize;
public char[] compressed_data = void;
public uint crc32;