This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SignInHelpers | |
def sign_up_as(user_type, form_params={}) | |
attributes = FactoryGirl.attributes_for(user_type).merge(form_params) | |
destory_user(attributes[:email]) | |
visit '/users/sign_up' | |
within("#new_user") do | |
fill_in "Name", :with => attributes[:name] | |
fill_in "Email", :with => attributes[:email] | |
fill_in "Password", :with => attributes[:password] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.codewars.com/kata/batchitemprocessor/ruby | |
require './batchitemprocessor' | |
class Test | |
# This class mimics the one provided in the kata | |
def self.assert_equals(actual, expected, message="") | |
if actual!=expected | |
puts "\nTest '#{message}' failed.\nExpected #{expected}\nGot #{actual}" | |
else | |
puts "." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright (c) 2006 Spencer Janssen | |
-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html) | |
{-# LANGUAGE Rank2Types #-} | |
module Main where | |
import Control.Monad | |
import Data.Generics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :sprites do | |
originals = Rake::FileList.new('app/assets/images/**/originals/*.png') | |
resized = originals.pathmap("%{/originals$,/}d%f") | |
task resize: resized | |
end | |
from_originals = ->(tn) { | |
tn.pathmap("%d/originals/%f") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AuthHelper | |
module Feature | |
def basic_auth(login, password) | |
if page.driver.respond_to?(:basic_auth) | |
page.driver.basic_auth(login, password) | |
elsif page.driver.respond_to?(:basic_authorize) | |
page.driver.basic_authorize(login, password) | |
elsif page.driver.respond_to?(:browser) && page.driver.browser.respond_to?(:basic_authorize) | |
page.driver.browser.basic_authorize(login, password) | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/db.rake | |
namespace :db do | |
desc "Dumps the database to db/APP_NAME.dump" | |
task :dump => :environment do | |
cmd = nil | |
epoch = Time.now.to_i | |
with_config do |app, host, db, user| | |
cmd = "pg_dump --verbose #{pg_login_config(host, user)} --clean --format=c #{db} > #{Rails.root}/db/#{app}-#{epoch}.dump" | |
end | |
puts cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addEvent(element, eventName, fn) { | |
if (element.addEventListener) | |
element.addEventListener(eventName, fn, false); | |
else if (element.attachEvent) | |
element.attachEvent('on' + eventName, fn); | |
} | |
var wasEnterPressed = function(e){ | |
return e.which == 13 || e.keyCode == 13; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def batch(iterable, n=1): | |
l = len(iterable) | |
for ndx in range(0, l, n): | |
yield iterable[ndx:min(ndx+n, l)] | |
import sendwithus | |
import csv | |
max_count = 100 # keep this as or around 100 for batch requests | |
csv_location = './customers.csv' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
ActionController::Renderers.add :csv do |collection, options| | |
self.content_type ||= Mime::CSV | |
self.headers['Content-Disposition'] = "attachment; filename=#{options[:filename]}.csv" if options[:filename] | |
self.response_body = collection.to_csv | |
end | |
module CsvRenderer | |
def to_csv(options={}) |
OlderNewer