Skip to content

Instantly share code, notes, and snippets.

View RodrigoDornelles's full-sized avatar
🏳️‍🌈
IEEE 754

RodrigoDornelles

🏳️‍🌈
IEEE 754
  • Porto Alegre, RS, Brasil
View GitHub Profile
@RodrigoDornelles
RodrigoDornelles / graybin.c
Created February 24, 2023 15:53
bidirectional converter between gray and binary
/**
* @file graybin.c
* @author Rodrigo Dornelles
* @link https://en.wikipedia.org/wiki/Gray_code
*/
#include <stdio.h>
#include <stdint.h>
/**
@RodrigoDornelles
RodrigoDornelles / dont_assign_string.c
Created February 23, 2023 14:59
Dangerous memory leakage without compiler warnings in C Language.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char* foo = malloc(4);
char* old_foo = foo;
foo[0] = 'f';
foo[1] = 'o';
foo[2] = 'o';
@RodrigoDornelles
RodrigoDornelles / max.py
Created February 2, 2023 13:50
greatest number between A and B
def max(a, b):
return (a + b + abs(a - b)) / 2
@RodrigoDornelles
RodrigoDornelles / safe_secret_input_posix.c
Created December 20, 2022 20:47
How to handle terminal in a safe protected way when cash/interrupt.
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
static unsigned int fid;
static struct termios term;
static char error_stdin[] = "[!] error in /dev/stdin";
static char question_name[] = "[?] what is your secret name:\n";
static char awsner_name_1[] = "[!] ok, good day ";
static char awsner_name_2[] = "!\n";
@RodrigoDornelles
RodrigoDornelles / force_true_isatty.sh
Created September 6, 2022 13:59
mama I want to take the risk of breaking my system.
script --return --quiet -c "[command here]" /dev/null
@RodrigoDornelles
RodrigoDornelles / from-scratch-boolean.js
Created July 8, 2022 23:41
from scratch boolean logic recreation based on the pure functional paradigm and lambda calculus.
const TRUE = (p) => (q) => (p)
const FALSE = (p) => (q) => (q)
const OR = (p) => (q) => p(p)(q)
const NOT = (p) => (p)(FALSE)(TRUE)
const AND = (p) => (q) => (p)(q)(FALSE)
const PROG = (func) => FALSE(func())(PROG)
const PRINT = (text) => () => TRUE(console.log(text))
const IF = (cond) => (execute) => (nonexecute) => (cond(execute)(nonexecute))()
PROG
@RodrigoDornelles
RodrigoDornelles / from-scratch-oop.php
Last active July 21, 2022 20:54
from scratch object-oriented recreation based on the functional paradigm.
<?php
$class = call_user_func(function () {
$objects = [];
return function() use (&$objects) {
return (object) [
'instanceof' => function($object) use (&$objects) {
return in_array($object, $objects);
},
@RodrigoDornelles
RodrigoDornelles / animate-number.js
Created December 28, 2021 17:43
Increment animation when scroll to number
document.addEventListener("DOMContentLoaded", () => {
const elements = document.querySelectorAll('.animate-number');
const lerp = (start, end, amt) => Math.round((1-amt)*start+amt*end);
const interval = 10;
const amount = 0.03;
const increment = (el) => {
el.setAttribute('data-now', lerp(el.getAttribute('data-now'), el.getAttribute('data-end'), amount));
el.innerText = Number(el.getAttribute('data-now')).toLocaleString();
@RodrigoDornelles
RodrigoDornelles / command.sh
Created July 14, 2021 17:58
Discover folders that take up more disk space.
du -bsh * > big_folders.txt &
@RodrigoDornelles
RodrigoDornelles / wget
Created June 25, 2021 14:40
Download the entire website with the wget command
wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains example.com \
--no-parent \
example.com/site/home