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
# -*- coding: utf-8 -*- | |
""" | |
Builds epub book out of Paul Graham's essays: http://paulgraham.com/articles.html | |
Author: Ola Sitarska <[email protected]> | |
This script requires python-epub-library: http://code.google.com/p/python-epub-builder/ | |
""" | |
import re, ez_epub, urllib2, genshi |
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 Position | |
attr_reader :x, :y | |
@cache_of_positions = {} | |
def self.new_with_memo(x,y) | |
@cache_of_positions[[x,y]] || Position.new(x,y).tap do |instance| | |
@cache_of_positions[[x,y]] = instance | |
end | |
end |
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 'rspec' | |
require 'simplecov' | |
SimpleCov.start | |
require './task.rb' | |
describe Todo::Task do | |
before(:each) do | |
@time = Time.now | |
Time.stub(:now).and_return(@time) |
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 'rspec' | |
require 'simplecov' | |
require './task.rb' | |
SimpleCov.start | |
require './list.rb' | |
describe Todo::List do | |
before(:each) do | |
@file_path = './spec_todo.txt' |
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 SudokuBoard | |
def initialize(board_str) | |
@board = board_str.split("").map { |value| Cell.new(value.to_i) } | |
@groups = [] | |
(generate_rows + generate_cols + generate_grids).each do |group_member_indices_ar| | |
group_cell_members = group_member_indices_ar.map { |index| @board[index] } | |
@groups << Group.new(group_cell_members) | |
end | |
puts to_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
class Array | |
def pad!(min_size, value = nil) | |
self.concat( Array.new(min_size - self.length, value)) if self.length < min_size | |
self | |
end | |
def pad(min_size, value = nil) | |
self.dup.pad!(min_size,value) | |
end | |
end |
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
module Anagram | |
attr_reader :word_dict | |
def anagrams | |
@word_dict = {} | |
self.each do |str| | |
puts str | |
sorted_str = str.chars.sort.join | |
if @word_dict[sorted_str] == nil | |
@word_dict[sorted_str] = [str] | |
else |
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 'jumpstart_auth' | |
require 'bitly' | |
class JSTwitter | |
attr_reader :client | |
def initialize | |
puts "Initializing" | |
@client = JumpstartAuth.twitter | |
end |
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 game(ar) | |
throw1 = ar[0][1].downcase | |
throw2 = ar[1][1].downcase | |
if %w{ rs pr sp }.include?(throw1 + throw2) | |
return ar[0] | |
elsif %w{ sr rp ps}.include?(throw1 + throw2) | |
return ar[1] | |
else | |
"It's a Tie!" |
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
module Mark_twain | |
def mark_twain | |
mark_twain_helper(self, []) | |
end | |
def mark_twain_helper(str, accum_ar) | |
if str.split.length == 1 | |
accum_ar << "Final draft: #{str}." | |
accum_ar | |
else |
NewerOlder