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
Shoes.app :width => 600, :height => 400 do | |
flow :width => 400, :height => 400, :margin => 20 do | |
fill '#dfd' | |
stroke '#ddd' | |
rect 0, 0, 200, 200 | |
background white | |
end | |
background black |
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 track_sql(&block) | |
timing = Hash.new 0 | |
track = ->(_,start,finish,_,data) do | |
Thread.exclusive do | |
timing[data[:name]] += (finish - start) | |
end | |
end | |
ActiveSupport::Notifications.subscribed(track, 'sql.active_record', &block) | |
timing |
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
# rails 3.X patch to remove extra allocations on field access | |
module ActiveRecord::AttributeMethods::Read::ClassMethods | |
def internal_attribute_access_code(attr_name, cast_code) | |
access_code = "(v=@attributes[attr_name]) && #{cast_code}" | |
unless attr_name == primary_key | |
access_code.insert(0, "missing_attribute(attr_name, caller) unless @attributes.has_key?(attr_name); ") | |
end | |
if cache_attribute?(attr_name) |
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 method_calls(detailed: false, thread: nil) | |
[].tap do |log| | |
ident = -1 | |
trace = TracePoint.new(:call, :return, :c_call, :c_return) do |tp| | |
break if thread and thread != Thread.current | |
case tp.event | |
when :call, :c_call | |
if tp.event == :call or detailed | |
ident += 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
Gem::Specification.new do |s| | |
s.name = 'docs' | |
s.version = '0.0.1' | |
s.files = ['docs.rb'] | |
s.require_path = '.' | |
s.add_dependency('swagger-ui_rails', ">= 2.1.0.alpha.7.1") | |
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
# This class is used to render jbuilder templates in grape. | |
# | |
# There is an existing grape-jbuilder gem but it depends | |
# on tilt-jbuilder gem which | |
# - does not support partial! with :collection | |
# - does not support template compilation | |
# | |
# In constrast this template handler supports all features of jbuilder | |
# and uses template compilation (5x-10x times faster than without). | |
class Tilt::Jbuilder < Tilt::Template |
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 Docs | |
def self.extended(version) | |
version.include Swagger::Blocks | |
end | |
def root | |
Swagger::Blocks.build_root_json [self] | |
end | |
concerning :App 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
class String | |
def -@ | |
'unary minus redefined' | |
end | |
end | |
-"foobar" # => 'unary minus redefined' |
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 'forwardable' | |
module SingletonCollection | |
module Methods | |
extend Forwardable | |
def_delegators :@storage, *Array.instance_methods(inherited=false) | |
attr_accessor :current_index | |
def current |
OlderNewer