Skip to content

Instantly share code, notes, and snippets.

public class LinkedSet<Row> {
/* "Empty" list, is first and last with null values - first & last are same */
private Node first = null;
private Node last = null;
private Map<Row, Node> index = new HashMap<Row, Node>();
/* Linked-list node */
private final class Node {
@ruskotron
ruskotron / remedian-mat.java
Last active November 16, 2016 10:46
Java style pseudocode for the remedian algorithm
/* Remedian algorithm rework to use matrices rather than discrete arrays
"""The program of Figure 2 can be easily adapted to produce
the remedian curve, by replacing the arrays A l , A2,
A3, and A4 of length 11 by matrices with 11 rows and T
columns. In this way the total storage becomes 44T, whereas
the plain median would have needed 14,641T positions"""
*/
@ruskotron
ruskotron / bgbuild.sh
Created September 11, 2015 15:17
Run a build in the background ; write output to faster local 'scratch' ; on exit copy output into local dir
$ nohup bash -c "(. env.sh ; make all > /tmp/build.log.${!} 2>&1 ; mv /tmp/build.log.${!} .)" &
# Tips from https://www.mattcutts.com/blog/a-quick-tutorial-on-screen/
# Use Ctrl-Z instead of Ctrl-A for escape
#escape ^Zz
# "You'll get scrolling like you're used to (with your wheely mouse)"
termcapinfo xterm|xterms|xs|rxvt ti@:te@
# you will get a bottom bar indicating name of machine you're on, a clock, and indicators in which shell you currently are.
# Use CTRL-A SHIFT-A to rename your shells. The names will then also appear in the bottom bar
@ruskotron
ruskotron / start_vm.sh
Last active August 29, 2015 14:22
Start a Vagrant VM without having to use "vagrant up" (which can potentially destroy your VM if it prior "vagrant halt" didn't work properly)
#!/usr/bin/bash
#
VM_NAME=$1
SSH_PORT=$(VBoxManage showvminfo ${VM_NAME} --machinereadable | awk -F, '/^Forwarding\([0-9]+\)="/ && $NF == "22\"" { print $(NF-2) ; exit}')
echo "SSH PORT: $SSH_PORT"
VBoxManage.exe list runningvms | grep -q "^\"$VM_NAME\" " || (
@ruskotron
ruskotron / key_decode.py
Created January 14, 2015 09:13
Decode MS-MPPE-Send-Key / MS-MPPE-Recv-Key
from hashlib import md5
from binascii import unhexlify, hexlify
seq_xor = lambda c, b: ''.join(
chr(x) for x in map(lambda X: ord(X[0]) ^ ord(X[1]), zip(c, b))
)
#
interface Resource {
void monopolise() throws InterruptedException;
}
public class Interrupts implements Runnable {
private final MyResources myRes;
@ruskotron
ruskotron / my_bash_profile.sh
Last active January 25, 2016 09:24
My .bash_profile
#
# rrusk 2015-11-25 Universal bash profile
# 2015-12-21 Added Colour Output for Ant
# 2016-01-25 ignore CVS and .svn autocomplete
# notify version
echo hello 8.2
#
@ruskotron
ruskotron / my_epoch
Last active December 21, 2015 09:09
So imagine you have an arbitrary time system in place, where you define time as a number of minutes from a particular date (beginning of your "epoch"), or days from that particular date. If you ever needed to convert such dates to a sensible format, commands such as these could be useful to you. Just add to your environment (e.g. ".bashrc") e.g.…
# set base of 'my' epoch (here it's the start of the 21st century)
export MY_EPOCH=$(expr $(date --date="2000/01/01 00:00:00" +%s))
# format date and time, as expressed in minutes from start of 'my' epoch
function strftime_my {
date --date="@$(expr $MY_EPOCH + \( $1 \* 60 \) )"
}
# format date, as expressed in days from start of 'my' epoch
function strfdate_my {
@ruskotron
ruskotron / mycmd.cmd
Last active December 18, 2015 04:59
Windows command-shell initialisation - if you're used to developing under linux and you want to enjoy some of the same command-line luxuries under windows unfortunately there's nothing you can do to get command-line history beyond your current seesion :-(
rem lines starting with "rem" are commented out similar to '#' in unix-land
rem so you want to have a useful windows command-line?
rem put this file in some standard location like "C:\myscripts"
rem then right-click, "New > Shortcut" and enter the following for location:
rem C:\Windows\System32\cmd.exe /K "C:\myscripts\mycmd.cmd"
rem give it a name you like and then 'finish'
rem then right-click on the shortcut, go to "Properties" and set "Start in:" to be your "Home Directory"
rem I've tried to explain some of the peculiarities of windows "batch-file" and "doskey" scripting below ...