Skip to content

Instantly share code, notes, and snippets.

View bxt's full-sized avatar

Bernhard Häussner bxt

View GitHub Profile
@bxt
bxt / md2html
Created November 10, 2011 23:50
Bash script for invoking MarkdownJ to convert Markdown to HTML on CLI
#!/bin/bash
usestdi=off
filename=$1
if [ $1 = "-h" ] ; then
echo "Usage: $0 mdfile [outfile]"; exit
fi
if [ $1 = "-" ] ; then
usestdi=on
@bxt
bxt / bottom.java
Created March 22, 2012 09:43
Java generic "bottom" value
public abstract class Bottom {
public static <E> E get() {
return null;
}
}
@bxt
bxt / Util.java
Created March 25, 2012 12:31
Java utility class for comparable and collections
package de.bxt.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@bxt
bxt / hextime.sh
Created July 22, 2012 13:18
Print the current time as 4 byte hex timestamp
#!/bin/bash
printf '0x%08x' $(date +%s)
@bxt
bxt / webmsg.py
Created August 27, 2012 19:11
Really simple python web server to serve a maintenance message to the web
import string,cgi,time, datetime
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
try:
self.send_response(503) # let bots know whats up
self.send_header('Content-type','text/html')
self.end_headers()
self.wfile.write('<!DOCTYPE html>\n<meta charset=utf-8 />\n<title>Notification page</title>\n')
@bxt
bxt / once.js
Created September 8, 2012 08:38
JavaScript の once よくつかうので (I actually don't use it that often)
function once (fn) {
var done = false, result;
function _once_ () {
if(!done) {
result = fn.apply(this,Array.prototype.slice.call(arguments))
done = true;
}
return result;
}
return _once_;
@bxt
bxt / ConsList.java
Created September 27, 2012 16:34
ConsList for Java, draft
import java.util.AbstractList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class ConsList<E> extends AbstractList<E> implements List<E> {
private E element;
private List<E> parent;
@bxt
bxt / ListSetTest.java
Created September 28, 2012 12:51
Test Java collection performance against set operations with various input characteristics
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.TreeSet;
public class ListSetTest {
public static void main(String[] args) {
@bxt
bxt / see256colors.sh
Last active October 11, 2015 04:37
Handy script for figuring how 256 color terminal colors look like
for i in {0..255}; do echo -e "- \033[38;5;${i}m\\[\\33[38;5;${i}m\\]\033[0m -"; done;
# Prints the code needed for PS1 in the corresponding color.
@bxt
bxt / CD2-README.md
Last active April 9, 2017 19:57
Change shell directory to one of the open directories in other shells

cd2

cd2 is a tiny handy tool for working with multiple console windows at a time. When called, it displays a list of all working directories of your running terminals and lets you choose one by simply entering a number. If you enter nothing it takes you to the last entry listed which makes a good default behavior. This way, when you open a new terminal window and type cd2 and press enter twice you can continue in the same wd as your other bash.

Installing

To install for your user simply run: