Skip to content

Instantly share code, notes, and snippets.

View brookr's full-sized avatar
💭
🚀

Brook R brookr

💭
🚀
View GitHub Profile
var countdown = function() {
var index;
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
@brookr
brookr / gist:2002589
Created March 8, 2012 18:40
JS Master Class assignment #1
var Card = {
isValid: function(strum) {
var sum = 0, mul = 1, length = strum.length, digit, tproduct
forEach(c in strum.slice(0,17)) {
digit = CC.substring(length-i-1,length-i);
tproduct = parseInt(digit ,10)*mul;
sum += (tproduct >= 10 ? (tproduct % 10) + 1 : tproduct)
mul += (mul == 1 ? 1 : -1)
}
@brookr
brookr / existential_rails.irb
Created October 19, 2011 05:42
Comparison of existential checks in Rails
# Does it have substance? Use .blank? or .present?, it's opposite:
>> " ".blank?
=> true
>> nil.blank?
=> true
>> [].blank?
=> true
>> nil.present?
=> false
>> [].present?
@brookr
brookr / suspenders-attempt.log
Created August 19, 2011 23:16
Console log of attempting to create a Rails app with Suspenders
Last login: Fri Aug 19 15:43:53 on ttys006
You have new mail.
Fri Aug 19 15:44:57 brookr@pridwen.local:~ > ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
Fri Aug 19 15:44:59 brookr@pridwen.local:~ > rvm list
rvm rubies
Fri Aug 19 15:45:03 brookr@pridwen.local:~ > rvm install 1.9.2
class NilClass
def method_missing(method, *args, &block)
nil
end
end
@brookr
brookr / FakerCalData.rb
Created November 15, 2009 06:41 — forked from carlosdavis/gist:225567
Fake CalHawk Data
gem 'faker'
require 'faker'
I18n.reload!
account_id = 4
# Makes a bunch of different types of events per day at a random time during work hours
(30.days.ago.to_date..90.days.from_now.to_date).each do |date|
rand(3).times do
start = date.beginning_of_day + 8.hours + (rand(32) * 15).minutes
def load_sql_file(file)
config = ActiveRecord::Base.configurations[RAILS_ENV]
database = config['database']
user = config['username']
puts `psql -U #{user} -f #{file} #{database}`
end
desc 'Load an SQL file'
task :load_sql => [ENV['FILE'], :environment] do |t|
file = ENV['FILE']
require 'rubygems'
require 'utility_belt'
require 'wirble'
class Object
def local_methods
(methods - Object.instance_methods).sort
end
end
gem 'faker'
require 'faker'
# Clean out what is there
# Makes a bunch of different types of events per day at a random time during work hours
account_id ||= 1
(30.days.ago.to_date..90.days.from_now.to_date).each do |date|
rand(5).times do
start = date.beginning_of_day + 8.hours + (rand(32) * 15).minutes
require File.dirname(__FILE__) + '/../test_helper'
class SurveysControllerTest < ActionController::TestCase
context 'GET to index' do
setup do
@staff = Factory(:staff)
session['staff'] = @staff.id
get :index
end