Skip to content

Commit 9b4bd85

Browse files
committed
push new blog post
1 parent 624e053 commit 9b4bd85

File tree

2 files changed

+89
-4
lines changed

2 files changed

+89
-4
lines changed

content/posts/HellEsc.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,28 @@ title: "HellEsc"
33
date: 2023-02-06
44
---
55

6-
Life is complicated, and the tech world is full of choices. To learn better, I code in low-level languages and work my way. RabbitHoleCoding, I will call it HellEsc since I will be coming from the pit of hell of bits ;). Let's start with the basics, and I will need to start with hardware which will be virtual for now. Virtualization will make things portable and less worried about me breaking things. The first step is to boot hello world like I am the only living thing in a system. so let's make a shopping list to get things in order
6+
# Journey into RabbitHoleCoding: A Wizard's Tale in the Realm of the Command Line
77

8-
- language: x86 assembly
9-
- staging area or platform: qemu
10-
- assembler: as or nasm
8+
In the mystical realm of technology, where choices abound like stars in the night sky, embarks a brave soul on a quest named RabbitHoleCoding, or as I prefer, HellEsc. Picture this journey as a descent into the very core of the digital netherworld, delving into the abyss of bits and bytes.
9+
10+
### The Art of Command-Line Wizardry
11+
Just as a wizard begins with the fundamentals of magic, so shall this journey commence with the rudimentary elements of computing. For now, the focus is on the ethereal, the virtual, as tangible hardware takes a back seat to its virtual counterpart. This choice of virtualization, akin to conjuring realms within realms, provides safety and flexibility - a sandbox for magical experiments, free from the fear of breaking the physical threads of reality.
12+
13+
### Conjuring the Basics: The Sorcerer's Shopping List
14+
The tools and incantations are as crucial as the spells in a wizard's grimoire in this arcane quest. Here is the mystical shopping list, a collection of artifacts and magic needed to breathe life into this digital realm:
15+
16+
**Language: x86 Assembly** - The ancient tongue of the machine, a language of power and precision. It's the runic script through which we converse directly with the device's heart.
17+
18+
**Staging Area or Platform: QEMU** - Like a wizard's circle, QEMU serves as the staging ground. It's our own created world, a virtual sandbox where our code can dance without disturbing the fabric of the physical realm.
19+
20+
**Assembler: AS or NASM** - These are the wands of our trade, tools to transmute our written spells (code) into a form the machine spirits can understand. Whether it's AS (the GNU assembler) or NASM (Netwide Assembler), each has its unique charms and incantations.
21+
22+
### The First Enchantment: "Hello World"
23+
The initial spell to cast in this realm is the legendary "Hello World" - a rite of passage for all who delve into the arcane arts of programming. It's akin to a wizard's first successful summoning, an affirmation that they can bend the elements to their will.
24+
This incantation, when invoked, will make it seem as if you are the sole entity in this system - a solitary sorcerer casting spells into the void, watching them echo back with life.
25+
26+
### The Path Forward
27+
28+
With our shopping list and virtual cauldron ready, we stand at the precipice of a grand adventure. Each step in this journey is a step deeper into the underworld of bits, a dive into the essence of computing itself.
29+
Remember, fellow command-line sorcerers, the path of RabbitHoleCoding, or HellEsc, is fraught with challenges and wonders alike. May your spells compile without error, and your digital incantations bring unseen marvels into this virtual realm. 🧙‍♂️✨🖥️
1130

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: "A Wizard's Command Line Incantations for Enchanting C Code in Vim"
3+
date: 2023-11-20
4+
---
5+
6+
7+
# A Wizard's Command Line Incantations for Enchanting C Code in Vim
8+
9+
A Wizard's Command Line Incantations for Enchanting C Code in Vim
10+
Greetings, fellow practitioners of the command line arts! Today, we delve into the mystical world of Vim, where keystrokes become spells, and code transforms at our whim. Join me as we explore a spellbinding Vim script, an incantation designed to transmute chaotic C code into a tapestry of elegance and order.
11+
The Enchanted Scroll: Our Vim Spellbook
12+
13+
In the heart of our magical library lies a spell written in the ancient runes of Vim:
14+
```vim
15+
function! FormatCCode()
16+
" Save cursor position
17+
let l:save_cursor = getpos(".")
18+
19+
" Remove trailing whitespace
20+
%s/\s\+$//e
21+
22+
" Replace tabs with spaces
23+
setlocal expandtab
24+
%retab
25+
26+
" Set C style indentation
27+
setlocal cindent
28+
setlocal cinoptions=:0,l1,(0,u0,U0
29+
normal gg=G
30+
31+
" Adjusting Curly Braces
32+
" Place opening brace on a new line
33+
%s/\s*{\s*$/\r{/e
34+
" Ensure single line spacing before closing brace
35+
%s/\n\s*\n\s*}/\r}/e
36+
37+
" Reapply indentation after brace adjustments
38+
normal gg=G
39+
40+
" Restore cursor position
41+
call setpos('.', l:save_cursor)
42+
endfunction
43+
44+
45+
```
46+
47+
### Unraveling the Mystical Code
48+
1. The Locator Charm: let l:save_cursor = getpos(".") - As a locator spell allows wizards to remember their place in a vast forest, this charm reflects your cursor's position, ensuring you can return to your exact spot after the formatting ritual.
49+
50+
2. The Trailing Wind: %s/\s\+$//e - Imagine a gentle breeze that sweeps away all unnecessary spaces at the end of lines. This incantation ensures each line in your code ends cleanly, maintaining the purity of your script.
51+
52+
3. The Space Conjuror: The twin spells setlocal expandtab and %retab work in unison to transform all tabs into spaces. Like a wizard turning lead into gold, these ensure your indentations are universally understood in all realms.
53+
54+
4. The Alignment Hex: setlocal cindent and setlocal cinoptions=:0,l1,(0,u0,U0 - This powerful hex aligns your code in the ancient style of C, organizing your incantations into a readable and structured grimoire.
55+
56+
5. The Grand Alignment: normal gg=G - Envision this as a grand spell that aligns every line from the beginning to the end of your document, bringing harmony and order to your code.
57+
58+
6. The Return Portal: call setpos('.', l:save_cursor) - After the grand sorcery, this spell returns you to your original position, just like a portal spell brings you back to your starting point after a long journey.
59+
60+
### Casting the Grand Spell
61+
To bring this magic into your realm, inscribe this script into your .vimrc grimoire. In the mystical world of Vim, summon this enchantment on any C script by uttering the incantation `:call FormatCCode().`
62+
A Mage's Word of Caution
63+
While powerful, this script may need to fully understand the more complex spells of the C language, such as eldritch macros or the riddles of multiline comments. Test this magic on less important scrolls (backup files) before applying it to your main codices.
64+
The Path to Advanced Sorcery
65+
For wizards seeking even more formidable enchantments, explore the realms of vim-autoformat or summon external spirits like clang-format to aid you. These entities offer a plethora of formatting spells for various coding languages, expanding your magical repertoire.
66+
In the end, remember, fellow command line wizards, this Vim script is a tool in your mystical arsenal to bring order and beauty to your code. May your spells be error-free and your coding journeys full of wonder. 🧙‍♂️✨📜

0 commit comments

Comments
 (0)