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 Github | |
require 'open-uri' | |
attr_accessor :user_id, :repo, :branch, :api | |
def initialize(user, repo, branch, api = "http://github.com/api/v2/json") | |
@user_id = user | |
@repo = repo | |
@branch = branch | |
@api = api |
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
-module(tail_recursion). | |
-export([tail_bump/1, tail_sum/1, tail_fact/1, tail_len/1]). | |
tail_bump(List) -> tail_bump(List,[]). | |
tail_bump([], Acc) -> lists:reverse(Acc); | |
tail_bump([H|T], Acc) -> tail_bump(T, [H+1|Acc]). | |
tail_sum(List) -> tail_sum(List, 0). | |
tail_sum([],Acc) -> Acc; | |
tail_sum([H|T], Acc) -> tail_sum(T, H + Acc). |
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
-module(direct_recursion). | |
-export([bump/1, average/1, sum/1, len/1, factorial/1, even/1, member/2, sum_boundary/1, sum_interval/2, reverse_create/1]). | |
% Add 1 to each value in a List, we could use list comprehensions of course but this is fun!! | |
bump([]) -> []; | |
bump([H|T]) -> [H + 1| bump(T)]. | |
average([])-> 0; | |
average(List) -> sum(List)/len(List). |
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 multiplier(x) | |
lambda { |n| x * n } | |
end | |
# mult2 = multiplier(2) # returns Proc object | |
# mult2.call(3) # 6 |
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
// usage : mult2 = multiplier(2) ; mult2(3) gives you 6 | |
// usage : mult3 = multiplier(3) | |
var multiplier = function(x){ | |
return function(y){ | |
return x * y; | |
} | |
}; |
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 make_a_sound(obj) | |
obj.sound! | |
end | |
def catch_make_a_sound(obj) | |
return obj.sound! if obj.respond_to? sound! | |
"#{obj.name} does not make a sound!!" | |
end | |
class Mouse |
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
//Based on Crockford's Private Members in JavaScript post.. | |
var myObject = { | |
name : "Edmore", | |
age : 28, | |
next_year : function(){ // method | |
return this.age += 1; | |
} | |
}; |
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
var person = function(spec){ | |
var that = {}; | |
that.getName = function(){ | |
return spec.name; | |
}; | |
that.getSex = function(){ | |
return spec.sex; | |
}; |
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 last_commit_message | |
with_commits_list { |o| o["commits"] ? o["commits"][0]["message"] : o } | |
end | |
def last_commit_date | |
with_commits_list do |o| | |
o["commits"] ? DateTime.parse(o["commits"][0]["committed_date"]).strftime("%d %B %Y %I:%M%p") : o | |
end | |
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 last_commit_message | |
output = parsed_json(list_commits) | |
output["commits"] ? output["commits"][0]["message"] : output | |
end | |
def last_commit_date | |
output = parsed_json(list_commits) | |
output["commits"] ? DateTime.parse(output["commits"][0]["committed_date"]).strftime("%d %B %Y %I:%M%p") : output | |
end |
OlderNewer