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
| all_floors = ["sb", "b", "one", "two", "three"] | |
| start = "one" | |
| up_and_downs = [all_floors.take(all_floors.find_index(start)), all_floors.drop(all_floors.find_index(start))] |
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
| //basic | |
| function movieTicketMaker(movieName) { | |
| return function(movieGoer){ | |
| console.log("Here\'s your ticket for " + movieName + ".\n" + "Enjoy the show " + movieGoer + " !"); | |
| } | |
| } | |
| var star_wars = movieTicketMaker("Star Wars"); | |
| var rev_of_nerds = movieTicketMaker("Revenge of the Nerds"); | |
| var spectre = movieTicketMaker("Spectre"); |
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
| // this function since its declared, is loaded into memory as soon as program runs | |
| // it is loaded in memory and held there until you want to use it. | |
| function pythagoras (a, b) {return (a * a) + (b * b);} | |
| // function expressions apply things a little bit differently | |
| // this loads ONLY when this particular line of code is reached inside your program | |
| var pthgrs = function pythagorasFuncExpress(a, b) { | |
| return (a * a) + (b * b); | |
| }; //note, since this is an expression, we need a semicolon | |
| // call it this way -> pthgrs(3, 4); |
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
| # gem install looksee | |
| # in pry | |
| require 'looksee' | |
| animal = "cat" | |
| animal.ls | |
| # => ... | |
| require 'awesome_print' |
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
| # example usage | |
| ? <=> ? returns any one of these values [-1, 0, 1] | |
| 3 <=> 4 #=> -1, in this case, less_than (-1 is less than 0) | |
| 4 <=> 4 #=> 0, in this case, equal (0 is eq to 0) | |
| 5 <=> 4 #=> 0, in this case, greater_than (1 is greater than 0) | |
| # implementation with sort | |
| names = %w[tony steve andy tammy linda] | |
| alphabetical_names = names.sort | |
| #=>["andy", "linda", "steve", "tammy", "tony"] |
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 data-hook="envelope_stamps"> | |
| <%= collection_select(:envelope, :stamp_id, @stamps, :id, :stamp_name_sku, {selected: envelope.stamp_id, include_blank: "Please select a stamp"}, { class: 'select2', envelope_id: envelope.id}) %> | |
| </div> |
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
| reflections = Spree::Order.reflect_on_all_associations | |
| reflections.each do |reflection| | |
| puts ":#{reflection.macro} => :#{reflection.name}" | |
| end |
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
| blah = if_this_is_a_true_value ? then_the_result_is_this : else_it_is_this |
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 'rubygems' | |
| require 'nokogiri' | |
| require 'open-uri' | |
| # require 'pry' | |
| url = "http://www.amazon.com/s/ref=nb_sb_ss_i_0_9?url=search-alias%3Daps&field-keywords=patterns%20of%20enterprise%20application%20architecture&sprefix=patterns+%2Caps%2C251&rh=i%3Aaps%2Ck%3Apatterns%20of%20enterprise%20application%20architecture" | |
| doc = Nokogiri::HTML(open(url)) | |
| first_three_books = doc.css("#result_3 , #result_2 , #result_1 , #result_0 , .red") |
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
| words = %w[Had eggs for breakfast] | |
| # conventions | |
| # do/end if the block does something | |
| words.each do |word| | |
| puts word | |
| end | |
| # braces if you're just going to use its return value | |
| backwards_word = words.map {|word| word.reverse} |