Skip to content

Instantly share code, notes, and snippets.

View shanemcd's full-sized avatar

Shane McDonald shanemcd

  • (Ansible (Red Hat (IBM)))
  • Jersey City
View GitHub Profile
@shanemcd
shanemcd / gist:2209334
Created March 26, 2012 20:14
Populate staging server with Production DB
heroku pgbackups:restore DATABASE `heroku pgbackups:url --app instruments2` --app instruments2-staging
window.App =
Models: {}
Collections: {}
Views: {}
Routers: {}
init: (options) ->
App.project = options.project
App.question_set = options.question_set
App.router = new App.Routers.QuestionsRouter()
Backbone.history.start();
@shanemcd
shanemcd / gist:2644373
Created May 9, 2012 13:10
Kick Ass CSS "Well" Look
position: relative;
white-space: pre;
padding: 10px;
float: right;
width: 380px;
font-size: 12px;
font-family: 'Courier new';
font-weight: bold;
background: rgba(0, 0, 0, 0.15);
border-radius: 4px;
- Start Redis
redis-server /usr/local/etc/redis.conf
- Start Resque
rake resque:work QUEUE="*"
- Start Rails last
@shanemcd
shanemcd / gist:4066669
Created November 13, 2012 16:11
Benchmarks when removing duplicate items from array
require 'benchmark'
arr1 = (1..5000).to_a
arr2 = (1..10000).to_a
a = arr1.zip(arr2).flatten # 10000 items, 5000 duplicates
# with #uniq
puts Benchmark.measure { a.uniq }
# Total time
@shanemcd
shanemcd / gist:4177528
Created November 30, 2012 18:20
FizzBuzz
(1..100).to_a.map { |i|
if (i % 3 == 0 ) && (i % 5 == 0)
i = "fizzbuzz"
elsif i % 3 == 0
i = "fizz"
elsif i % 5 == 0
i = "buzz"
else
i = i
end
@shanemcd
shanemcd / gist:4217247
Created December 5, 2012 16:41
Clean up $PATH - removes duplicate directories
echo "$PATH" | /usr/bin/awk -v RS=':' -v ORS=":" '!a[$1]++'
@shanemcd
shanemcd / gist:4259171
Created December 11, 2012 15:03
modules
module Foobar
def self.foo
puts 'foo'
end
end
module Foobar
def self.bar
puts 'bar'
end
@shanemcd
shanemcd / gist:4269738
Created December 12, 2012 17:21
Require all (most) fields in Rails model
validates_presence_of(self.column_names - ["id", "created_at", "updated_at"])
class Instruments2.Views.FilterQuestionSets extends Backbone.View
template: JST['folders/filter']
id: "filter-question-sets"
className: "clearfix"
events:
"keyup input[type=text]": "filter"