Skip to content

Instantly share code, notes, and snippets.

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
/***
*
* 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():
}
$.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) {
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]
function archiveOld() {
var threads = GmailApp.search('in:inbox -is:starred older_than:7d');
for (var thread in threads) {
GmailApp.moveThreadToArchive(threads[thread]);
}
}
archiveOld();
def meth(&blk)
foo = yield(10)
puts "foo was #{foo}"
end
meth do |n|
n * 3
end
# => "foo was 30"
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
@latentflip
latentflip / ruby.rb
Created December 7, 2012 14:41
Ruby Pop Quiz
class Foo < BasicObject
def method_missing(method, *args, &block)
puts "You called #{method}"
end
end
Foo.new.hi
@latentflip
latentflip / game_of_life.coffee
Created October 28, 2012 22:52 — forked from joejag/game_of_life.coffee
Conways Game of Life in CoffeeScript
# 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
@latentflip
latentflip / Instrumentor.coffee
Created October 27, 2012 12:21
Instrumentor
#depends on underscore
_.isConstructor = (thing) ->
if thing.name && thing.name[0].toUpperCase() == thing.name[0]
true
else
false
class Instrumentor
constructor: (namespace) ->