Tuesday, August 4, 2026

TIL - Horner's method: An algorithm for reading a number written in any positional numeral system.

There is a universal algorithm for evaluating numbers written in any positional numeral system. Once you know the base and can convert each symbol into its corresponding digit, the algorithm is simply:

result = result * base + digit;

Suppose you are reading a number in base 10 say 1234:

Let's decompose in exponentials from left to right:

1234 = 1*10³ + 2*10² + 3*10¹ + 4*10⁰

Now we factor 10:

10(1*10² +2*10¹+3)+4

And again:

10(10(1*10+2)+3)+4

Finally:

10(10(10(1) +2)+3+4

Alternatively:

((1×10+2)×10+3)×10+4

This works for any positional numeral system. Changing 2 to 10 parses decimal numbers, changing it to 16 parses hexadecimal numbers (after converting A–F to 10–15) and so on.

Thursday, July 23, 2026

Newton's Binomial Theorem


I stumbled upon this formula in a book the other day and set about coding it in C from scratch. At the end of the day any summation can be easily turned into a for loop.

I also wrote my own functions for exponential, combinatorial numbers and factorial.

Tuesday, August 26, 2025

[fread]: An old-school text file viewer for the modern terminal (GNU/Linux)

Last month I came across an old gem: PC Game Programmer's Encyclopedia, a DOS-era program built with the Pascal TUI Vision library. It’s a collection of docs about assembly and game programming compiled by Mark Feldman.

These files were originally stored in old MS-DOS encodings. Luckily, thanks to the dos2ansi project I was able to convert them into a more UTF-8-friendly format, making them readable on modern systems.

That got me thinking: why not create a modern TUI version for GNU/Linux to display these texts?

The first step was building a text file viewer that supports modern Unicode encoding. That’s how fread was born.


You can see it in action in this demo video.

The project has a modular approach:

  • openfile.c handles opening and reading files.

  • viewer.c takes care of displaying the contents, with both horizontal and vertical scrolling, screen resizing, and even binary file detection.

I'm quite happy with how it turned out and it is a marked improvement on my previous attempt at coding a textfile reader fw, which only supported ASCII characters. I like how you can keep writing the same style of program and still learn something new each time. I have quite a collection of TUI programs now :D

The next step will be to create a mock-up of the original DOS program with the dro-down menus at the top linking to the documents.


Friday, August 15, 2025

Dictionary Apps: Terminal and Web-Based

I set about coding a TUI dictionary program for the Linux terminal in C to help me expand my vocabulary in English using the interface I had made for HIS (TUI history command). The dictionary is stored in a CSV file with 4 fields (ID, WORD, TRANSLATION, COMMENT). You can add words from the program, edit specific fields.  The feature I'm definitely most proud of is the built-in game to guess words from your dictionary.



You can try it out here: https://github.com/velorek1/dict

It's fun to play it on Termux on an Android phone. The downside is that the dictionary is stored locally and cannot be accessed from any other device. 

Another approach I explored was reusing the previous work I had done with Google App Scripts , Javascript, Google sheets and the recently discovered, amazing hosting service of Netlify. Thanks to Claude (AI) I was able to deploy a fully developed APP that mimicks and more than exceeds the  features of my terminal program. I will definitely be using Netlify in future web-based projects! :)


Full version here : https://regal-sawine-d63fb6.netlify.app/



Sunday, January 5, 2025

Art - Exploring objects in the computational universe

Fractals are characterized by self-similarity and recursive patterns at various scales. Sometimes this complex behavior can be achieved from simple rules which typically make use of loops, recursion, or even modular arithmetic in conjunction with bit-wise operations (XOR; AND, ETC).

I had found this example a while ago and I'm still amazed at how such a complex pattern like the Sierpinski fractal can emerge in only 14 bytes of assembler code!? Truly mind-boggling.

The second example uses modular arithmetic to create a maze-like fractal pattern.

REPOSITORY FOR ART 





Saturday, January 4, 2025

[keyc] : A proof-of-concept Linux Keylogger in C

[keyc] : KeyCapture

A simple keylogger for Linux using evdev. This program captures keyboard input. I

t requires root privileges to run. Keyboard device file defaults to event0. 


If different, check /proc/bus/input/devices and run with paramater specifying device file number (X) as in ./keyc X


Key chars are stored in .capt.dat


Compilation

Compile the program with GCC:

  • gcc keyc.c -o keyc

Saturday, November 30, 2024

Sunday, August 27, 2023

A starfield animation in C with SDL2

Starfields are one of my favourite pixel animations.

Hugo Elias once wrote a wonderful write-up tutorial about the intricacies of coding star field animations that should not fall into oblivion.

http://web.archive.org/web/20160114180422/http://freespace.virgin.net/hugo.elias/graphics/x_stars.htm

My implementation in C with SDL2:

https://github.com/velorek1/starfield



Tuesday, April 25, 2023

N.R.P ( Número de registro personal)

CALCULA TU NRP

Sunday, April 9, 2023

A beautiful TUI periodic table for Linux Terminals coded in C - no extra dependencies

The periodic table, also known as the periodic table of the elements, is a rows and columns arrangement of the chemical elements. It is widely used in chemistry, physics, and other sciences, and is generally seen as an icon of chemistry. (WIKIPEDIA)

In my last project in C I wanted to compile everything I've learned with graphical text interfaces and create a retro-looking periodic table that looks nice :)

Though not my best or cleanest code, it is intended to be used as a "demo" for the Lynx TUI. Is is also made with a lot of love.

The explanation of all the modules below:

(Increasing in order of abstraction until you reach main.c)


LEVEL 0: (BASE)

  • rterm.c : With the ANSI escape sequences to color our output in the terminal
  • tm.c : Create a millisecond timer for animations

LEVEL 1: (LOW LEVEL ABSTRACTIONS)

  • keyb.c : Creates a small keyboard abstraction to read escaped keys \e on Linux
  • scbuf.c (1) : Creates an intermediate layer between the display and the terminal as a double screen buffer - listbox.c (2) : Creates a list with a selector with horizontal scroll

LEVEL 2: (HIGH LEVEL ABSTRACTIONS)

  • ui.c : Different tools like textbox and window for user interface
  • global.h and about.h : text messages and global variables

main.c: Main program elements.dat: Database of elements, most of the info generated with chatGPT.

(1) http://oldstuff286.blogspot.com/2017/09/a-very-simple-screen-double-buffer.html

(2) http://oldstuff286.blogspot.com/2018/07/segmentation-fault-c-pointers.html


Wednesday, November 9, 2022

Meneame en la Terminal (LINUX) - (Spanish)

En mi último proyecto en C he querido reunir todo lo que he aprendido con las interfaces gráficas de texto y darle uso conectándome a la API de meneame. Soy usuario de meneame desde sus inicios y éste es mi guiño personal por estar ahí durante todos estos años. 
Por ahora es una DEMO de lo que podría llegar a ser. El programa descarga las 100 noticias que aparecen en portada haciendo un CURL request a "https://meneame.net/api/list.php?status=published". 

Luego parsea la información recibida y la muestra en un programa con una interfaz de texto retro. 
No es mi mejor código, pero está hecho con mucho cariño :) 
Código en:

La explicación de todos los módulos a continuación: 

(Aumentando en orden de abstracción hasta llegar a main.c
________________

NIVEL 0: (BASE) 
- rterm.c : Con las secuencias de escape ANSI para dar color a nuestro output en la terminal 
- tm.c : Crea un timer de milisegundos para animaciones 
- fileop.c: Un módulo que ayuda para operaciones con archivos 
_______________

NIVEL 1: (DEPENDENCIAS) 
- download.c : Depende de libcurl. Hacemos la llamada a la API de meneame y guardamos su contenido en un fichero 
- parse.c : Parsea el contenido del fichero y lo volcamos a una array. Quitamos las secuencias de unicode y parsear acentps del español 
_______________

NIVEL 2: (ABSTACCIONES NIVEL BAJO) 
- keyb.c : Crea una pequeña abstracción del teclado para leer las teclas con secuencia de escape \e en Linux 
- scbuf.c (1) : Crea una capa intermedia entre el display y el terminal a modo de doble buffer de pantalla - listbox.c (2) : Crea una lista con un selector con scroll horizontal 
_______________

NIVEL 3: (ABSTACCIONES NIVEL ALTO) 
- ui.c : Diferentes herramientas como textbox y ventana para la interfaz de usuario 
- global.h y about.h : mensajes de texto y variables globales 
_______________

main.c: Programa principal


Sunday, February 27, 2022

C - WORDLE CLONE IN C

Inspired by the popular game, I set about coding my own version for the terminal. :)

This is the first playable version: https://github.com/velorek1/cwordle

It is only one file with code plus the dictionary files that can be changed or adapted as they are just regular text files.

I think it looks retro and cool and it is worth sharing. One of my most popular programs so far. :)





Sunday, February 6, 2022

LYNX - A LIBRARY FOR CREATING TEXT USER INTERFACES FOR TERMINALS IN C

Lynx compiles some of the ideas I have developed into a soon-to-be cross-platform library that makes it possible to develop fast TUI applications for terminals.

The following Demo features:

  • Double Screen Buffer.
  • Ansi Color Sequences for Terminals.
  • Keyboard input with kbhit().  
  • Screen Resizing.
  • Timer for animations.

https://github.com/velorek1/lynx

 


Saturday, January 2, 2021

FilevieWer - A TUI program to view files with scroll for linux terminals


These days I've been working on fw-fileviewer: a fileviewer for GNU/linux terminals. 



My text editor (C-edit) is currently stalled. It needs a thorough redesign and I need to find the time and motivation to undertake it. In the meantime, I have put everything I've learned in that project to code a simple fileviewer for linux terminals with a decent Text User Interface. Plus, it makes use of my latest module with timers in C.

Link to code -> fw-fileviewer

 

 



Saturday, December 26, 2020

A millisecond Timer in C


Here is one possible implementation of a millisecond timer in C using time.h and ts.tv_nsec
Proof of concept:  Timer Source code
A simpler, more compliant version can be found in repository.

Saturday, December 5, 2020

New Horizons

Google Sheets & Javascript

GOOGLE SHEET MANIPULATION

Spreadsheet link

WORD TRANSLATION
COMMENT
[+] Words:

>> Translation:

Result:

Table:

Saturday, November 14, 2020

A one-line formula to add the digits of a 2-digit number using mod

Adding two digits of a number is the same as subtracting 9 multiplied by the number in the tens from the original number. This formula uses mod(%) to isolate such number and provides the result of the addition of the 2 digits of a given number from 11 to 99:

From: x- (((x -(x mod 10)) / 10) *9)
To: f(x) = x - (1/10(x - x mod 10))× 9
Example: 23 -> 2+3 = 5 | 23 - (9*2) = 5 | 23 - (((23 - (23 mod 10)) / 10) * 9) = 5 
Sample in Ctwodigits




Friday, August 28, 2020

Asteroid Game

Screenshot of the remake of the classic game Asteroid with SDL2 in pure C.

[+] Code:
First commit and subsequent development: 

[+] Game Structure: