Skip to content

Instantly share code, notes, and snippets.

View stevecass's full-sized avatar

Steven Cassidy stevecass

  • 15:30 (UTC -04:00)
View GitHub Profile
class Duck
def quack
"Quack quack"
end
end
class Person
def quack
"Bad impression of Donald Duck"
end
@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
@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 / 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 / gist:586957197295028635d6
Created June 1, 2015 19:32
Using twitter-typeahead-rails
<input class="typeahead">
<script>
var substringMatcher = function(states) {
return function findMatches(q, cb) {
var matches, substringRegex;
// an array that will be populated with substring matches
matches = [];
(function(){
var loadFirstNumber = function(){
return new Promise(function(resolve, reject){
var request = $.ajax({
method: 'get',
url:'/first.json',
})
request.done(function(result){
resolve(result.value);
@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
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
</head>
<body id="body">
<button>Click me and watch the console</button>
<script>
function f() {