Skip to content

Instantly share code, notes, and snippets.

Problem 1: Stacks and Bags

Our goal is to make it so that we have a stack equality operator that is both a stand-in replacement for bag's equality operator and does the right thing when dealing with a stack operation. Liskov suggests that you could define something like Bag#bag_equal?, which Stack must expose and implement to match Bag's behavior, and that you could add a second stack_equal? method for doing ordered comparisons. However, this feels like a kludge to me, and so I tried to take another angle, following a pattern found in Ruby's Numeric class (i.e. its integer? and float? methods):

require "set"

class Bag  
  def ==(other)
    [Set.new(data), limit] == [Set.new(other.send(:data)), other.send(:limit)]
@ivaravko
ivaravko / gist:1908459
Created February 25, 2012 13:19 — forked from wesbos/gist:1476820
PhantomJS Screenshot
var page = new WebPage(),
address, output, size;
address = "http://www.metachunk.com/";
width = 1024; height = 600;
output = "./screenshots/wat-"+width+"X"+height+".png";
page.viewportSize = { width: width, height: height };
if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") {
@ivaravko
ivaravko / MetaObject.php
Created January 18, 2012 10:04 — forked from CHH/MetaObject.php
PHP does Meta Programming too! (Requires PHP 5.4)
<?php
namespace CHH;
trait MetaObject
{
protected static $metaClass;
static function setMetaClass(MetaClass $metaClass)
{
@ivaravko
ivaravko / selenium_dom.py
Created January 17, 2012 08:47 — forked from pamelafox/selenium_dom.py
Python Selenium Dom Helper Functions
from selenium.common.exceptions import NoSuchElementException, TimeoutException
class DomHelper(object):
driver = None
waiter = None
def open_page(self, url):
self.driver.get(url)
@ivaravko
ivaravko / chat.rb
Created December 17, 2011 13:30 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@ivaravko
ivaravko / revspdynpn.sh
Created December 14, 2011 13:41 — forked from carsonmcdonald/revspdynpn.sh
How to set up ruby, eventmachine and spdy to use NPN
#
# Get development tools installed
#
sudo yum install -y git cvs zlib-devel
sudo yum groupinstall -y "Development Tools"
#
# Install RVM
#
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
@ivaravko
ivaravko / test.rb
Created September 12, 2011 14:58 — forked from jarib/test.rb
modal dialog issue
require 'rubygems'
require 'selenium-webdriver'
require 'pp'
dir = Dir.mktmpdir("modal-dialog")
htmls = DATA.read.scan(/--- (.+?) ---\n(.+?)(?=---|\z)/m)
htmls.each do |name, content|
File.open(File.join(dir, name), "w") { |io| io << content}
end
require 'selenium-webdriver'
ctrl = Selenium::WebDriver::Platform.os == :macosx ? :command : :control
browser = Selenium::WebDriver.for :chrome
begin
browser.get "data:text/html;content-type=utf-8,#{URI.escape DATA.read}"
receiver = browser.find_element(:id => "receiver")
receiver.send_keys 'foo'
receiver.send_keys [ctrl, 'a'], :backspace
@ivaravko
ivaravko / test.rb
Created August 9, 2011 10:46 — forked from jarib/test.rb
require 'selenium-webdriver'
browser = Selenium::WebDriver.for :firefox
begin
browser.get "data:text/html;content-type=utf-8,#{URI.escape DATA.read}"
opts = browser.find_elements(:tag_name => "option")
opts[0].click
opts[1].click
@ivaravko
ivaravko / test.rb
Created August 9, 2011 09:30 — forked from jarib/test.rb
#encoding: utf-8
require 'selenium-webdriver'
browser = Selenium::WebDriver.for :firefox
begin
browser.get "data:text/html;content-type=utf-8,#{URI.escape DATA.read}"
frame = browser.find_element(:tag_name => "iframe")
p frame