Skip to content

Instantly share code, notes, and snippets.

View leandronsp's full-sized avatar

Leandro Proença leandronsp

  • Brazil
View GitHub Profile
@leandronsp
leandronsp / triggers-rbac.yaml
Created February 19, 2023 16:53
Tekton Event Listener RBAC
apiVersion: v1
kind: ServiceAccount
metadata:
name: tekton-service-account
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: tekton-triggers-minimal
rules:
@leandronsp
leandronsp / server.rb
Created February 15, 2023 11:39
HTTP server using Ractors (Ruby 3)
require 'socket'
@queue = Ractor.new do
loop do
Ractor.yield(Ractor.receive, move: true)
end
end
listener = Ractor.new(@queue) do |queue|
socket = TCPServer.new(PORT)
@leandronsp
leandronsp / checker_test.rb
Created December 20, 2022 23:25
Purchases Checker
require 'test/unit'
require 'digest'
require 'date'
class PurchasesChecker
attr_reader :authorizations
def initialize
@authorizations = []
@purchases_idx = {}
@leandronsp
leandronsp / bitwise_sum.rb
Created September 6, 2022 03:21
Overengineering sum in Ruby
class Integer
def method_missing(m, right)
return if m != :sum
bitwise_sum(self, right)
end
private
def bitwise_sum(left, right)
@leandronsp
leandronsp / 001-README.md
Last active December 16, 2024 15:55
OOP in Bash script

OOP in Bash script

Wait, what?

Inspired by this awesome article.

Prelude about OOP

According to wikipedia, OOP is a programming paradigm or technique based on the concept of "objects". The object structure contain data and behaviour.

Data is the object's state, which should be isolated and must be private.

@leandronsp
leandronsp / 001-server.bash
Last active December 22, 2024 01:17
A complete yet simple Web server (with login & logout system) written in Shell Script
#!/bin/bash
## Create the response FIFO
rm -f response
mkfifo response
function handle_GET_home() {
RESPONSE=$(cat home.html | \
sed "s/{{$COOKIE_NAME}}/$COOKIE_VALUE/")
}
@leandronsp
leandronsp / grafana-dashboard.json
Created July 6, 2022 21:23
Grafana Dashboard (basic)
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
@leandronsp
leandronsp / add-index.sql
Created June 11, 2022 02:54
Comparing B-Tree index vs CTE's
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
leandronsp / ruby101.rb
Created June 4, 2022 20:49
Entendendo attr_accessor, writer e reader no Ruby
class Dog
def name
# retorna variável de instância
@name
end
end
doguinho = Dog.new
# Chamando método de instância
@leandronsp
leandronsp / server.rb
Created April 6, 2022 01:40
Web Login/Logout in Ruby, using TCP socket, in less than 110 lines
require 'socket'
require 'cgi'
PORT = 3000
socket = TCPServer.new('0.0.0.0', PORT)
puts "Listening to the port #{PORT}..."
loop do
# Wait for a new TCP connection..."