This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrieNode | |
def initialize | |
@sub_tries = {} | |
@end_of_word = false | |
end | |
def insert(input) | |
to_insert = input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Langton Ant in ruby-processing | |
class LangtonAnt < Processing::App | |
WHITE = -1 | |
BLACK = -16777216 | |
DefaultMovements = { | |
:up => { WHITE => :right, BLACK => :left }, | |
:down => { WHITE => :left, BLACK => :right }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fixnum | |
ROMAN_CONVERSION = [ | |
[1000, 'M' ], | |
[900, 'CM'], | |
[500, 'D' ], | |
[400, 'CD'], | |
[100, 'C' ], | |
[90, 'XC'], | |
[50, 'L' ], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer