Skip to content

Instantly share code, notes, and snippets.

View nealfennimore's full-sized avatar
🎪
RGlkIHlvdSBhbHNvIGRlY29kZSB0aGlzPw==

Neal Fennimore nealfennimore

🎪
RGlkIHlvdSBhbHNvIGRlY29kZSB0aGlzPw==
View GitHub Profile
@nealfennimore
nealfennimore / javascript_hoisting.js
Created April 30, 2014 15:19
Javascript Hoisting
// hoisting
function hoisted() {
console.log(name);
}
hoisted();
// name is not defined
// -----------------
@nealfennimore
nealfennimore / execution_contexts_with_functions.js
Created April 30, 2014 15:23
Execution contexts with functions
function makeCounter(){
// "i" is only accesible within 'makeCounter'
var i = 0;
return function() {
console.log ( ++i );
};
}
// ------------------------
var counter = makeCounter();
@nealfennimore
nealfennimore / click_handler_javascript.js
Created April 30, 2014 15:43
Click Handler Javscript
// <div>
// <a href="/about">About</a>
// <a href="/home">Home</a>
// <a href="/something">Something</a>
// </div>
console.log(elements);
for (var i = 0; i < elements.length; i++) {
color= "#" + "%06x" % (rand * 0xffffff)
#require 'pry' # ruby loop evaluation
class Pokemon < ActiveRecord::Base
self.inheritance_column = nil
TYPES = %w(pokemon types array)
scope :free, -> { where (caught: false) } # Lambda
scope :captured, -> { where (caught: true) }
@nealfennimore
nealfennimore / object_oriented_javascript_christine.js
Created May 2, 2014 23:13
Object Oriented Javascript by Christine Feaster
// Class List; end
// Object constructor
function Item(name, qty) {
this.name = name;
this.qty = qty;
};
// Object literal notation
var List = {
@nealfennimore
nealfennimore / json_nested_hashes_article
Created May 3, 2014 22:59
Json and Nested Hashes article
http://www.johnkeith.us/blog/2014/04/01/json-and-nested-hashes-in-ruby/
@nealfennimore
nealfennimore / band_crud_sinatra.rb
Created May 5, 2014 15:41
All them bands - CRUD Sinatara
# PUTS and DELETE hack
# in config/environment.rb
enable :method_override, true
# -------------------------------
# <form action="/bands/<%[email protected]%>" method="post">
# #==============================================
# <input type="hidden" name="_method" value="put">
# #==============================================
# <label for="band[name]">Name</label>
# Study has_many, belongs_to methods (10 or so)
ActiveRecord::Migration.create_table :followings do |t|
t.belongs :follower
t.belong :stalked
end
ActiveRecord::Migrator.up "db/migrate"
class User < ActiveRecord::Base
@nealfennimore
nealfennimore / OOJS_Part_2.js
Created May 7, 2014 20:46
Object Oriented Javascript
function Quote(text, author) {
this.text = text;
this.author = author;
}
Quote.prototype.textCount = function() {
return this.text.length;
};
Quote.prototype.tooLong = function(){