Skip to content

Instantly share code, notes, and snippets.

View runjak's full-sized avatar
🍧
<- drop it.

Jakob Runge runjak

🍧
<- drop it.
View GitHub Profile
@runjak
runjak / Main.hs
Created March 2, 2014 14:21
Simple, clutchy deduplication done with softlinks.
module Main where
{-
When using `find -type f -print0 | xargs -0 md5sum > foo.sums`,
this script allows to compare two files of such sums for their intersecting sums.
The `drop 4` later on drops the ' ./' after the md5sums,
and the `splitAt 32` determines the length of the sum,
in case another sum should be used.
Deduplication is performed by replacing the files from f1
with softlinks to files from f2.
-}
@runjak
runjak / tmux.sh
Created August 24, 2014 16:55
A script to setup a tmux session with ssh connections to multiple hosts
#!/bin/sh
SESSION="sessionName"
# Creating the tmux session:
tmux new-session -d -s $SESSION
# Disable renaming of windows:
tmux set-option -t $SESSION -g allow-rename off
# Function to open a window and connect to a target:
# Parameters are window name, target ip
@runjak
runjak / howto
Last active August 29, 2015 14:07
Two scripts to perform a backup of several block devices over network.
The two backup scripts ``read.sh`` and ``write.sh`` will be executed as a pair,
to copy multiple devices or logical volumes from a host to a local computer.
To achive this, a number of steps must be taken:
1: Fill targets="" with the same sequence of targets for both scripts, the order being essential.
2: Make sure the targets to write to at the client/write.sh part are at least as large as the targets on the host/read.sh part.
3: We assume that the host runs an ssh server, but the client may not offer an ssh connection.
To get data flowing over network from host to client we'll therefore build a reverse tunnel with ssh.
```ssh -R 62222:localhost:62222 $host -N```
Note that we use port ``62222`` on both sides, which is the same port as used with ``nc`` in both scripts.
4: Start ``write.sh`` before ``read.sh``, so that it already listens for incoming data before ``read.sh`` tries and failes to connect.
@runjak
runjak / setMacs.sh
Created October 5, 2014 12:13
A simple script that helps me to manage my mac addresses.
#!/usr/bin/bash
# Inspired by https://wiki.archlinux.org/index.php/MAC_address_spoofing
eth="eth0"
wifi="wlan0"
case $1 in
old)
echo "Changing to your old macs:"
macchanger --mac=xx:xx:xx:xx:xx:xx $eth
macchanger --mac=xx:xx:xx:xx:xx:xx $wifi
@runjak
runjak / dockerdropbox.service
Last active August 29, 2015 14:12
/etc/systemd/system
[Unit]
Description=Start/Stop the docker dropbox container
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=-/usr/bin/make -C <path to docker-dropbox> start
ExecStop=-/usr/bin/make -C <path to docker-dropbox> stop
#!/bin/sh
# Inspired by https://gist.github.com/runjak/1c76dc9e3fcda878c7c9
SESSION="wlan"
# Creating a new session:
tmux new-session -d -s $SESSION
# Splitting the window:
tmux split-window -v -t $Session:0.0
tmux split-window -h -t $Session:0.0
# Execute some fun commands:
@runjak
runjak / startBitcoind.sh
Created April 3, 2015 10:42
Starting and stopping some bitcoind instances in regtest mode
#!/usr/bin/sh
#https://bitcoin.stackexchange.com/questions/28107/bitcoin-is-not-connected-in-regtest-mode/28109
# Creating config directories:
RDIR="/tmp/bitcoind"
mkdir -p $RDIR/A $RDIR/B $RDIR/C $RDIR/D $RDIR/E
# Starting bitcoind instances:
bitcoind -server -listen -port=17591 -rpcuser=bitcoinrpc -rpcpassword=pass -rpcport=16591 -datadir=$RDIR/A/ -connect=localhost:17592 -regtest -pid=$RDIR/A/.pid -daemon -debug
bitcoind -server -listen -port=17592 -rpcuser=bitcoinrpc -rpcpassword=pass -rpcport=16592 -datadir=$RDIR/B/ -connect=localhost:17593 -regtest -pid=$RDIR/B/.pid -daemon -debug
bitcoind -server -listen -port=17593 -rpcuser=bitcoinrpc -rpcpassword=pass -rpcport=16593 -datadir=$RDIR/C/ -connect=localhost:17594 -regtest -pid=$RDIR/C/.pid -daemon -debug
bitcoind -server -listen -port=17594 -rpcuser=bitcoinrpc -rpcpassword=pass -rpcport=16594 -datadir=$RDIR/D/ -connect=localhost:17595 -regtest -pid=$RDIR/D/.pid -daemon -debug
@runjak
runjak / joinMe.hs
Created December 21, 2015 17:06
HIM - Join Me In Death
module Main where
{-| HIM - Join Me In Death |-}
txt = [ "Baby join me in death"
, "Won't you die"
, "this life ain't worth living"
, "We are so young"
, "our lives have just begun"
, "but already we are considering"
@runjak
runjak / checkBackup.sh
Last active October 21, 2017 18:31
A short backup script using Borg
#!/bin/bash
# Inspired by https://borgbackup.readthedocs.org/en/stable/quickstart.html
# https://gist.github.com/ericmieth/c045edebb0709dfd88e1
# Created by mushu 2016-02-22
# Mounting the volume:
cryptsetup --key-file <keyFile> luksOpen UUID=<deviceUUID> cryptBackup
mount /dev/mapper/cryptBackup /mnt
# Verifying current backups:
borg check /mnt/backups
# Umounting the volume:
@runjak
runjak / DicePuzzle.hs
Created April 28, 2016 17:05
Haskell implementation of the dice puzzle presented at https://www.youtube.com/watch?v=Hfw8bB82-ps
module DicePuzzle where
import Control.Arrow ((&&&))
import Control.Monad
import Data.List
{-|
Projecting the result of three dice onto two dice.
After the design of Katie and Paul [1,2,3].
[1]: https://www.youtube.com/watch?v=Hfw8bB82-ps