Skip to content

Instantly share code, notes, and snippets.

@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 / 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") {

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)]
$ irb -r selenium-webdriver
>> require 'net-http-spy'
=> true
>> Net::HTTP.http_logger_options = {:verbose => true}
=> {:verbose=>true}
>> driver = Selenium::WebDriver.for :firefox
opening connection to 127.0.0.1...
opened
<- "POST /hub/session HTTP/1.1\r\nAccept: application/json\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 193\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: 127.0.0.1:7056\r\n\r\n"
<- "{\"desiredCapabilities\":{\"browserName\":\"firefox\",\"version\":\"\",\"platform\":\"ANY\",\"javascriptEnabled\":true,\"cssSelectorsEnabled\":true,\"takesScreenshot\":true,\"nativeEvents\":false,\"rotatable\":false}}"
@ivaravko
ivaravko / abs-fatal.php
Created April 6, 2012 15:05 — forked from rgantt/abs-fatal.php
php 5.4 traits
<?php
/**
* This gives a fatal error
*/
class AbsTest {
abstract public function saySomething( $something );
public function saySomething( $something ) {
echo "{$something}\n";
}
}
@ivaravko
ivaravko / gist:2415869
Created April 18, 2012 19:14 — forked from cheezy/gist:2415279
Using PageObject with RSpec
# spec_helper.rb
require 'rspec'
require 'watir-webdriver'
require 'page-object'
require 'page-object/page_factory'
require 'require_all'
require_all 'lib/pages'
RSpec.configure do |config|
@ivaravko
ivaravko / node-httprequest
Created April 29, 2012 19:46 — forked from bdickason/node-httprequest
Simple HTTP Request in NodeJS
getRequest: (callback) ->
options = {
host: config.host or 'yourserver'
port: config.port or 80
path: config.path or '/api/'
method: config.method or 'GET'
tmp = [] # Russ at the NYC NodeJS Meetup said array push is faster
http.request _options, (res) ->
@ivaravko
ivaravko / request post node.js
Created April 29, 2012 20:08 — forked from alessioalex/request post node.js
request post node.js
var request = require('request'), default_headers, site_root = 'http://localhost:3000';;
default_headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-us,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
// 'Connection': 'keep-alive',
'Cache-Control': 'max-age=0'
require 'selenium/webdriver'
driver = Selenium::WebDriver.for :firefox
driver.get "http://jqueryui.com/demos/slider/range.html"
amount = driver.find_element(:id => "amount")
left, right = driver.find_elements(:class => "ui-slider-handle")
driver.action.click_and_hold(left).perform
until amount[:value].include? "150"
@ivaravko
ivaravko / gist:3236244
Created August 2, 2012 10:59
Browser API wishlist

Browser API wishlist

Native event delegation

Browsers could do so much more to optimize delegated handlers at a lower level. Most of the CSS selector parsing and grouping optimizations could be applied here. No javascript code ever has to be invoked if the selector doesn't match.

document.addDelegatedEventListener("mouseover", ".tooltip", listener)

Possibly coming with Web Components.