Skip to content

Instantly share code, notes, and snippets.

View rhiroyuki's full-sized avatar
🏠
Working from home

Ricardo Eihara rhiroyuki

🏠
Working from home
  • Brazil
View GitHub Profile
@rhiroyuki
rhiroyuki / redis_stream.md
Created November 28, 2018 13:15
Redis Stream

Memory usage and saving loading times

Because of the design used to model Redis streams, the memory usage is remarkably low. It depends on the number of fields, values, and their lengths, but for simple messages we are at a few millions of messages for every 100 MB of used memory. Moreover, the format is conceived to need very minimal serialization: the listpack blocks that are stored as radix tree nodes, have the same representation on disk and in memory, so they are trivially stored and read. For instance Redis can read 5 million entries from the RDB file in 0.3 seconds. This makes replication and persistence of streams very efficient.

It is planned to also allow deletion of items in the middle. This is only partially implemented, but the strategy is to mark entries as deleted in the entry flag, and when a given ratio between entries and deleted entires is reached, the block is rewritten to collect the garbage, and if needed it is glued to another adjacent block in o

@rhiroyuki
rhiroyuki / pos-clouding.txt
Last active December 1, 2018 17:13
aws elb - ecs - autoscaling
elb
sticky session, connection draining, proxy protocol
# frozen_string_literal: true
#
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', __dir__)
require 'sinatra'
require 'sinatra/contrib'
require 'logger'
set :logger, Logger.new(STDOUT)
@rhiroyuki
rhiroyuki / postgres_setup.md
Last active March 13, 2019 18:52
rails db:create error: FATAL: role does not exist

Error

FATAL:  role "ricardo" does not exist
Couldn't create 'somedb_development' database. Please check your configuration.
rails aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "ricardo" does not exist
bin/rails:4:in `<main>'

Caused by:
PG::ConnectionBad: FATAL:  role "ricardo" does not exist
@rhiroyuki
rhiroyuki / gist:c367aac1a65cb5cd2f65c3e380d4d2e1
Created January 3, 2019 19:16
sinatra/padrino/not rails application rspec not loading support files

Add this in spec_helper.rb

Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f }
@rhiroyuki
rhiroyuki / Vagrantfile
Last active January 29, 2019 01:40
About vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "jacksonpires/ubuntu-rails-dev"
config.vm.box_version = "1.0.0"
config.vm.network :forwarded_port, guest: 3000, host: 3000 # rails
config.vm.network :forwarded_port, guest: 9292, host: 9292 # rack
config.vm.network :forwarded_port, guest: 4567, host: 4567 # sinatra
def main
CYCLES_COUNT = 1_000_000_000
start = Time.now
CYCLES_COUNT.times do
end
end_time = Time.now
@rhiroyuki
rhiroyuki / sidekiq.rb
Last active February 13, 2019 20:28
Sidekiq
# Getting all jobs in retry
retries = Sidekiq::RetrySet.new
retries.each do |job|
p [job.klass, job.args, job.jid, job['created_at'], job['failed_at']]
end
# job['created_at'] and job['failed_at'] return epoch time, to parse it use Time.at(job['created_at'].to_f)
@rhiroyuki
rhiroyuki / gist:0fedf706ba2952ad6b799b4b2ed1023d
Last active March 10, 2019 21:23
gpg, keyserver and etc

For some reason the current keyserver that is by default set on Manjaro /etc/pacman.d/gnupg/gpg.conf doesn't work for me. To fix that I have to edit the keyserver for another https://wiki.archlinux.org/index.php/Pacman/Package_signing Or manually get the signature using the following command: gpg --keyserver hkp://ipv4.pool.sks-keyservers.net:11371 --recv-keys {keys}

#! /bin/bash
main () {
sudo pacman -Syu --noconfirm
sudo pacman -S tmux \
zsh \
neovim \
fzf \
fd \
jq \