Skip to content

Instantly share code, notes, and snippets.

View markuswustenberg's full-sized avatar

Markus Wüstenberg markuswustenberg

View GitHub Profile
public static String humanReadableByteCount(long bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit) return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
#!/bin/bash
sudo socat tcp-l:54321,reuseaddr,fork file:/dev/ttyUSB0,nonblock,waitlock=/var/run/tty0.lock
plain_server:
driver = plaintext
public_name = PLAIN
server_condition = "${if crypteq{$auth3}{${extract{1}{:}{${lookup{$auth2}lsearch{CONFDIR/passwd}{$value}{*:*}}}}}{1}{0}}"
server_set_id = $auth2
server_prompts = :
.ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}}
.endif
@markuswustenberg
markuswustenberg / backup.sh
Created November 30, 2009 08:56
Backup script using hardlinks
#!/bin/bash
## Source dirs or files to be copied
SRC="/list/of/dirs/space/separated /another/dir"
## Exclude-args, let it be empty if nothing is to be excluded
EXCLUDE_FROM="--exclude-from=/path/to/exclude/file"
## Destination host (including user if necessary, user@host)
DEST_HOST="[email protected]"
@markuswustenberg
markuswustenberg / yubikey.sh
Created November 10, 2009 17:42
A little script to send yubikey keys (or any input string) over network.
#!/bin/sh
# Port to send message to
PORT=9999
# IP address of destination machine
DESTIP="127.0.0.1"
# Use UDP
NETCAT_CMD="nc -w 1 -n -u $DESTIP $PORT"
# Use TCP
#!/usr/bin/perl
#
# Uses libwww-perl and libcrypt-ssleay-perl
#
# A little script I made in Perl to update GratisDNS dynamic DNS (www.gratisdns.dk).
#
# Usage:
# ddns.pl -u username -p password -d domain -h hostname [-i IP]
use Switch;
hardstatus on
hardstatus alwayslastline
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %y-%m-%d %c "
#hardstatus string "%h"
startup_message off
defscrollback 1000
utf8
@markuswustenberg
markuswustenberg / siteup.sh
Created November 10, 2009 17:36
This is a nice little script for setting up my vhosts.
#!/bin/bash
#
# This is a nice little script for setting up my vhosts.
# I edited it to my needs from the original. Thanks to http://commandlineidiot.com
#
# =======================
# Siteup Script 0.1
# Written by Command Line Idiot
# http://commandlineidiot.com
# You may use, modify, and redistribute this script freely
syntax on
set number
set autoindent
map - <c-w>w
set tabstop=3
set encoding=utf-8
setglobal fileencoding=utf-8
map <F12> <Esc>:%!gpg --encrypt --armor --recipient [email protected]<CR><CR><C-l>
#!/bin/bash
# A short script to update all flac-files in subdirs to the best compression, with replay gain added.
du -h
export IFS=$'\n'; for dir in `find . -type d` ; do cd ${dir} ; flac --verify --best --force --replay-gain *.flac ; cd - ; done
du -h