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 |
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_relative 'memoize' | |
class Object | |
def _identity | |
self | |
end | |
end | |
# | |
# class providing binary search functionality around Array |
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 'pqueue' | |
require 'set' | |
### class Point and subclasses | |
Point = Struct.new(:x, :y) | |
class Point | |
attr_reader :marked |
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 PriorityQueue | |
include Enumerable | |
def initialize(from = [], &cmp) | |
@cmp = cmp || proc { |a, b| a <=> b } | |
@heap = BinaryHeap.new(from, &@cmp) | |
end | |
[:push, :pop, :empty?].each do |m| |
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
# Lines configured by zsh-newuser-install | |
HISTFILE=~/.histfile | |
HISTSIZE=1000 | |
SAVEHIST=1000 | |
bindkey -v | |
# End of lines configured by zsh-newuser-install | |
# The following lines were added by compinstall | |
zstyle :compinstall filename '/home/mdunsmuir/.zshrc' | |
autoload -Uz compinit |
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/sh | |
ruby -e 'lines=IO.readlines(ARGV.shift);l=lines.map(&:length).max;puts lines.map{|s|sprintf("%-#{l}s",s.strip).chars}.transpose.map(&:join).join("\n")' $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
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-} | |
module BinomialHeap ( | |
fromList, toList, | |
insert, findMin, deleteMin, merge, | |
checkAll, checkOrders, checkFindMin, checkDeleteMin | |
) where | |
import Data.List hiding (insert) | |
import qualified Data.Map.Lazy as M |
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
def subset_sum(set, length) | |
map = Hash.new { |h, k| h[k] = Hash.new([]) } | |
map[set.first][1] = [set.first] | |
1.upto(set.length - 1) do |i| | |
map.keys.each do |sum| | |
new_sum = sum + set[i] | |
map[sum].keys.each do |subset_len| |
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 ErrorCollector | |
class DontUseThisError < StandardError; end | |
class DontUseThis < BasicObject | |
def method_missing(*args) | |
::Kernel.raise ::ErrorCollector::DontUseThisError.new('this object is invalid') | |
end | |
end |
OlderNewer