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
class Duck | |
def quack | |
"Quack quack" | |
end | |
end | |
class Person | |
def quack | |
"Bad impression of Donald Duck" | |
end |
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 AAA | |
def abc | |
"abc in AAA" | |
end | |
def not_in_common | |
"not_in_common in AAA" | |
end | |
end |
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
# WheelType knows about the behavior of wheels | |
class WheelType | |
def diameter | |
#snip | |
end | |
def rim_size | |
#snip | |
end |
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
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 |
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 doSumByGroup() { | |
var agg = [ | |
{$group: { | |
_id: "$columnObject", | |
total: {$sum: 1} | |
}} | |
]; | |
Snippet.aggregate(agg, function(err, logs){ | |
if (err) { |
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
class CreateUsers < ActiveRecord::Migration | |
def change | |
create_table :users do |t| | |
t.string :name | |
t.string :email | |
t.timestamps null: false | |
end | |
end | |
end |
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
<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 = []; | |
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(){ | |
var loadFirstNumber = function(){ | |
return new Promise(function(resolve, reject){ | |
var request = $.ajax({ | |
method: 'get', | |
url:'/first.json', | |
}) | |
request.done(function(result){ | |
resolve(result.value); |
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
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 |
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
<!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() { |
OlderNewer