Skip to content

Instantly share code, notes, and snippets.

View sgtcortez's full-sized avatar
😁
An idiot admires complexity, a genius admires simplicity." - Terry A. Davis

Matheus Rambo sgtcortez

😁
An idiot admires complexity, a genius admires simplicity." - Terry A. Davis
  • Porto Alegre, Brazil
View GitHub Profile
@sgtcortez
sgtcortez / Test.c
Last active June 5, 2023 15:44
Serialize and Deserialize a number in C/C++
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/**
* Function to serialize a unsigned 64 bit number to a byte array
* The serialization uses Little Endian to store the bytes in the byte array
* so, the least significant byte(LSB) is the first byte of array, and the
* most significant byte(MSB) is the last byte in the array
*/
@sgtcortez
sgtcortez / Redis-cli.md
Last active August 31, 2022 12:12
redis-cli useful commands
  • Commands to obtain memory usage by certain key prefix:
redis-cli --scan --pattern "KEY_PREFIX*" | awk '{ print $1 }' | xargs --max-args 1 redis-cli MEMORY USAGE | awk '{total=total + $1} END { print "Total of bytes:", total} '
@sgtcortez
sgtcortez / Main.cpp
Created April 21, 2022 00:47
This is a very simple implementation of a semaphore using c++, just for learning purposes
#include "Semaphore.hpp"
#include <chrono>
#include <condition_variable>
#include <cstdint>
#include <iostream>
#include <string>
#include <thread>
using namespace std;
@sgtcortez
sgtcortez / Resolution.java
Created February 23, 2022 21:32
Dining Philosophers problem
import java.util.concurrent.Semaphore;
public class Resolution {
private static final int EAT_TIME = 3 * 1000;
private static final int THINK_TIME = 2 * 1000;
private static final int WAIT_TIME = 1 * 1000;
private static final int ITERATIONS_NUMBER = 1000;
@sgtcortez
sgtcortez / Cache Line.md
Last active March 16, 2022 20:18
This gist demonstrates False Sharing cache. Shows how a naive task can have a lot of difference when sharing the cache line in a effective way
@sgtcortez
sgtcortez / ReversePolishCalculator.java
Created July 31, 2021 02:42
RPN - Reverse Polish Notation calculator
import java.util.*;
class ReversePolishCalculator {
interface Operation {
int calculate(int a, int b);
}
enum MathOperation implements Operation {
ADD('+') {