Skip to content

Instantly share code, notes, and snippets.

@Lohann
Lohann / itoa.rs
Last active May 14, 2026 02:28
Rust itoa
// Implementation of itoa (integer to ASCII), which converts an 64-bit to decimal string.
//
// Rust's `format!("{num}")` requires heap `alloc` and bloats the code with panic messages,
// I needed something simpler for support basic tracing in Wasm targets.
// This implementation focus on smaller binary instead raw performance, ideal for
// no_std environements like wasm32-unknown-unknown or embeeded.
//
// @author Lohann Paterno Coutinho Ferreira <[email protected]>
#[unsafe(no_mangle)]
#!/bin/sh
# single quote arguments using only pure shell, this
# script doesn't require any external programn such as `sed`.
quote ()
{
test $# -gt 0 || return 0
while test $# -gt 1
do
quote "$1" || return $?
#!/bin/sh
set -eu
# This script prepares a macOS virtual machine for SSH-Only access.
# it is based on https://github.com/sickcodes/osx-optimizer
# Safety check to prevent executing this script in the HOST machine
# instead the macOS virtual machine.
VM_USERNAME='<VM-USERNAME-HERE>'
#!/usr/bin/env bash
set -euo pipefail
# Prevent locale nonsense from breaking basic text processing.
LC_ALL=C
export LC_ALL
# display a message then exit
abort() {
@Lohann
Lohann / current-shell.sh
Created December 6, 2025 19:16
Shell script that prints recursively what is the current shell emulator.
#!/bin/sh
# Prints recursively what is the current shell emulator.
pid=$$
printf 'pid="%s"\n' "${pid}"
test "${pid}" = '1' && exit 1
die(){
echo "${1}"
@Lohann
Lohann / settings.json
Last active October 9, 2025 23:27
Rust VSCode Settings
{
"editor.inlineSuggest.enabled": true,
"editor.semanticHighlighting.enabled": true,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.extraArgs": [
"--",
"-Dwarnings",
#define SQLITE_ENABLE_NORMALIZE
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <openssl/rand.h>
#include <pthread.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdio.h>
@Lohann
Lohann / itoa.c
Last active August 21, 2025 21:04
// Implementation of itoa (int to ASCII), which converts an 64-bit to decimal string.
//
// Based on Tigran Hayrapetyan Algorithm: `34% faster Integer to String conversion algorithm`
// ref: https://towardsdatascience.com/34-faster-integer-to-string-conversion-algorithm-c72453d25352/
//
// @author Lohann Paterno Coutinho Ferreira <[email protected]>
#include "itoa.h"
// lookup table of powers of 10, used by `ilog10` and `itoa`.
static uint64_t const powers_of10[20] = {
@Lohann
Lohann / heaps_algorithm.rs
Last active December 9, 2025 18:07
Heap's Permutation Algorithm in Rust
// Author: Lohann Paterno Coutinho Ferreira
//
// Heap's Permutation Algorithm
/// Move all duplicated elements to the end of the array.
/// Returns the number of distinct elements.
fn move_duplicated<T: PartialEq>(array: &mut [T]) -> usize {
let mut n = array.len();
let mut i = 0;
while i < n {
/*
* @author Lohann Paterno Coutinho Ferreira <[email protected]>
*
* Example on how to add numbers using only bitwise operators:
* - xor: ^
* - and: &
* - not: ~
* - or: |
*
* # Motivation