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
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 http://xstream.codehaus.org/
XStream x = new XStream(new Sun14ReflectionProvider(new FieldDictionary(new ImmutableFieldKeySorter())), new JsonHierarchicalStreamDriver());
Log.d(tag, x.toXML(o));
}
@JonasGroeger
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("http://example.com/login");
// 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
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
JonasGroeger / cantor.hs
Created June 22, 2012 16:31
Cantorsche Paarungsfunktion
module Cantor (
c,
cx,
cy,
d,
h,
c_umkehr,
findmax)
where
@JonasGroeger
JonasGroeger / settings.py
Created September 7, 2012 05:17
Django relative directories in settings.py
# 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')
DATABASES = {
'default': {
@JonasGroeger
JonasGroeger / sumatra.desktop
Created February 13, 2013 12:28
.desktop file for launching SumatraPDF with wine
[Desktop Entry]
Type=Application
Name=SumatraPDF
MimeType=application/pdf;
Exec=env WINEPREFIX="/home/jonas/.wine" wine start /ProgIDOpen SumatraPDF %f
NoDisplay=true
StartupNotify=true
Icon=518F_SumatraPDF.0
@JonasGroeger
JonasGroeger / pdfxchange.desktop
Created February 13, 2013 12:29
.desktop file for launching PDF-XChange Viewer with wine
[Desktop Entry]
Type=Application
Name=PDF-XChange Viewer
MimeType=application/pdf;
Exec=env WINEPREFIX="/home/jonas/.wine" wine start /ProgIDOpen PDF-XChangeViewer.1 %f
NoDisplay=true
StartupNotify=true
Icon=C055_PDFXCview.0
@JonasGroeger
JonasGroeger / doBackup.py
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 iou.de and iou.ch
#!/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
JonasGroeger / tarjan.py
Last active December 16, 2015 15:50
Tarjan's strongly connected components algorithm for python3
# From http://stackoverflow.com/a/6575693/488265
# By http://stackoverflow.com/users/577088/senderle
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
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