Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View vasilakisfil's full-sized avatar

Filippos Vasilakis vasilakisfil

View GitHub Profile
@vasilakisfil
vasilakisfil / run.sh
Last active February 16, 2024 09:05
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 http://install.ohmyz.sh | sh
chsh -s /bin/zsh
zsh
#edit pg_hba.conf
@vasilakisfil
vasilakisfil / deadpool_postgres.rs
Created July 20, 2020 11:48
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(
std::env::var("DATABASE_URL")
.map_err(|_| String::from("Environment variable Database URL could not be read"))
@vasilakisfil
vasilakisfil / duplex.rs
Last active August 17, 2022 16:28
Duplex channel using tokio constructs
use tokio::sync::mpsc::{self, Receiver, Sender};
use tokio_stream::wrappers::ReceiverStream;
use tokio_util::sync::{PollSendError, PollSender};
use std::pin::Pin;
use std::task::{Poll, Context};
pub struct Duplex<T: Send + 'static> {
channel1: Channel<T>,
channel2: Channel<T>,
}
@vasilakisfil
vasilakisfil / test.rb
Created September 3, 2016 14:39
Ruby calling method performance
require 'benchmark/ips'
class Foo
def bar; end
end
foo = Foo.new
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
@vasilakisfil
vasilakisfil / error.rs
Created April 4, 2020 18:35
basic error structure in Rust
use std::{error::Error as StdError, fmt};
#[derive(Debug)]
pub struct Error {
pub kind: ErrorKind,
pub context: ErrorContext,
}
#[derive(Debug)]
pub enum ErrorKind {
@vasilakisfil
vasilakisfil / timing_benchmark.rb
Created February 27, 2019 15:23
simple timing/benchmark mechanism for Ruby
class TimingBenchmark
def measure(label, &block)
@label_times ||= {}
start = Time.now
result = block.call
@label_times[label] = Time.now - start
return result
end
@vasilakisfil
vasilakisfil / hash_first.rb
Created November 16, 2018 10:59
Accessing a hash value by key is extremely fast. Is it possible to access the value of the first key with the same performance ?
require 'benchmark/ips'
require 'faker'
_hash = 100.times.inject({}){|hash, i|
hash[Faker::Lorem.word] = Faker::Lorem.word
hash
}
_hash[:aaa] = 'a'
HASH = _hash
@vasilakisfil
vasilakisfil / performance.rb
Created September 23, 2018 08:13
instance_exec vs args in a lambda
require 'bundler/setup'
Bundler.require(:default)
class Serializer
def user_path(id)
"/user/#{id}"
end
end
class User
// {{ 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
vasilakisfil / decorators.rb
Last active December 21, 2017 21:04
Decorator strategies battletested. Original script: https://gist.github.com/rbishop/7555357
#ENV: Ruby 2.4.1, a i7-6700HQ CPU, 16GB RAM
require 'benchmark'
require 'delegate'
require 'forwardable'
class Person
def initialize(name)
@name = name
end