Skip to content

Instantly share code, notes, and snippets.

View RavuAlHemio's full-sized avatar

Ondřej Hošek RavuAlHemio

View GitHub Profile
@RavuAlHemio
RavuAlHemio / deriff.py
Created May 9, 2014 07:46
dissect a RIFF file and extract all WAVE components into .wav files
import io
import struct
container_chunks = {b"RIFF", b"LIST"}
class RiffChunk:
def __init__(self, tag, data):
self.tag = tag
self.data = data
@RavuAlHemio
RavuAlHemio / cbencode.cpp
Last active August 29, 2015 14:02
HTML and URL encoding outgoing messages for the vBulletin chatbox, for Qt.
#include <iomanip>
#include <iostream>
#include <QByteArray>
#include <QSet>
#include <QString>
#include <QTextCodec>
static const QSet<QChar> urlSafeCharacters {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
@RavuAlHemio
RavuAlHemio / mbdbpy3.py
Created June 22, 2014 21:49
mbdb file decoder, ported to Python 3, no mbdx file needed
#!/usr/bin/env python3
import sys
import hashlib
def getint(data, offset, intsize):
"""Retrieve an integer (big-endian) and new offset from the current offset"""
value = 0
while intsize > 0:
value = (value << 8) | data[offset]
offset += 1
@RavuAlHemio
RavuAlHemio / KeysToKeystore.java
Last active August 29, 2015 14:05
Converts a private key (generated by OpenSSL's "genpkey") and a corresponding certificate chain (X.509 PEM) to a Java keystore.
// Released into the public domain.
// http://creativecommons.org/publicdomain/zero/1.0/
// converts a PKCS#8 PEM private key (as generated by OpenSSL's "genpkey")
// and a corresponding certificate chain (X.509 PEM) to a Java keystore.
// why can't keytool do this natively?
// warning: requires JRE 8 because it uses java.util.Base64
import java.io.BufferedInputStream;
@RavuAlHemio
RavuAlHemio / vbcbbot-client.ini
Created September 24, 2014 22:31
sample minimal HTTP-interface-only configuration for vbcbbot
[forum]
url = http://www.informatik-forum.at/
username = bowle12_forum
password = correct horse battery staple
custom smileys =
:paulbierporn: http://i.imgur.com/cd4laTo.png
:pokeinlove: http://i.imgur.com/wScND5F.gif
:gn8db: http://i.imgur.com/Mh2d0vJ.gif
:wtfdb: http://i.imgur.com/4HhumHP.gif
:lauschereek2: http://i.imgur.com/klExUVX.gif
@RavuAlHemio
RavuAlHemio / ninepatch.py
Created October 19, 2014 15:42
Renders a nine-patch image. (The border sizes are supplied numerically, not as pixels in the image's border as on Android.)
#!/usr/bin/env python3
#
# Renders a scaled nine-patch image.
#
# Released into the public domain.
# http://creativecommons.org/publicdomain/zero/1.0/
#
from PIL import Image
class NinePatch:
@RavuAlHemio
RavuAlHemio / isprime.hs
Last active August 29, 2015 14:08
tightPrimeEmbedding
import Data.List (find)
import Data.Maybe (fromJust)
isPrime :: Integer -> Bool
isPrime n
-- negative numbers, 0 and 1 are not prime
| n < 2 = False
-- 2 is prime, all other numbers divisible by 2 aren't
| n == 2 = True
| n `mod` 2 == 0 = False
package ds3;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
@RavuAlHemio
RavuAlHemio / fd redirection.md
Last active August 29, 2015 14:12
Redirection von Dateideskriptoren

Dateideskriptoren

Unix-Kernels speichern für jeden Prozess eine Liste von offenen Dateien. Diese Liste können die Prozesse nicht direkt einsehen; sie verwenden stattdessen Dateideskriptoren (file descriptors oder FDs) – ints, die einen Index in diese Tabelle darstellen.

Es gibt konventionell drei „besondere“ FDs: stdin (0), stdout (1) und stderr (2). Prinzipiell unterscheiden sie sich nicht von anderen FDs, doch ihre zweckmäßige Verwendung wird „stark empfohlen“, und die meisten Programmierumgebungen erleichtern das (z.B. schreibt Cs printf auf stdout, und Java bietet ein „fertig geöffnetes“ stdout über java.lang.System.out an).

Prozessstart

Unter Unix werden Prozesse nicht gestartet, sondern „geklont und ersetzt“. Der Systemaufruf fork sorgt dafür, dass ein Klon des laufenden Prozesses erstellt wird und an derselben Stelle wie der ursprüngliche weiterläuft. Hierbei werden offene Dateideskriptoren übernommen. Die Ersetzung erfolgt durch einen exec-Systemaufruf; unter Linux etwa

@RavuAlHemio
RavuAlHemio / brace-policy.c
Created June 25, 2015 20:38
Brace policy
int main()
{
return 0;
}