Skip to content

Instantly share code, notes, and snippets.

View astromechza's full-sized avatar
🐙

Ben Meier astromechza

🐙
View GitHub Profile
@astromechza
astromechza / GObjectPool.cs
Last active December 24, 2015 19:09
A C# implementation of a Object Pool pattern. An array backed fixed size resource pool that supports provisioning and disposing instances as well as looping through the instances being used int forward or reverse order. WARNING: may contain bugs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Author: Benjamin Meier ([email protected])
// Date: 06/10/2013
namespace ObjectPoolTester
public class Levenshtein
{
/**
* Calculate the Levenshtein distance between two strings. Basically, the number of
* changes that need to be made to convert one string into another. Very useful when
* determining string similarties.
* @param stringOne
* @param stringTwo
* @param caseSensitive Should differences in case be treated as changes.
@astromechza
astromechza / .gitconfig
Created February 3, 2014 18:28
This is the current .gitignore I use most of the time.
[user]
name = Ben Meier
email = [email protected]
[alias]
# git ds - diff your staged changes == review before committing.
ds = diff --staged
# smarter status - include tag and branch info
st = status -sb
# I know what you did yesterday - great for follow-ups
@astromechza
astromechza / sublime_perferences.json
Created June 23, 2014 11:33
my Sublime Text 3 preferences
{
"always_prompt_for_file_reload": false,
"always_show_minimap_viewport": true,
"animation_enabled": true,
"atomic_save": true,
"auto_find_in_selection": false,
"auto_match_enabled": true,
"bold_folder_labels": true,
"caret_extra_width": 1,
"caret_style": "phase",
@astromechza
astromechza / configuration.py
Created August 9, 2014 13:23
Sweet and simple configuration module for Python scripts
import os
import json
class Config(object):
_CONFIG_FILE = '~/.config/my_program/settings'
def __init__(self, custom_path=_CONFIG_FILE, auto_load=False):
self.loaded = False
self.file_path = os.path.expanduser(custom_path)
@astromechza
astromechza / CompactBitArray.java
Last active August 29, 2015 14:06
My own version of a compacted integer array for storing values which only need a few bits rather than entire bytes/integers. Although any number of bits from 1 to 32 is supported, it only uses blocks that can divide equally into 32.
package org.uct.cs.simplify.util;
public class CompactBitArray
{
private static final int INTEGER_SIZE = 32;
private final int bits;
private final long length;
private final int blockLength;
private final int blocksPerInt;
@astromechza
astromechza / pyskeleton.py
Last active February 10, 2017 13:09
pyskeleton.py: Generate a basic Python package, ready for development.
#!/usr/bin/env python
"""
This script creates a basic Python package skeleton in the given directory.
It also sets up pytest (with coverage).
"""
import os
import re
@astromechza
astromechza / coloured_stream_handler.py
Last active August 29, 2015 14:13
coloured_stream_handler.py: A logging stream handler that colours lines differently depending on their logging level.
from logging import StreamHandler
try:
unicode
_unicode = True
except NameError:
_unicode = False
class ColouredStreamHandler(StreamHandler):
@astromechza
astromechza / webbing.html
Created February 1, 2015 20:21
Quick JS webbing demo with canvas.
<!DOCTYPE html>
<html>
<head>
<title>JS Webbing</title>
<style type="text/css">
h1, h5 {
font-family: Verdana;
}
</style>
</head>
@astromechza
astromechza / gen-loadshedding-times
Created February 2, 2015 18:45
Python script to generate the times the given Cape Town area will be load shed on a certain day under a certain schedule
#!/usr/bin/env python
"""
Generate eskom loadshedding schedule v2 for Cape Town
In the following code, 'day' means the day of the month.. 1-31
Author: Ben Meier
Date: 02/02/2015
"""
import sys