Skip to content

Instantly share code, notes, and snippets.

Filippos Vasilakis vasilakisfil

Block or report user

Report or block vasilakisfil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
vasilakisfil / timing_benchmark.rb
Created Feb 27, 2019
simple timing/benchmark mechanism for Ruby
View timing_benchmark.rb
class TimingBenchmark
def measure(label, &block)
@label_times ||= {}
start =
result =
@label_times[label] = - start
return result
vasilakisfil / hash_first.rb
Created Nov 16, 2018
Accessing a hash value by key is extremely fast. Is it possible to access the value of the first key with the same performance ?
View hash_first.rb
require 'benchmark/ips'
require 'faker'
_hash = 100.times.inject({}){|hash, i|
hash[Faker::Lorem.word] = Faker::Lorem.word
_hash[:aaa] = 'a'
HASH = _hash
vasilakisfil / performance.rb
Created Sep 23, 2018
instance_exec vs args in a lambda
View performance.rb
require 'bundler/setup'
class Serializer
def user_path(id)
class User
vasilakisfil / decorators.rb
Last active Dec 21, 2017
Decorator strategies battletested. Original script:
View decorators.rb
#ENV: Ruby 2.4.1, a i7-6700HQ CPU, 16GB RAM
require 'benchmark'
require 'delegate'
require 'forwardable'
class Person
def initialize(name)
@name = name
vasilakisfil / nested_controllers.rb
Created Oct 24, 2017
A module for creating UI controllers in Rails
View nested_controllers.rb
module NestedControllers
CALLBACKS_OPTS = [:filter, :if, :unless, :kind].freeze
#adds the relative paths to controller so you can do `render 'subcontroller/something'`
#instead of `render 'parent_controller/subcontroller/something'`
#(solves 2)
def self.extended(base)
vasilakisfil / file.rb
Created Oct 4, 2017
Weird Ruby behavior on private method
View file.rb
class Foobar
def run!
self.foobar = 'test' #doesn't fail?
hey = self.foobar #bang! fails
attr_accessor :foobar
vasilakisfil / flash_hash.rb
Created Jun 1, 2017
Rails flash improvements
View flash_hash.rb
module ActionDispatch
class Flash
class FlashHash
# Returns a hash that includes everything but the given keys.
# hash = { a: true, b: false, c: nil}
# hash.except(:c) # => { a: true, b: false}
# hash # => { a: true, b: false, c: nil}
# This is useful for limiting a set of parameters to everything but a few known toggles:
# @person.update(params[:person].except(:admin))
View gist:0186bea379ed80fefe40c7638512c5c3
pi@raspberrypi:~ $ crystal
/opt/crystal/embedded/bin/crystal: /lib/arm-linux-gnueabihf/ no version information available (required by /opt/crystal/embedded/bin/crystal)
/opt/crystal/embedded/bin/crystal: /usr/lib/arm-linux-gnueabihf/ version `GLIBCXX_3.4.21' not found (required by /opt/crystal/embedded/bin/crystal)
vasilakisfil / .eslintrc
Created Apr 27, 2017
eslint defaults..
View .eslintrc
"extends": "airbnb",
"env": {
"browser": true
"rules": {
"no-underscore-dangle": 0,
"class-methods-use-this": 0,
"arrow-body-style": 0,
"no-console": 0,
vasilakisfil / test.rb
Created Sep 3, 2016
Ruby calling method performance
View test.rb
require 'benchmark/ips'
class Foo
def bar; end
foo =
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
You can’t perform that action at this time.