Skip to content

Instantly share code, notes, and snippets.

@schoettl
schoettl / setter.java
Created September 29, 2012 15:25
A setter for views to set data models
public void setGameState(GameState gameState) {
if (gameState != this.gameState) {
if (this.gameState != null) {
// unregister listeners/observers
}
this.gameState = gameState;
if (gameState != null) {
// register listeners/observers
}
}
@schoettl
schoettl / UnixPasswordField.java
Last active October 11, 2015 16:18
UnixPasswordField -- A unix style password input
/*
* UnixPasswordField -- A unix style password input
* Copyright (C) 2012 Jakob Schöttl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@schoettl
schoettl / Main.hs
Last active November 7, 2015 05:17
Extract all hs-source-dirs from a cabal file
module Main (main) where
import System.Environment (getArgs)
import Data.Maybe (maybeToList)
import Data.List.Utils (uniq)
import Distribution.Verbosity (normal)
import Distribution.Package (Dependency)
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse (readPackageDescription)
@schoettl
schoettl / DocoptOptionsWrapper.java
Last active May 9, 2016 10:38
A wrapper object around the options Map returned by Docopt.parse(...)
/*
* Released under
* The MIT License (MIT)
* Copyright (c) 2016 Jakob Schöttl
*/
package edu.hm.cs.vadere.seating.traingen;
import java.util.List;
import java.util.Map;
@schoettl
schoettl / range-mapping.vim
Last active October 11, 2016 19:19
Vim mapping with range
function! ExportAndOpenHtml() range
execute a:firstline . ',' . a:lastline . 'TOhtml'
execute 'silent !xdg-open %'
quit
redraw!
endfunction
nnoremap <Leader>h :0,$call ExportAndOpenHtml()<CR>
vnoremap <Leader>h :call ExportAndOpenHtml()<CR>
#!/bin/bash
# utf82latex - Convert UTF-8 encoded input to ASCII encoded LaTeX
# warning:
# does not work if input contains double quotes (") or back slashes (\)
# usage:
# in Vim: :%!utf82latex
# in shell: xclip -o -selection c | utf82latex | xclip -selection c
# in shell: utf82latex <<EOF | xclip -selection c
@schoettl
schoettl / rewrite-after-timeout.hs
Last active January 23, 2017 16:01
Write stdin to a file and rewrite the file after a timeout
-- See http://jakob.keramik-schoettl.de/blog/
-- usage: rewrite-after-timeout SECONDS FILENAME
import Prelude
import System.IO
import System.Timeout
import System.Environment
import Data.Time
import Data.Maybe
import Control.Monad
@schoettl
schoettl / change-hosts-file.sh
Created August 14, 2017 17:59
Automatically change the /etc/hosts file depending on the network you are currently in
#!/bin/bash
# Change the hosts file /etc/hosts - must run as root.
# To be used with a cron job or systemd service to automatically
# adjust the hosts file depending on the network the computer is in.
printUsage() {
cat <<EOF
usage: $PROGNAME (-a | -n NETWORK) DOMAIN_NAME IP_ADDRESS
$PROGNAME -r DOMAIN_NAME
options:
@schoettl
schoettl / org2dot.hs
Created March 20, 2018 14:22
Transform Org mode document to DOT graphviz language
-- required packages: split orgmode-parse
import qualified Data.Text as T
import Data.OrgMode.Parse
import Data.OrgMode.Types (Document (..), Headline (..), Section (..), Properties (..))
import Data.Attoparsec.Text
import Data.Maybe
import qualified Data.HashMap.Lazy as M
import Data.List.Split
@schoettl
schoettl / switch-audio-output.sh
Created April 29, 2018 17:05
Switch current audio output device (or toggle between sinks) – This code is for PulseAudio. I use it in an Xmonad key binding.
#!/bin/bash
# Switch the current audio output device.
# Without options: Toggle between two sinks.
# This script works for PulseAudio; pactl must be installed.
printUsage() {
cat <<EOF
usage: $PROGNAME [options]
options: