Skip to content

Instantly share code, notes, and snippets.


Filippos Vasilakis vasilakisfil

View GitHub Profile
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)
vasilakisfil /
Created Jul 20, 2020
deadpool postgres simple setup
use deadpool_postgres::tokio_postgres::NoTls;
use deadpool_postgres::{Config, ManagerConfig, Pool, PoolError, RecyclingMethod};
use once_cell::sync::Lazy;
use std::sync::Arc;
static DB_POOL: Lazy<Arc<Pool>> = Lazy::new(|| {
let mut cfg = Config::new();
cfg.dbname = Some(
.map_err(|_| String::from("Environment variable Database URL could not be read"))
vasilakisfil /
Last active Jun 11, 2020
New linux machine setup
#install essential stuff
sudo apt-get install build-essential autoconf locate
sudo apt-get install git guake zsh curl vim vim-gtk3 postgresql-client \
postgresql postgresql-contrib redis golang direnv tmux bat ripgrep fzf
curl -L | sh
chsh -s /bin/zsh
#edit pg_hba.conf
vasilakisfil /
Created Apr 4, 2020
basic error structure in Rust
use std::{error::Error as StdError, fmt};
pub struct Error {
pub kind: ErrorKind,
pub context: ErrorContext,
pub enum ErrorKind {
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
View radio-button-component.js
// {{ radio-button name='dish' value='spam' groupValue=selectedDish selectedAction='testAction' }} Spam
// {{ radio-button name='dish' value='eggs' groupValue=selectedDish }} Eggs
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: [ 'checked', 'name', 'type', 'value' ],
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)