Skip to content

Instantly share code, notes, and snippets.

var applyToNew = function(Class, args) {
var F = function () {};
F.prototype = Class.prototype;
var f = new F();
Class.apply(f, args);
return f;
};
applyToNew(SomeClass, arrayOfArguments);
@fantactuka
fantactuka / gist:1115402
Created July 30, 2011 10:42
Rerun all tests after changed tests passed
# encoding: utf-8
require "test_notifier/runner/autotest"
class Autotest
alias :original_get_to_green :get_to_green
def get_to_green
original_get_to_green
rerun_all_tests
end
@fantactuka
fantactuka / gist:1238174
Created September 23, 2011 19:03
Cucumber + Capybara test new window opened
Then /url "([^"]*)" is opened in new window/ do |url|
 browser = page.driver.browser
 current_id = browser.window_handle
 tab_id = page.driver.find_window(url)
 browser.switch_to.window tab_id
 page.driver.browser.close
 browser.switch_to.window current_id
end
== ImportSql: migrating ======================================================
Connected to database
- remove all tables from database
- import database from /Users/maksim/Projects/tabletennis-by/db/migrate/../tabletennis_onliner_tournament.sql
- rename/remove tables
- rename/remove/add columns
- create group for single games and remove extra columns
- delete relations for removed players
- apply group changes:
extract league id 6903/6903
@fantactuka
fantactuka / gist:1489828
Created December 17, 2011 09:56
Inheritable class attributes
module InheritableAttributes
def self.included base
base.extend ClassMethods
end
module ClassMethods
def inheritable_attr *attrs
attrs.each do |attr|
class_eval <<-CODE
def self.#{attr} #{attr}=nil
@fantactuka
fantactuka / gist:1540550
Created December 30, 2011 16:38
Creates hash code from string, ported from #C
// Borrowed from http://stackoverflow.com/questions/5293174/creating-a-unique-id-from-an-array-of-strings-in-javascript
function getHashCode(str) {
var h1 = (5381 << 16) + 5381, h2 = h1, index = 0;
while (index < str.length) {
h1 = ((h1 << 5) + h1 + (h1 >> 27)) ^ str.charCodeAt(index);
if (index == str.length - 1) {
break;
}
h2 = ((h2 << 5) + h2 + (h2 >> 27)) ^ str.charCodeAt(index + 1);
@fantactuka
fantactuka / gist:1887133
Created February 22, 2012 20:43
Compile sass file into string with compass includes
require "sass"
require "compass"
def compile_sass(sass_file)
sass_dir = File.dirname(sass_file)
compass_dir = File.join(Compass.base_directory, "frameworks/compass/stylesheets")
Sass.compile(File.read(sass_file), syntax: :sass, load_paths: [sass_dir, compass_dir])
end
@fantactuka
fantactuka / update-chrome-driver.sh
Last active June 2, 2020 13:15
Update Chrome driver for mac os
#!/bin/bash
# bash < <(curl -s https://gist.githubusercontent.com/fantactuka/3228898/raw/f0806a64306426ca72f16734ae7cd16c1f84bd87/update-chrome-driver.sh)
echo "Updating Chrome Driver"
sudo su
if [ -e /usr/bin/chromedriver ]; then
rm /usr/bin/chromedriver
echo "Removing current Chrome Driver from /usr/bin"
@fantactuka
fantactuka / matchers.js
Created September 19, 2012 09:47
Adding jasmine matches in helper outside beforeEach (to speedup)
// Hacking Jasmine: adding matchers outside beforeEach to speed up code
jasmine.addMatchers = function(matchers) {
var parentClass = jasmine.getEnv().matchersClass;
var matchersClass = function() {
parentClass.apply(this, arguments);
};
jasmine.util.inherit(matchersClass, parentClass);
jasmine.Matchers.wrapInto_(matchers, matchersClass);
jasmine.getEnv().matchersClass = matchersClass;
@fantactuka
fantactuka / app.rb
Created October 28, 2012 20:51
Parallel requests in sinatra
require "sinatra"
require "sinatra/async"
require "em-synchrony"
require "em-synchrony/em-http"
class App < Sinatra::Base
register Sinatra::Async
aget "/" do
Fiber.new {