Skip to content

Instantly share code, notes, and snippets.

View pascalbetz's full-sized avatar

Pascal Betz pascalbetz

  • Switzerland
View GitHub Profile
@pascalbetz
pascalbetz / dateperf.rb
Created May 7, 2021 14:56
Benchmark Ruby Date Operations
require "benchmark/ips"
require "date"
base = Date.new(Date.today.year)
Benchmark.ips do |x|
x.compare!
x.report("int 1") { base + (100) }
x.report("int 2") { base + (100 - 1) }
x.report("int 3") { base + (100 - 1 - 1) }
x.report("int 4") { base + (100 - 1 - 1 - 1) }
@pascalbetz
pascalbetz / benchmark.rb
Created February 14, 2016 10:30
Compare BigDecimal implementations of Hanami Utils
require 'benchmark/ips'
require 'bigdecimal'
VALUES = ['100.123', 100.123, '100', 100, Rational(1), Rational(4,1), Rational(0.3), BigDecimal.new('758.3'), 13289301283 ** 2, 0xf5]
module Hanami
module Utils
module Kernel
NUMERIC_MATCHER = /\A([\d\/\.\+iE]+|NaN|Infinity)\z/.freeze
def self.BigDecimalGem(arg)
@pascalbetz
pascalbetz / case.rb
Created February 10, 2016 10:12
Benchmark of Case/If
require 'benchmark/ips'
thing = 102
Benchmark.ips do |x|
x.report('block') do
case thing
when -> (a) { a < 100 && a.even? } then 1
when -> (a) { a > 100 && a.odd? } then 2
else 3
end
## View Hierarchy
Web::Views::Home::WithPartial
Web::Views::Home::AnotherSubclass < Web::Views::Home::WithPartial
## Add some debug code
# in view/rendering/registry.rb
def initialize(*args)
puts "Creating registry #{object_id} for #{args}"
require 'uri'
require 'pry'
module Lotus
module Helpers
# Helper methods to generate asset-paths
#
# @since 0.6.0
# @api public
@pascalbetz
pascalbetz / gist:c5f9967d64b082fe97cf
Created January 27, 2015 21:32
Wordpress Code Highlighting
[code language="ruby"]
puts "hello world"
[/code]
@pascalbetz
pascalbetz / marshalling.rb
Created July 8, 2013 07:39
Executable Testcase for https://github.com/rails/rails/issues/8020#issuecomment-19958061 Note that this bug is gone in AR 4.0.0
gem 'activerecord', '3.2.13'
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
@pascalbetz
pascalbetz / gist:1778441
Created February 9, 2012 08:26
Failing Withings Call
require 'rubygems'
require 'withings'
include Withings
Withings.consumer_secret = 'ABCD'
Withings.consumer_key = 'EFGH'
user_id = 12345
token = '5678'