Skip to content

Instantly share code, notes, and snippets.

View marka2g's full-sized avatar
🎯
Focusing

Mark Sadegi marka2g

🎯
Focusing
View GitHub Profile
@marka2g
marka2g / up_down_floors
Last active December 17, 2015 03:16
Elevator - Spilt an array on an element
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))]
@marka2g
marka2g / closures.js
Last active November 19, 2015 15:53
Javascript Closures
//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");
@marka2g
marka2g / js_function_expression_notes.js
Last active November 12, 2015 03:07
js3 - function expression notes
// 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);
@marka2g
marka2g / rubyist.rb
Created November 10, 2015 03:13
Show the Ruby Object Model Ecosystem in Pry
# gem install looksee
# in pry
require 'looksee'
animal = "cat"
animal.ls
# => ...
require 'awesome_print'
@marka2g
marka2g / spaceship.rb
Last active November 10, 2015 02:05
Spaceship Operator - Combined Compararison Operator
# 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"]
<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>
@marka2g
marka2g / reflect_associations_on_model.rb
Created July 10, 2015 00:35
Show ActiveRecord Associations
reflections = Spree::Order.reflect_on_all_associations
reflections.each do |reflection|
puts ":#{reflection.macro} => :#{reflection.name}"
end
@marka2g
marka2g / ruby_ternary.rb
Created October 23, 2014 05:13
Ruby Terinary
blah = if_this_is_a_true_value ? then_the_result_is_this : else_it_is_this
@marka2g
marka2g / scrappy_coco.rb
Created April 30, 2014 19:50
scraping internets
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")
@marka2g
marka2g / ruby_blocks
Last active December 22, 2015 03:08
Ruby Blocks - Yield - Yield Return Value P1L6
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}