Skip to content

Instantly share code, notes, and snippets.

View JonasGroeger's full-sized avatar
Working from home

Jonas Gröger JonasGroeger

Working from home
View GitHub Profile
JonasGroeger / logObjectAsJson with XStrea
Created May 29, 2012 21:09
How to print the field name and value of an arbitrary object.
public static void logObjectAsJSON(String tag, Object o) {
// In order for this to work you need the XStream library located at
XStream x = new XStream(new Sun14ReflectionProvider(new FieldDictionary(new ImmutableFieldKeySorter())), new JsonHierarchicalStreamDriver());
Log.d(tag, x.toXML(o));
JonasGroeger / HTTPClient POST
Created May 31, 2012 20:38
HTTPPost request using the apache http client
// We are going to post to this url.
HttpPost post = new HttpPost("");
// We are going to use the apache httpclient
HttpClient client = new DefaultHttpClient();
// The request is going to have some parameters.
final HttpParams params = new BasicHttpParams();
// Set the redirecting parameter in params to false. This will make sure we dont follow redirects like 302 and the result we get from the server later is the actual one and not some follow up resource.
JonasGroeger / gist:2942552
Created June 16, 2012 21:32
Remove specific pages from pdf
// Use in.pdf, extract pages 1-5, 10-19 and 26-end and output in out.pdf
pdftk in.pdf cat 1-5 10-19 26-end output out.pdf
JonasGroeger / cantor.hs
Created June 22, 2012 16:31
Cantorsche Paarungsfunktion
module Cantor (
JonasGroeger /
Created September 7, 2012 05:17
Django relative directories in
# coding=utf-8
# Django 1.4.1 settings for <project-name> project.
import os
PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..'))
DATABASE = os.path.join(PROJECT_DIR, 'db', 'db.sqlite3')
'default': {
JonasGroeger / sumatra.desktop
Created February 13, 2013 12:28
.desktop file for launching SumatraPDF with wine
[Desktop Entry]
Exec=env WINEPREFIX="/home/jonas/.wine" wine start /ProgIDOpen SumatraPDF %f
JonasGroeger / pdfxchange.desktop
Created February 13, 2013 12:29
.desktop file for launching PDF-XChange Viewer with wine
[Desktop Entry]
Name=PDF-XChange Viewer
Exec=env WINEPREFIX="/home/jonas/.wine" wine start /ProgIDOpen PDF-XChangeViewer.1 %f
JonasGroeger /
Last active December 13, 2015 23:59
A little script to backup your IOU Potts. Either pass the urls from command line or embed them in code at lines 45+. I made an example there. Works for and
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'Jonas Gröger'
import argparse
import urllib.request
from urllib.error import URLError
from time import strftime
import os
JonasGroeger /
Last active December 16, 2015 15:50
Tarjan's strongly connected components algorithm for python3
# From
# By
from itertools import chain
from collections import defaultdict
class Graph(object):
def __init__(self, edges, vertices=()):
edges = list(list(x) for x in edges)
self.edges = edges
JonasGroeger / build.gradle
Last active January 23, 2024 07:55
Gradle: Read git commit hash.
def getCheckedOutGitCommitHash() {
def gitFolder = "$projectDir/.git/"
def takeFromHash = 12
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd