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 MyView < Mustache | |
def cache_by_user_id | |
lambda do |text| | |
cache_key = "user:#{current_user.id}" | |
if value = $cache.get(cache_key) | |
value | |
else | |
rendered = render(text) | |
$cache.set(cache_key, rendered) |
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 Enumerable | |
def toggle_boolean | |
is_even = false | |
map{|object| | |
is_even = !is_even | |
is_even | |
} | |
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
module Enumerable2 | |
def map2 | |
new_array = [] | |
each{|item| new_array << yield(item)} | |
return new_array | |
end | |
end | |
class Array | |
include Enumerable2 |
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 TaskList | |
def initialize | |
@tasks = [] | |
end | |
def add(task) | |
@tasks << task | |
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
class TaskList | |
def initialize | |
@tasks = [] | |
end | |
def add(task) | |
@tasks << task | |
end | |
def each |
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 TaskList | |
include Enumerable | |
def initialize | |
@tasks = [] | |
end | |
def add(task) | |
@tasks << task | |
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 TaskList | |
include Enumerable | |
def initialize | |
@tasks = [] | |
end | |
end | |
class TaskList | |
def add(task) |
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 run(cmdline=ARGV) | |
name, *args = cmdline | |
name &&= name.to_sym | |
name, *args = :main, name, *args unless COMMANDS[name] | |
Commandant.call name.to_sym, args.compact | |
end | |
module_function :run |
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
SELECT "drawings".* FROM "drawings" | |
INNER JOIN "assignment_tag_drawings" ON ("drawings"."id" = "assignment_tag_drawings"."drawing_id") | |
INNER JOIN "assignment_tags" ON ("assignment_tags"."id" = "assignment_tag_drawings"."assignment_tag_id") | |
WHERE (drawings.assignment_id = 12 | |
AND assignment_tags.umbrella_category_id in ('29')) | |
GROUP BY drawings.id | |
HAVING count(DISTINCT umbrella_category_id) = 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
def factorial_recursive(n) | |
return 1 if n == 0 # base case | |
n *= factorial(n - 1) #recursion | |
end | |
def factorial_iterative(n) | |
(1..n).reduce(:*) | |
end |