Skip to content

Instantly share code, notes, and snippets.

var Config = {
'legal-entities/:id': 'entities#show',
'external-contact/current/legal-entities': 'ecEntities#index',
'internal-contact/current/legal-entities': 'icEntities#index',
'outreach-campaigns': 'oc#index',
'outreach-campaigns/new': 'oc#create',
'outreach-campaigns/:id': 'oc#show',
'outreach-campaigns/:id/edit': 'oc#edit',
'outreach-campaigns/:id/legal-entities': 'ocEntities#index'
};
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
== 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: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 / 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 {
@fantactuka
fantactuka / gist:4113044
Created November 19, 2012 19:21
Stupid Objective C hashes
NSMutableDictionary *requestConfig = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"GET", @"method",
@"/", @"path",
[[NSMutableDictionary alloc] init], @"params",
^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"[Request] Success: %@", responseObject);
}, @"success",
^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"[Request] Failure: %@", error);
}, @"failure",
@fantactuka
fantactuka / gist:4123991
Created November 21, 2012 09:36
Quick iterating through string matching
"Hello world".replace(/[aeoiu]/g, function(match, matchIndex) {
console.log(match, matchIndex);
});
// -> e, 1
// -> o, 4
// -> o, 7