Skip to content

Instantly share code, notes, and snippets.

View spalladino's full-sized avatar
🔷

Santiago Palladino spalladino

🔷
View GitHub Profile
@spalladino
spalladino / default_request_params.rb
Created December 2, 2011 16:03
Default request parameters in Rails functional tests
class ActionController::TestCase < ActiveSupport::TestCase
module Behavior
def process_with_default_params(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
default_params = {:locale => :en}
parameters ||= {}
parameters.reverse_merge! default_params
process_without_default_params(action, parameters, session, flash, http_method)
end
alias_method_chain :process, :default_params
end
@spalladino
spalladino / jquery.delayedChange.js
Created December 16, 2011 23:36
Delayed change jquery plugin
(function($){
$.delayedChangeDelay = 1000;
$.checkUpdateTime = 500;
// Special event definition.
$.event.special.delayedChange = {
setup: function( params ) {
// Add data and handlers to other events
@spalladino
spalladino / instedd_init.js.coffee
Created April 17, 2012 16:15
Knockout js binding handler for reapplying instedd initializer when the object is created
ko.bindingHandlers.instedd_init =
init: (element, valueAccessor, allBindingsAccessor, viewModel) ->
$.instedd.init_components($(element))
@spalladino
spalladino / blog01.js.coffee
Created May 23, 2012 11:45
Organizing coffeescript code in a Rails 3 app
if $('#my_div_in_complex_page').length > 0
class Foo
...
@spalladino
spalladino / recordings.rb
Created June 11, 2012 14:28
Retrieve recordings duration for steps in call flow for Verboice from exported vrb
require 'yaml'
require 'csv'
FILE = 'sample.vrb'
class Recording < Struct.new(:step_id, :step_name, :message, :duration)
def self.from_step(step, message='message')
self.new(step['id'], step['name'], message, (step[message]['duration'] rescue nil))
end
end
@spalladino
spalladino / vertica_adapter.rb
Created November 29, 2012 20:47
ActiveRecord adapter for Vertica compatible with version 3.2.8
# Based on version by https://github.com/mgbaron/activerecord_vertica_adapter2/blob/master/lib/active_record/connection_adapters/vertica_adapter.rb
# Place this file in lib/extras/active_record/connection_adapters/vertica_adapter.rb and require it when needed
# You may use a different connection by specifying `establish_connection Rails.configuration.database_configuration["census"]`
require 'active_record/connection_adapters/abstract_adapter'
require 'arel/visitors/bind_visitor'
module ActiveRecord
class Base
# Establishes a connection to the database that's used by all Active Record objects
@spalladino
spalladino / array_first_with_block.rb
Created June 14, 2013 21:39
Array#first redefinition so it can accept a block and behave like find, for compatibility with .NET LINQ programmers
class Array
def first_with_block(&block)
block_given? ? find(&block) : first_without_block
end
alias_method_chain :first, :block
end
# 1.9.3p0 :009 > [1,2,3,4,5].first{|x| x > 2}
# => 3
# 1.9.3p0 :010 > [1,2,3,4,5].first
@spalladino
spalladino / update-icmls.py
Created July 17, 2013 17:36
Updates the icml files for the handbook's chapters based on a diff file from txt extracts
import re
import fileinput
import os
from glob import glob
ICML_DIR = "icml"
OUT_DIR = "output"
# Get icml files in memory
@spalladino
spalladino / Capfile
Created September 2, 2013 22:13
Hacking an erlang application deployment with Capistrano 3
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
namespace :deploy do
@spalladino
spalladino / verboice-user.sh
Created January 29, 2016 12:05
Manually change the password for the main user in a local installation of Verboice
# Go to Verboice main folder
cd verboice
# Open console
bundle exec rails c production
# Retrieve the first user
u = User.first
# This line should print the user's email, check that it is the one you expect