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
# | |
# simple option parser that supports negative numbers as arguments, because I needed to do that | |
# | |
# should mostly be a drop-in replacement for OptionParser's basic usage patterns | |
# | |
class MDOP | |
# | |
# class to hold each option's data (including its Proc) | |
# |
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
tape = {} | |
tape.default = 0 | |
ptr = 0 | |
tape[ptr] += 13 | |
while tape[ptr] != 0 | |
tape[ptr] -= 1 | |
tape[ptr + 1] += 2 | |
tape[ptr + 4] += 5 | |
tape[ptr + 5] += 2 | |
tape[ptr + 6] += 1 |
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 subclass of Hash is designed to search for the values associated | |
# with the two nearest Numeric keys to a given "key" argument *not* | |
# a member of the FindNeighborsHash, or the *single* value associated with | |
# an *existing* key. | |
# | |
class FindNeighborsHash < Hash | |
def []=(key, val) | |
raise ArgumentE |
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
filetype indent on " automatically indent | |
set expandtab " tabs are spaces | |
set shiftwidth=2 " two space indent | |
set tabstop=2 | |
set ruler " display line number and position | |
"This unsets the "last search pattern" register by hitting return | |
nnoremap <CR> :noh<CR><CR> |
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
# parse input | |
input = IO.read(ARGV.shift) | |
scanned = input.scan(/([A-Z].+?)([.?!])/).collect{ |arr| arr.join(" ").split } | |
words = Hash.new # store the successive probabilities of words | |
firstcount = 0 | |
firsthash = Hash.new(0) # store the initial words' probabilities | |
scanned.each do |sentence| | |
last = sentence.shift |
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
require 'mail' | |
require 'iconv' | |
file, subj, email = *ARGV | |
raise "usage: #{File.basename(__FILE__)} <file> <subject> <email>" unless email | |
file_content = IO.read(file) | |
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') |
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
import System.Environment(getArgs) | |
main = do args <- getArgs | |
if length args > 0 | |
then do inpstr <- readFile $ head args | |
putStrLn $ show (maxPathSum (parseData inpstr)) | |
else putStrLn "I need a filename with triangle data!" | |
parseData s = map (\s -> map read (words s)) $ lines s |
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
MAX_THREADS = 4 | |
def self.run_threaded_systems(tasks) | |
queued_tasks = tasks.each_with_object(Queue.new) do |task, queue| | |
queue.push(task) | |
end | |
MAX_THREADS.times.inject(Array.new) { |threads| | |
threads << Thread.new(queued_tasks) { |queue| | |
while task = queued_tasks.pop(true) rescue nil | |
puts("running command #{task.join(" ")}") |
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
WIDTH = 80 | |
puts $stdin.read.split(/\n\n+/).each_with_object([]) { |paragraph, result| | |
result << paragraph.split.each_with_object([""]) { |word, lines| | |
if (lines.last + " " + word).length > WIDTH | |
lines << word | |
elsif lines.last.empty? | |
lines[-1] += word | |
else | |
lines[-1] += (" " + word) |
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
require 'thread' | |
module KnifeDrawer | |
DEFAULT_NUM_FORKS = 4 | |
def self.do_with_forks(tasks_hash, num_forks = DEFAULT_NUM_FORKS) | |
input_queue = Queue.new | |
output_queue = Queue.new |
OlderNewer