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 'date' | |
old_date = Date.new(2013,1,1) | |
new_date = Date.new(2013,2,1) | |
future_date = Date.new(2013,3,1) | |
a_month_ago = (Date.today << 1) | |
puts old_date <= a_month_ago #=> true | |
puts new_date <= a_month_ago #=> false |
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
/*** | |
* | |
* I want to execute someFunc() if the variable x is greater than 5 | |
* how would you rewrite the below to NOT use a conditional? (EG no "if" used) | |
* | |
* **/ | |
if(x > 5) { | |
someFunc(): | |
} |
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
$.getJSON('https://github.com/users/'+document.location.href.split('/')[3]+'/contributions_calendar_data', weekendWork); | |
function weekendWork(contribs) { | |
var inwe = false, streak = 0, highest = 0, total = 0, possible = 0; | |
contribs.forEach(function (c) { | |
var d = new Date(c[0]).getDay(); | |
if (d === 6) { | |
inwe = true; | |
} else if (d === 0 && inwe) { | |
possible++; | |
if (c[1] !== 0) { |
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
and' :: [Bool] -> Bool | |
and' [] = True | |
and' (x:xs) = x && and' xs | |
concat' :: [[a]] -> [a] | |
concat' [] = [] | |
concat' [[]] = [] | |
concat' (x:xs) = x ++ concat' xs | |
replicate' :: Int -> a -> [a] |
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
function archiveOld() { | |
var threads = GmailApp.search('in:inbox -is:starred older_than:7d'); | |
for (var thread in threads) { | |
GmailApp.moveThreadToArchive(threads[thread]); | |
} | |
} | |
archiveOld(); |
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
def meth(&blk) | |
foo = yield(10) | |
puts "foo was #{foo}" | |
end | |
meth do |n| | |
n * 3 | |
end | |
# => "foo was 30" |
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
class MagicObject | |
def method_missing(name, *args, &block) | |
if name =~ /greet_/ | |
puts "Haven't greeted this person before, I'll make them a greet method" | |
self.class.send(:define_method, name) do | |
puts "Yo! #{name.to_s.split('_',2)[1].gsub('_',' ')}" | |
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
class Foo < BasicObject | |
def method_missing(method, *args, &block) | |
puts "You called #{method}" | |
end | |
end | |
Foo.new.hi |
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
# Utility methods | |
flatten_nested_array = (array) -> | |
[].concat array... | |
includes = (item, coll) -> | |
item = key_to_array(item) | |
for potential_match in coll | |
return true if item[0] == potential_match[0] && item[1] == potential_match[1] | |
false |
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
#depends on underscore | |
_.isConstructor = (thing) -> | |
if thing.name && thing.name[0].toUpperCase() == thing.name[0] | |
true | |
else | |
false | |
class Instrumentor | |
constructor: (namespace) -> |