Skip to content

Instantly share code, notes, and snippets.

View Theldus's full-sized avatar
🙃

Davidson Francis Theldus

🙃
View GitHub Profile
@Theldus
Theldus / no-internet.sh
Created February 26, 2024 02:30
Simple shell script to temporarily deny internet access (but keep local network) to some given command
#!/usr/bin/env bash
# This is free and unencumbered software released into the public domain.
# Based on:
# https://serverfault.com/questions/550276/how-to-block-internet-access-to-certain-programs-on-linux
GROUP_NAME="no-internet"
IPv4_NETWORK="192.168.100.0/24"
IPv6_LOOPBACK="::1/128"
@Theldus
Theldus / v8.md
Last active February 11, 2024 19:56
Does V8's JIT Engine Truly Compete with GCC?

Does V8's JIT Engine Truly Compete with GCC?

JavaScript is a language that has never particularly piqued my interest, as I prefer working at the binary, CPU, operating system level, etc. However, something that has truly caught my attention recently is V8, or more precisely, its ability to perform Just-in-time Compilation (JIT).

V8's JIT is highly acclaimed for its speed and consistently ranks not far from the top in various benchmarks. While it might not always be the fastest, it is orders of magnitude ahead of purely interpreted languages such as Python (CPython), PHP, and Perl.

@Theldus
Theldus / README.md
Last active April 5, 2024 14:18
The only proper way to debug 16-bit (x86) code on Qemu+GDB

The only proper way to debug 16-bit code on Qemu+GDB

(or nearly so...)

GDB is undeniably an extremely versatile debugger, with the ability to add breakpoints, watchpoints, dump memory, registers, and the source code (along with its corresponding assembly). These features make it the perfect Swiss Army knife for most programmers. In addition to that, the possibility of implementing a 'GDB Stub' and automatically supporting GDB in your application makes it an almost universal debugger for a variety of tasks.

Qemu, like other virtual machines (such as 86Box), also implements debugging via GDB Stub, which enormously facilitates the development of bootloaders, operating systems, and more. The support for 32-bit and 64-bit code is quite good, and I have never seen any complaints about it. However, for 16-bit/real mode...

Is debugging in 16-bit/real mode really that bad?

If you have ever tried to debug 16-bit code on Qemu, you know how painful it can be:

  1. GDB thinks your code is
@Theldus
Theldus / README.md
Created January 16, 2023 02:16
Slackware 15 running on a Pentium 133 MHz (32MB of RAM)
@Theldus
Theldus / syntax.s
Created August 18, 2022 07:26 — forked from mishurov/syntax.s
AT&T assembly syntax and IA-32 instructions
# --------
# Hardware
# --------
# Opcode - operational code
# Assebly mnemonic - abbreviation for an operation
# Instruction Code Format (IA-32)
# - Optional instruction prefix
# - Operational code
@Theldus
Theldus / README.md
Last active March 2, 2023 20:27
Helping your 'old' PC build faster with your mobile device (no root required)

Helping your 'old' PC build faster with your mobile device

It all happened when I decided to run Geekbench 5 on my phone: surprisingly the single-core performance matched my 'old'¹ Pentium T3200 and surpassed it in multicore. Since I've been having fun with distcc for the last few days, I asked myself: 'Can my phone really help my old laptop build faster? nah, hard to believe... but let's try'.

Without further ado: YES. Not only can my phone be faster, but it can significantly help in the build process, I believe the results below speak for themselves:

asciicast

Building Git (#30cc8d0) on a Pentium T3200, 8m30s

asciicast Building Git (#30cc8d0) on a Pentium T3200 (2x 2.0 GHz)+ Snapdragon 636 (4x1.8 + 4x1.6 GHz), 2m9s

@Theldus
Theldus / aqua.h
Last active June 16, 2022 01:43
💧 Aqua: a simple syntax highlighter for Python code written in C
/*
* This is Aqua: a public-domain syntax highlighter for Python code
* written in C, which uses ANSI Escape Sequences to color the output.
*
* Aqua tries to be as simple as possible:
* - Cannot identify UTF-8 encoded keywords (it just ignores them).
* - Number parsing is pretty silly (see state_number() for more info),
* but it 'works'.
*
* Which also brings several interesting advantages, such as:
@Theldus
Theldus / Makefile
Last active April 21, 2022 20:57
Get infos from inodes/symlinks directly from the kernel, because why not?
CFLAGS_inodereader.o := -DDEBUG
obj-m += inodereader.o
#
# Kernel source directory, default or not
#
# Idea taken from: Documentation/kbuild/modules.txt
#
KDIR ?= /lib/modules/`uname -r`/build
@Theldus
Theldus / read_dir.c
Created April 18, 2022 07:22
Read directory entries through ext4 filesystem layout, without opendir/readdir
/*
* 2022 April, 18
* The author disclaims copyright to this source code, and it is
* release to the public domain.
*
* This code serves and has been published for study purposes
* only, I am not responsible for any damage caused by it.
*/
#include <stdio.h>
@Theldus
Theldus / xorxor.c
Last active February 16, 2022 01:42
Encrypt files recursively using XOR and PRNG.
/*
* 2021 November, 17
* The author disclaims copyright to this source code, and it is
* release to the public domain.
*
* This code serves and has been published for study purposes
* only, I am not responsible for any damage caused by it.
*/
/* Enable nftw(). */