Skip to content

Instantly share code, notes, and snippets.

View DataWraith's full-sized avatar

Johannes Holzfuß DataWraith

View GitHub Profile
@DataWraith
DataWraith / trie.rb
Created December 23, 2009 18:03
A simple Trie to find words that match a simple pattern
class TrieNode
def initialize
@sub_tries = {}
@end_of_word = false
end
def insert(input)
to_insert = input
@DataWraith
DataWraith / arc_four_cipher.rb
Created February 12, 2010 07:19
Ruby implementation of the Arcfour Cipher
# Ruby implementation of the Alleged RC4 Cipher
class ArcFourCipher
def initialize(key)
@s = (0..255).to_a
s2 = []
key_arr = key.bytes.to_a
0.upto(255) do |i|
s2 << key_arr[i % key.bytesize]
@DataWraith
DataWraith / hash_dir.zsh
Created April 6, 2010 17:16
Script to recursively hash the contents of the current directory, with a nice progress display
#!/bin/zsh
# hash_dir.zsh recursively hashes the contents of the current directory.
#
# It is meant for use with file collections that are occasionally added to, and
# will preserve older hashes if files are removed for some reason (for example,
# moved to a different storage medium).
#
# To avoid recalculating hashes every time it is run, it caches file hashes by
# full path, size and mtime.
@DataWraith
DataWraith / rangton.rb
Created April 14, 2010 10:12
Langton Ant written with ruby-processing
# Langton Ant in ruby-processing
class LangtonAnt < Processing::App
WHITE = -1
BLACK = -16777216
DefaultMovements = {
:up => { WHITE => :right, BLACK => :left },
:down => { WHITE => :left, BLACK => :right },
@DataWraith
DataWraith / polipo_cache_clean.zsh
Created May 7, 2010 19:11
Script to clean Polipo's cache once free space runs low
#!/bin/zsh
# This script deletes the least-recently used (LRU) files from Polipo's cache
# once the partition it is on has less than $min_disk_free Bytes of free space
# left.
#
# It's meant to be used as a cron job, and it's a little more complicated than
# it needs to be, because I wrote it mostly to learn zsh.
local cache_dir="/var/cache/polipo/"
@DataWraith
DataWraith / Neural_Net_demo.rb
Created July 1, 2010 19:14
Example of a _very_ simple feed-forward neural network.
class Link
def initialize(to, weight)
@to = to
@weight = weight
end
def propagate(activation)
puts " propagating #{activation} * #{@weight} = #{@weight * activation} to #{@to.name}"
puts " old activation: #{@to.activation}"
@DataWraith
DataWraith / roman_numerals.rb
Created April 6, 2011 13:44
The result of my 2nd attempt at the Roman Numerals Kata
class Fixnum
ROMAN_CONVERSION = [
[1000, 'M' ],
[900, 'CM'],
[500, 'D' ],
[400, 'CD'],
[100, 'C' ],
[90, 'XC'],
[50, 'L' ],
@DataWraith
DataWraith / genpswd.rb
Created July 23, 2011 15:59
Simple random password generator. Bonus: Base62 encoder/decoder
#/usr/bin/env ruby
require 'securerandom'
ENTROPY_BITS = 256
# Generate a password with an entropy of #{ENTROPY_BITS} bits by encoding a large number
# from the secure random number generator as Base62. Base64 is avoided because some websites
# reject passwords that contain non-alphanumeric characters. This also makes copy&paste easy
# through automatic word-boundary detection (on doubleclick) in many application.
@DataWraith
DataWraith / COPYING
Last active September 16, 2024 03:24
A simple Tetris clone written in Java
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
@DataWraith
DataWraith / ppm32d.py
Created April 5, 2013 14:11
A rock-paper-scissors player written in Python for rpscontest.com. As of April 2013 it was ranked 85th out of 1318 contestants.
# This entry is based on Prediction by Partial Matching, a method that is used
# in data compression.
import random
from collections import defaultdict
CONTEXT_SIZE=32
if input == "":
# Initialize data structure