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
# Fibonacci numbers WITH memoization. | |
# Initialize the memoization array. | |
@scratchpad = [] | |
# Calculate the nth Fibonacci number, f(n). | |
def fibo(n) | |
if n <= 1 | |
n | |
else |
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
@main = -> | |
canvas = document.getElementsByTagName("canvas")[0] | |
gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl") | |
compiler = new WebGLCompiler(gl, window.shaders) | |
program = compiler.createProgramWithShaders("main_vertex", "main_fragment") | |
gl.clearColor(1.0, 1.0, 1.0, 1.0) | |
gl.clear(gl.COLOR_BUFFER_BIT) | |
gl.useProgram(program) |
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
require 'redis' | |
module Features | |
class << self | |
extend Forwardable | |
def_delegators :rollout, :active?, :activate_user, :deactivate_user, :activate, :deactivate | |
private | |
def rollout | |
@rollout ||= begin |
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 SomeBusinessCase | |
include Wisper | |
def execute(attributes) | |
if true | |
publish(:some_business_case_successful, details) | |
else | |
publish(:some_business_case_failed, details) | |
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 SomeService | |
def call | |
call_service_a | |
end | |
private | |
def service_a | |
# ... uses status objects | |
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
require 'benchmark' | |
ActiveRecord::Base.logger = nil | |
Benchmark.bmbm do |bench| | |
bench.report("SQL query") do | |
1000.times { Whatever.count } | |
end | |
bench.report("exception hit") do |
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
require 'openssl' | |
require 'net/http' | |
require 'net/https' | |
module CloudFront | |
extend self | |
def invalidate(path) | |
date = Time.now.utc | |
date = date.strftime("%a, %d %b %Y %H:%M:%S %Z") |
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 JQueryEventsHelpers | |
def trigger_change(jQuerySelector) | |
script = "$('#{jQuerySelector}').trigger('change');" | |
page.execute_script(script); | |
end | |
end | |
World(JQueryEventsHelpers) |
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 view_css | |
path = "views/#{params[:controller]}/#{params[:action]}" | |
stylesheet_link_tag(path) unless Rails.application.assets.find_asset(path).nil? | |
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
#somewhere in a controller | |
CreateOrder.new(OrderRepository).create current_user, params | |
# where | |
class CreateOrder < UseCaseService | |
def initialize order_repo | |
@order_repo = order_repo |
OlderNewer