Skip to content

Instantly share code, notes, and snippets.

@panthomakos
panthomakos / Gemfile
Created August 8, 2019 04:50
suggest-typed and todo hang
gem 'sorbet'
@panthomakos
panthomakos / Gemfile
Created January 10, 2017 01:27
Hanami Model Primary Key Exception
source 'https://rubygems.org'
gem 'sqlite3'
gem 'hanami-model'
@panthomakos
panthomakos / Gemfile
Created December 13, 2016 23:48
mapping (Hanami::Model::Error)
source 'https://rubygems.org'
gem 'sqlite3'
gem 'hanami-model'
@panthomakos
panthomakos / keybase.md
Created March 19, 2014 23:41
keybase.io

Keybase proof

I hereby claim:

  • I am panthomakos on github.
  • I am pan (https://keybase.io/pan) on keybase.
  • I have a public key whose fingerprint is A2C6 17A6 4D65 2854 1240 7843 39F8 C7AA 10D9 15ED

To claim this, I am signing this object:

@panthomakos
panthomakos / Gemfile
Created October 18, 2012 18:30
Guard-Yard Example
source "http://rubygems.org"
gem 'guard-yard'
gem 'rb-fsevent', :require => false
@panthomakos
panthomakos / benchmark.rb
Created May 3, 2012 20:06
Benchmark Your Bundle
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@panthomakos
panthomakos / benchmark.rb
Created March 12, 2012 06:16
Rails ActiveSupport::Autoload Benchmark
# Rails 3.2 @ d5d241cb2c696f13e2c16efca0d24565a6e1c0a5
require 'active_support/dependencies/autoload'
require 'benchmark'
GC.disable
FILES = (1..1_000_000).map do |file|
["Base#{file}".to_sym, "base/#{file}"]
end
@panthomakos
panthomakos / gil.rb
Created February 5, 2012 02:16
Ruby - Threading and the GIL
require 'benchmark'
require 'mysql2'
x = Mysql2::Client.new
y = Mysql2::Client.new
Benchmark.bm do |b|
b.report('w/o') do
x.query("SELECT SLEEP(1)")
y.query("SELECT SLEEP(1)")
@panthomakos
panthomakos / user_presenter_spec.rb
Created January 26, 2012 21:29
Simplified Version of user_presenter_spec.rb from DestroyAllSoftware
class Module
alias :let :define_method
end
UserPresenter = Struct.new(:user) do
let(:full_name){ [user.first_name, user.last_name].join(' ') }
end
describe UserPresenter do
let(:user){ stub(:user, :first_name => 'Bob', :last_name => 'Smith') }
@panthomakos
panthomakos / group.rb
Created September 20, 2011 23:09
Improved Custom Error Messages in Ruby
class Group
module Error
class Standard < StandardError; end
class AlreadyAMember < Standard; end
class NotPermittedToJoin < Standard; end
end
def join user
raise Error::NotPermittedToJoin unless self.permitted?(user)
raise Error::AlreadyAMember if self.member?(user)