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.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>>>>,
@leandronsp
leandronsp / socket.rs
Created August 5, 2023 16:55
A UNIX socket server written in Rust
// A UNIX socket server written in pure Rust
use std::io::Read;
use std::os::unix::net::{UnixListener, UnixStream};
use std::path::Path;
fn main() {
let socket = Path::new("/tmp/echo.sock");
if socket.exists() {
@leandronsp
leandronsp / socket-server.go
Created August 5, 2023 16:11
A UNIX socket server written in Go
// A UNIX socket server written in Go, using the net package.
package main
import (
"fmt"
"net"
"os"
)
@leandronsp
leandronsp / background_job_test.go
Created August 5, 2023 02:15
A dead simple background processor in Go, using a double-ended queue based on a doubly linked list
// go mod init queues
// go mod tidy
// go get github.com/stretchr/testify/assert
// go mod tidy
// go test background_job_test.go
package queues
import (
"fmt"