Skip to content

Instantly share code, notes, and snippets.

View stevecass's full-sized avatar

Steven Cassidy stevecass

  • 09:49 (UTC -04:00)
View GitHub Profile
@stevecass
stevecass / gist:d718290951618a52f9f4
Created November 25, 2014 16:24
Ancestor chaining in ruby
module AAA
def abc
"abc in AAA"
end
def not_in_common
"not_in_common in AAA"
end
end
class Duck
def quack
"Quack quack"
end
end
class Person
def quack
"Bad impression of Donald Duck"
end
@stevecass
stevecass / gist:9b555430e2bddb2004e5
Last active August 29, 2015 14:10
Composition and delegation
# WheelType knows about the behavior of wheels
class WheelType
def diameter
#snip
end
def rim_size
#snip
end
@stevecass
stevecass / array_recap.rb
Last active August 29, 2015 14:10
Ruby array recap
arr = [] # => []
arr = Array.new # => []
arr = Array.new(5, "t") # => ["t", "t", "t", "t", "t"]
arr = Array.new(5) { |i| i **2 } # => [0, 1, 4, 9, 16]
arr[3] = 'replacement' # => "replacement"
arr # => [0, 1, 4, "replacement", 16]
arr.fetch 0 # => 0
arr.first # => 0
arr.last # => 16
@stevecass
stevecass / hash_recap.rb
Last active September 4, 2020 13:24
Ruby hash recap
h1 = Hash.new # => {}
h2 = Hash.new("a") # => {}
h3 = {} # => {}
h4 = {abc: "def"} # => {:abc=>"def"}
h5 = {:abc => "def"} # => {:abc=>"def"}
h6 = {"abc" => "def"} # => {"abc"=>"def"}
h1["abc"] # => nil
h1.fetch("abc", "kitty") # => "kitty"
@stevecass
stevecass / meteor_s3_sample.js
Created March 8, 2015 04:03
Meteor and S3
/*
Prerequisite: meteor add peerlibrary:aws-sdk
Terminology:
AWS: Amazon web services
S3: Simple storage service (one of the above.)
Create a bucket on S3. Use AWS Identity and Access Manager to create
a user that your app can log in as . Attach a policy to that user
@stevecass
stevecass / gist:7084098fb1edf42ba9cd
Created March 10, 2015 17:53
Mongoose group by parent
function doSumByGroup() {
var agg = [
{$group: {
_id: "$columnObject",
total: {$sum: 1}
}}
];
Snippet.aggregate(agg, function(err, logs){
if (err) {
@stevecass
stevecass / following.rb
Last active August 29, 2015 14:19
Modelling followers
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps null: false
end
end
end
@stevecass
stevecass / rails_setup_notes.txt
Last active November 20, 2019 00:56
Starting a new rails app
#Creating an app called my_great_app
rails new my_great_app -T -d postgresql --skip-turbolinks
cd my_great_app
git init
git add .
git commit -m "Initial commit. Rails boilerplate."
# Edit gemfile
# #Remove the reference to coffee-rails.
@stevecass
stevecass / heroku_setup.txt
Created April 22, 2015 04:57
Notes on heroku / rails
This is very well documented at https://devcenter.heroku.com/articles/getting-started-with-rails4
Short version:
Download heroku tool belt and install it. Then in terminal, cd into the root folder of the app you want to deploy
In the Gemfile declare ruby version with a line like:
ruby "2.1.4"
Also add
gem 'rails_12factor', group: :production