View routes.rb
Rails.application.routes.draw do | |
resources :uploads, only: :show do | |
member do | |
post :download | |
end | |
end | |
end |
View routes.rb
Rails.application.routes.draw do | |
resources :uploads, only: :show | |
end |
View fork.rb
class ActiveSupport::TestCase | |
def run | |
read_io, write_io = IO.pipe | |
read_io.binmode | |
write_io.binmode | |
if fork | |
# Parent: load the result sent from the child | |
write_io.close |
View extended_formatter.rb
class Logging::ExtendedFormatter | |
def initialize(class_name, formatter) | |
@class_name = class_name | |
@formatter = formatter | |
end | |
def call(severity, datetime, progname, msg) | |
@formatter.call(severity, datetime, progname(progname), msg(msg)) | |
end |
View markdown.py
''' | |
>>> parse_markdown('This is a paragraph.') | |
Markdown([Paragraph([Text('This is a paragraph.')])]) | |
>>> parse_markdown('The first paragraph.\\n\\nThe second paragraph.') | |
Markdown([Paragraph([Text('The first paragraph.')]), Paragraph([Text('The second paragraph.')])]) | |
>>> parse_markdown('Emphasis *is* supported.') | |
Markdown([Paragraph([Text('Emphasis '), Emphasis('is'), Text(' supported.')])]) |
View super_method_proxy.rb
module Authentication | |
def login | |
puts 'Authentication#login' | |
super | |
end | |
end | |
class User | |
prepend Authentication |
View 20150521093555_create_one_time_switches.rb
class CreateOneTimeSwitches < ActiveRecord::Migration | |
def change | |
create_table :one_time_switches do |t| | |
t.string :name, null: false | |
t.timestamp :created_at, null: false | |
t.index :name, unique: true | |
end | |
end | |
end |
View insert_query.rb
class InsertQuery | |
def initialize(model_class, column_names, returning = nil) | |
@model_class = model_class | |
@column_names = column_names | |
@returning = returning | |
@rows = [] | |
@executed = false | |
end |
View polynomial.rb
class Polynomial | |
# maps e.g. {x: 1, y: 2} => 3 which corresponds to term 3 * x ** 1 * y ** 2 | |
attr_reader :coefficients | |
def initialize(coefficients = {}) | |
puts @coefficients.inspect | |
@coefficients = coefficients.reject do |_index, coefficient| | |
coefficient == 0 | |
end | |
end |
View call_tracer.py
import bdb | |
# This is a custom debugger that calls the specified handler on each function | |
# call. | |
class _CallTracerBdb(bdb.Bdb): | |
def __init__(self, call_handler, return_handler): | |
bdb.Bdb.__init__(self) | |
self._call_handler = call_handler | |
self._return_handler = return_handler |
NewerOlder