Skip to content

Instantly share code, notes, and snippets.


Leandro Proença leandronsp

View GitHub Profile
leandronsp / add-index.sql
Created Jun 11, 2022
Comparing B-Tree index vs CTE's
View add-index.sql
DROP INDEX IF EXISTS transfers_in, transfers_out;
CREATE INDEX transfers_in ON transfers (target_account_id);
CREATE INDEX transfers_out ON transfers (source_account_id);
leandronsp / ruby101.rb
Created Jun 4, 2022
Entendendo attr_accessor, writer e reader no Ruby
View ruby101.rb
class Dog
def name
# retorna variável de instância
doguinho =
# Chamando método de instância
leandronsp / server.rb
Created Apr 6, 2022
Web Login/Logout in Ruby, using TCP socket, in less than 110 lines
View server.rb
require 'socket'
require 'cgi'
PORT = 3000
socket ='', PORT)
puts "Listening to the port #{PORT}..."
loop do
# Wait for a new TCP connection..."
leandronsp / cractor.rb
Created Jan 17, 2022
A dead simple Actor in Ruby, simulating the same API for Ractors
View cractor.rb
class Cractor
def initialize(*args, &block)
@inbox =
@outbox = do
result = yield(self, *args)
leandronsp / palindromesX.js
Last active Jan 4, 2022
Palindromes of X random words
View palindromesX.js
Reverse a word
const reverse = (word) => {
const letters = word.split('')
const lastIdx = letters.length - 1
return letters
.map((letter, idx) => { return letters[lastIdx - idx] })
leandronsp / benchmark-web-concurrency
Last active Dec 23, 2021
Ruby web server - concurrency benchmark
View benchmark-web-concurrency
ab -n 20 -c 5
Req per seconds Time per req (ms)
Threads – IO 232 21
Fibers – IO 450 11
Threads – External Req 1.85 2703
Fibers – External Req 7.97 627
leandronsp / main.rb
Created Dec 4, 2021
How to reduce time complexity of nested loops
View main.rb
require 'faker'
require 'benchmark'
def generate_groups
(1..1_000).map do |id|
{ id: id, name: Faker::Educator.primary_school }
def generate_users(groups_ids)
leandronsp / sum_range.rb
Created Dec 4, 2021
Sum all numbers in a consecutive range
View sum_range.rb
require 'benchmark'
def sum_range_using_for_loop(min, max)
range = (min..max)
sum = 0
for n in range
sum = sum + n
leandronsp /
Created Oct 23, 2021
NGINX on Kubernetes

Create the pod on the cluster

kubectl apply -f nginx-pod.yaml
leandronsp /
Last active Oct 23, 2021
Provisioning a Kubernetes cluster on GKE using Pulumi
gcp:project: "my-project-created-on-gcp"