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 currySumRecursive(n, sum) { | |
//sum will not be passed in on the first call | |
// so we set it to 0. | |
if(sum === undefined) { | |
sum = 0; | |
} | |
//if this is the last recursive call | |
// return a simple function that returns |
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 Tracker | |
@tracked_items = [] | |
def initialize | |
Tracker.tracked_items << self | |
end | |
def self.tracked_items | |
@tracked_items | |
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
class Tracker | |
@tracked_items = [] | |
def initialize | |
Tracker.tracked_items << self | |
end | |
def self.tracked_items | |
@tracked_items | |
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
def my_curry_sum x # x= number of times to curry | |
sum = 0 | |
# this will not work with a proc as a proc will return | |
# out of the my_curry_sum method | |
sum_prc = lambda do |n| | |
sum += n | |
x -= 1 | |
return sum if x == 0 | |
return sum_prc |
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
<div class="container"> | |
<h3>My Boards | |
<a class="pull-right" href="#"><small>New Board...</a></small> | |
</h3> | |
<ul class="list-group"> | |
<% boards.each(function (b) { %> | |
<li class="list-group-item"> |
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
resources :traders { resources :notes } | |
resources :companies { resources :notes } | |
# need condition for each polymorphic type | |
if (params[:trader_id]) | |
@notes = Trader.find(params[:trader_id]).notes | |
elsif (params[:company_id]) | |
@notes = Company.find(params[:company_id]).notes | |
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
# my solution | |
get '/:notable_type/:noteable_id/notes', to: "notes#index" | |
@notes = Note.find_by_noteable_id_and_noteable_type(params[:notable_id], params[:notable_type]) | |
# notice how it doesn't matter if an invalid :notable_type is used because it will just return an empty collection of notes | |
# railscast solution, but doesn't catch case with nesting more than 2 deep... | |
def find_noteable | |
params.each do |name, value| | |
if name =~ /(.+)_id$/ | |
return $1.classify.constantize.find(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
.titanic { | |
float: none; | |
width: 50%; | |
} |
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
pages/* | |
episode_pages/* | |
videos/* | |
cookies.txt |
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 TowersOfHanoi { | |
def Play(towers: List[List[Int]] = List(List(1, 2, 3), List[Int](), List[Int]())) { | |
Display(towers) | |
if(GameOver(towers)) { | |
println("You win!") | |
return | |
} | |
val from = GetMoveTower("Pick a from tower"); | |
val to = GetMoveTower("Pick a to tower"); | |
val moveResult = Move(from, to, towers) |
OlderNewer