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 / leetpolvo.rb
Created April 22, 2024 21:22
LeetPolvo
# ruby 3+
# gem install test-unit
require 'test/unit/assertions'
include Test::Unit::Assertions
def balanced?(input)
delimiters = {
"(" => ")",
"{" => "}",
"[" => "]"
@leandronsp
leandronsp / Dockerfile
Last active March 25, 2024 06:16
A multi-threaded web server in Assembly x86
FROM --platform=linux/amd64 ubuntu
RUN apt-get update
RUN apt-get install make binutils build-essential -y
RUN apt-get install nasm gdb strace -y
WORKDIR /app
@leandronsp
leandronsp / main.rb
Created December 4, 2021 21:50
How to reduce time complexity of nested loops
require 'faker'
require 'benchmark'
def generate_groups
(1..1_000).map do |id|
{ id: id, name: Faker::Educator.primary_school }
end
end
def generate_users(groups_ids)
@leandronsp
leandronsp / 001-server.bash
Last active February 28, 2024 19:44
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 / 001-README.md
Last active December 27, 2023 12:04
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 / main.rs
Created December 13, 2023 23:17
Actor model in Rust
use std::{thread, sync::{Arc, Mutex, Condvar}};
struct BlockingQueue<T> {
store: Mutex<Vec<T>>,
emitter: Condvar,
}
impl<T> BlockingQueue<T> {
fn new() -> BlockingQueue<T> {
Self {
@leandronsp
leandronsp / main.rs
Created October 31, 2023 01:47
Linked Lists in Rust
fn main() {
// 1. Singly Linked List (using Box)
{
println!("1. Singly Linked List (using Box)");
struct Node<T> {
value: T,
next: Option<Box<Node<T>>>,
}
let mut head = Box::new(Node { value: 1, next: None });
@leandronsp
leandronsp / main.rs
Created October 31, 2023 00:24
Smart Pointers in Rust (demonstration)
fn main() {
println!("This is a demonstration of ownership, borrowing and smart pointers in Rust.");
// 1. Data on the stack (fixed size)
{
println!("Data on the stack (fixed size):");
let age: i32 = 42;
println!("Age: {}", age);
// Transfer ownership: Copy
@leandronsp
leandronsp / README.md
Created October 10, 2023 19:40
Provisionar um registro de imagens Docker em cluster Kubernetes local
$ docker build -t localhost:5000/myapp . --push
@leandronsp
leandronsp / background_job.rs
Last active September 8, 2023 15:03
A dead simple background job processor written in Rust, using a double-ended queue and primitives sich as Arc and Mutex
use std::sync::{Arc, Mutex};
use std::sync::Condvar;
use std::thread;
use std::collections::HashMap;
use std::time::Duration;
struct Node<T> {
value: T,
next: Option<Arc<Mutex<Node<T>>>>,
previous: Option<Arc<Mutex<Node<T>>>>,