Skip to content

Instantly share code, notes, and snippets.

View orbekk's full-sized avatar

Kjetil Ørbekk orbekk

  • NTNU
  • Trondheim, Norway
View GitHub Profile
#!/bin/bash
#
# This script syncs authorized keys (found in the $authorized_keys_file below)
# to a list of remote hosts. It does not touch existing keys unless overwrite
# is set to true, but creates a special section containing the keys.
declare -r begin_marker="### BEGIN MANAGED_BY_KJ_SYNC_AUTHORIZED_KEYS.SH ###"
declare -r end_marker="### END MANAGED_BY_KJ_SYNC_AUTHORIZED_KEYS.SH ###"
declare -r overwrite=true
declare -r tmpdir=$(mktemp -d /tmp/kj_sync_authorized_keys.XXXXX)
@orbekk
orbekk / maybe.cpp
Last active December 26, 2015 08:19 — forked from ehamberg/maybe.cpp
template <class T>
struct Maybe {
public:
Maybe() {}
explicit Maybe(T v) : state_(v) {}
bool isJust() {
return state_;
}
s = r"print \"s = r\\\"\" + s + \"\\\"\"\nprint s.decode(\"string-escape\")"
print "s = r\"" + s + "\""
print s.decode("string-escape")
@orbekk
orbekk / gist:6206917
Created August 11, 2013 21:26
Bash quoting example
#!/bin/bash
function my_print() {
for arg in "$@"; do
echo -n "{$arg} "
done
echo
}
var1="Two bits"
@orbekk
orbekk / bash-challenge-1-solution.sh
Created August 8, 2013 00:00
Bash Challenge #1 Solution
#!/bin/bash
if [[ -z $1 ]]; then
echo "Usage: $(basename $0) NUM_PROCESSES COMMAND..."
fi
NUM_PROCESSES=$1
shift
SEMAPHORE=/tmp/semaphore.$RANDOM
@orbekk
orbekk / bash-challenge-1.txt
Created August 7, 2013 22:45
Bash Challenge #1
Write a script pardo.sh. It should take a target number of processes N, and a list of commands. The commands should be executed in parallel on up to N processes.
Usage: pardo.sh NUM_PROCESSES COMMAND...
Test as follows:
time /tmp/pardo.sh 2 "sleep 2" "sleep 4" "sleep 4" "sleep 2"
This should take 6 seconds.
class WithCallback {
Callback callback = null;
void done() {
callback.run();
}
protected abstract void run();
}
@orbekk
orbekk / gist:2351825
Created April 10, 2012 14:40
Java Data Parallelism
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
public class Par {
int parallelism = Runtime.getRuntime().availableProcessors() + 1;
ExecutorService executor = Executors.newCachedThreadPool();
@orbekk
orbekk / flatten.sh
Created December 4, 2011 17:24
Flatten.sh
#!/bin/bash
# Flatten multi-disk albums.
declare OUTPUT_DIR
declare ALBUM_TITLE
function usage() {
echo "Usage: $0 -t album_title -o output_directory DIRECTORY..."
}
@orbekk
orbekk / rip.sh
Created December 4, 2011 17:23
Rip.sh
#!/bin/bash
for i in {1..1000}; do
DIR=$(printf "Disc %02d\n" $i)
echo "Ripping: " $DIR
echo "Return to continue."
read
mkdir "$DIR" && EJECTCD=y OUTPUTDIR="${DIR}" abcde -N -n
done