Skip to content

Instantly share code, notes, and snippets.

View cjavdev's full-sized avatar
👉

CJ Avilla cjavdev

👉
View GitHub Profile
@cjavdev
cjavdev / currySum
Created June 24, 2013 05:03
I've been working on the curriedSum exercise from intro-js/arguments.md. I've got the following recursive solution working, but not sure how the iterative version is supposed to work.
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
class Tracker
@tracked_items = []
def initialize
Tracker.tracked_items << self
end
def self.tracked_items
@tracked_items
end
class Tracker
@tracked_items = []
def initialize
Tracker.tracked_items << self
end
def self.tracked_items
@tracked_items
end
@cjavdev
cjavdev / my_curry_sum.rb
Created July 17, 2013 03:56
Ruby my_curry_sum demonstrating closures.
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
@cjavdev
cjavdev / gist:6419154
Created September 3, 2013 02:40
div/a => ul/li
<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">
@cjavdev
cjavdev / gist:6546728
Created September 13, 2013 04:15
polymorphic routes problem
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
@cjavdev
cjavdev / gist:6546895
Created September 13, 2013 04:56
first crack at a nested route for polymorphic association
# 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)
@cjavdev
cjavdev / cool css
Created January 10, 2014 17:03
some awesome css
.titanic {
float: none;
width: 50%;
}
pages/*
episode_pages/*
videos/*
cookies.txt
@cjavdev
cjavdev / towers.scala
Created January 15, 2015 21:42
Towers of Hanoi in scala
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)