Skip to content

Instantly share code, notes, and snippets.

View srt32's full-sized avatar

Simon Taranto srt32

  • GitHub
  • WORLD
  • 19:26 (UTC -05:00)
View GitHub Profile
@srt32
srt32 / gist:6076872
Created July 25, 2013 04:16
output of rake routes
Prefix Verb URI Pattern Controller#Action
events_summary GET /events/summary(.:format) events#summary
event_attendees GET /events/:event_id/attendees(.:format) attendees#index
POST /events/:event_id/attendees(.:format) attendees#create
new_event_attendee GET /events/:event_id/attendees/new(.:format) attendees#new
edit_event_attendee GET /events/:event_id/attendees/:id/edit(.:format) attendees#edit
event_attendee GET /events/:event_id/attendees/:id(.:format) attendees#show
PATCH /events/:event_id/attendees/:id(.:format) attendees#update
PUT /events/:event_id/attendees/:id(.:format) attendees#update
DELETE /events/:event_id/attendees/:id(.:format) attendees#destroy
@srt32
srt32 / gist:6433024
Created September 4, 2013 05:19
Full console error output
2.0.0p247 :001 > rake nagging_email:send
ArgumentError: no method name given
from (irb):1
from /Users/Simon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
from /Users/Simon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
from /Users/Simon/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
@srt32
srt32 / gist:7254914
Last active December 27, 2015 02:49
responding to the first commenter's idea from http://codeulate.com/2012/07/depend-upon-abstractions/
# app/models/user.rb
class User
attr_reader :payment_gateway
def initialize
@payment_gateway = PaymentGateway::Braintree.new
end
def charge_for_subscription
@srt32
srt32 / gist:8031051
Created December 18, 2013 22:34
fourthmeal#transactions_controller refactor process Blog post about it: http://www.simontaranto.com/2013/12/11/it-all-comes-together-ruby-js-and-functional-programming.html
Before:
def create
@transaction = current_order.build_transaction(transaction_params)
@transaction.update(:order_id => current_order.id)
if @transaction.save
@transaction.pay!
if current_user
current_order.update(:user_id => current_user.id, :status => "paid")
else
current_order.update(:status => "paid")
@srt32
srt32 / gist:8535548
Created January 21, 2014 06:59
nginx.conf file for running multiple apps using passenger
#user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@srt32
srt32 / fizzbuzz.rb
Created January 22, 2014 03:52
Fizzbuzz with no ifs
class Fizzbuzz < Struct.new(:max)
MUTATIONS = {
'fizzbuzz' => ->(i) {i % 3 == 0 && i % 5 == 0},
'fizz' => ->(i) {i % 3 == 0},
'buzz' => ->(i) {i % 5 == 0}
}
def fizzle
1.upto(max).map do |i|
mutations.find(-> {[i]}) do |k, v|
@srt32
srt32 / gist:8673881
Last active January 4, 2016 20:29
writing code in a notepad :(
"1001" + "11" ---> "1100"
"1" + "1" ---> "10"
def add(number_one, number_two)
# "1011"
# "1111"
# 1110"
ones_digit = number_one[-1]
result = ""
@srt32
srt32 / gist:9791005
Created March 26, 2014 19:14
sample_output updated
title: Filters
output: basic.html
controls: true
--
# Filters
## Controllers
--
@srt32
srt32 / benchmark_funds.rake
Last active August 29, 2015 13:59
benchmark_funds.rake_v0
desc 'Benchmark funds_raised methods'
ITERATIONS = 100_000
task benchmark_sql: :environment do
GC.disable
campaign = Campaign.last
Benchmark.bm do |bm|
bm.report('sql') do
@srt32
srt32 / benchmark_funds.rake
Created April 14, 2014 22:28
benchmarks for map/inject vs SQL sum. See the sample app here: https://github.com/srt32/benchmarks_example
desc 'Benchmark funds_raised methods'
ITERATIONS = 1000
task benchmark_sql: :environment do
campaign = Campaign.last
Benchmark.bm do |bm|
bm.report('sql') do
ITERATIONS.times do