Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
perspectivezoom / pgessays.py
Created November 19, 2012 04:27 — forked from olasitarska/pgessays.py
Builds epub book out of Paul Graham's essays.
# -*- coding: utf-8 -*-
"""
Builds epub book out of Paul Graham's essays: http://paulgraham.com/articles.html
Author: Ola Sitarska <ola@sitarska.com>
This script requires python-epub-library: http://code.google.com/p/python-epub-builder/
"""
import re, ez_epub, urllib2, genshi
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
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)
require 'rspec'
require 'simplecov'
require './task.rb'
SimpleCov.start
require './list.rb'
describe Todo::List do
before(:each) do
@file_path = './spec_todo.txt'
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
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
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
require 'jumpstart_auth'
require 'bitly'
class JSTwitter
attr_reader :client
def initialize
puts "Initializing"
@client = JumpstartAuth.twitter
end
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!"
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