This file contains hidden or 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
| // hoisting | |
| function hoisted() { | |
| console.log(name); | |
| } | |
| hoisted(); | |
| // name is not defined | |
| // ----------------- |
This file contains hidden or 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 makeCounter(){ | |
| // "i" is only accesible within 'makeCounter' | |
| var i = 0; | |
| return function() { | |
| console.log ( ++i ); | |
| }; | |
| } | |
| // ------------------------ | |
| var counter = makeCounter(); |
This file contains hidden or 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
| // <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++) { |
This file contains hidden or 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
| color= "#" + "%06x" % (rand * 0xffffff) |
This file contains hidden or 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
| #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) } | |
This file contains hidden or 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 List; end | |
| // Object constructor | |
| function Item(name, qty) { | |
| this.name = name; | |
| this.qty = qty; | |
| }; | |
| // Object literal notation | |
| var List = { |
This file contains hidden or 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
| http://www.johnkeith.us/blog/2014/04/01/json-and-nested-hashes-in-ruby/ |
This file contains hidden or 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
| # 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> |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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 Quote(text, author) { | |
| this.text = text; | |
| this.author = author; | |
| } | |
| Quote.prototype.textCount = function() { | |
| return this.text.length; | |
| }; | |
| Quote.prototype.tooLong = function(){ |