undefined behavior

tb;dr - too boring; don’t read

Recent All Posts Categories Tags About Search

Setup Windows To Go in a Virtual Disk

Ramble

It looks like I had a lot stories about this Windows boot setup. I figure this post would be the last one I write about it since this is the most commonly used case I have so far.

So I got a Steam Deck last year. It’s pretty handy to use it as a mini PC in case I don’t have one in hands. However, there are still things exclusive on Windows but I don’t want to mess up with the internal SSD to dual-boot just for this temporary need.

 Read on …

Perl Quick Reference

Preface

Perl is a powerful tool to handle text processing. However, the learning curve might be steep due to some unusual syntax. I find myself even need to revisit the doc sometimes if I don’t use it often, so this post I’ll write down some commonly used patterns when it comes to text processing. That said this post is updated from time to time so remember to come back!

 Read on …

Moving from Arch Linux to NixOS

I’ve been learning Nix for a while and using the Nix package manager on my work desktop that runs Ubuntu. However, I did not use the NixOS on my personal laptop because I thought I might put a lot effort after work to set it up, which I didn’t really want to. Until recent, the Arch dependencies broke again and I felt it kinda suck to fix those issues so I decided to give Nix a try. To my suprise, the installation process is way simpler than I expected.

 Read on …

ANSI Escape Code Collection

The information in this collection is from Internet, which is collected for my personal convenience.

CSI sequences

CodeNameEffect
CSI n ACUU – Cursor UpMoves the cursor n (default 1) cells in the given direction. If the cursor is already at the edge of the screen, this has no effect.
CSI n BCUD – Cursor Down
CSI n CCUF – Cursor Forward
CSI n DCUB – Cursor Back
CSI n ECNL – Cursor Next LineMoves cursor to beginning of the line n (default 1) lines down. (not ANSI.SYS)
CSI n FCPL – Cursor Previous LineMoves cursor to beginning of the line n (default 1) lines up. (not ANSI.SYS)
CSI n GCHA – Cursor Horizontal AbsoluteMoves the cursor to column n (default 1). (not ANSI.SYS)
CSI n ; m HCUP – Cursor PositionMoves the cursor to row n, column m. The values are 1-based, and default to 1 (top left corner) if omitted. A sequence such as CSI ;5H is a synonym for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H
CSI n JED – Erase in DisplayClears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).
CSI n KEL – Erase in LineErases part of the line. If n is 0 (or missing), clear from cursor to the end of the line. If n is 1, clear from cursor to beginning of the line. If n is 2, clear entire line. Cursor position does not change.
CSI n SSU – Scroll UpScroll whole page up by n (default 1) lines. New lines are added at the bottom. (not ANSI.SYS)
CSI n TSD – Scroll DownScroll whole page down by n (default 1) lines. New lines are added at the top. (not ANSI.SYS)
CSI n ; m fHVP – Horizontal Vertical PositionSame as CUP
CSI n mSGR – Select Graphic RenditionSets the appearance of the following characters, see SGR parameters below.
CSI 5iAUX Port OnEnable aux serial port usually for local serial printer
CSI 4iAUX Port OffDisable aux serial port usually for local serial printer
CSI 6nDSR – Device Status ReportReports the cursor position (CPR) to the application as (as though typed at the keyboard) ESC[n;mR, where n is the row and m is the column.)
CSI sSCP – Save Cursor PositionSaves the cursor position/state.
CSI uRCP – Restore Cursor PositionRestores the cursor position/state.
CodeEffect
CSI ? 25 hDECTCEM Shows the cursor, from the VT320.
CSI ? 25 lDECTCEM Hides the cursor.
CSI ? 1049 hEnable alternative screen buffer
CSI ? 1049 lDisable alternative screen buffer
CSI ? 2004 hTurn on bracketed paste mode. Text pasted into the terminal will be surrounded by ESC [200~ and ESC [201~, and characters in it should not be treated as commands (for example in Vim).[20] From Unix terminal emulators.
CSI ? 2004 lTurn off bracketed paste mode.

SGR parameters

CodeEffectNote
0Reset / Normalall attributes off
1Bold or increased intensity
2Faint (decreased intensity)
3ItalicNot widely supported. Sometimes treated as inverse.
4Underline
5Slow Blinkless than 150 per minute
6Rapid BlinkMS-DOS ANSI.SYS; 150+ per minute; not widely supported
7reverse videoswap foreground and background colors
8ConcealNot widely supported.
9Crossed-outCharacters legible, but marked for deletion.
10Primary(default) font
11–19Alternative fontSelect alternative font {\displaystyle n-10} {\displaystyle n-10}
20FrakturRarely supported
21Doubly underline or Bold offDouble-underline per ECMA-48.[22] See discussion
22Normal color or intensityNeither bold nor faint
23Not italic, not Fraktur
24Underline offNot singly or doubly underlined
25Blink off
27Inverse off
28Revealconceal off
29Not crossed out
30–37Set foreground colorSee color table below
38Set foreground colorNext arguments are 5;n or 2;r;g;b, see below
39Default foreground colorimplementation defined (according to standard)
40–47Set background colorSee color table below
48Set background colorNext arguments are 5;n or 2;r;g;b, see below
49Default background colorimplementation defined (according to standard)
51Framed
52Encircled
53Overlined
54Not framed or encircled
55Not overlined
60ideogram underline or right side lineRarely supported
61ideogram double underline or double line on the right sideRarely supported
62ideogram overline or left side lineRarely supported
63ideogram double overline or double line on the left sideRarely supported
64ideogram stress markingRarely supported
65ideogram attributes offreset the effects of all of 60–64
90–97Set bright foreground coloraixterm (not in standard)
100–107Set bright background coloraixterm (not in standard)

Color code

ColorForegroundBackground
Black\u001b[30m\u001b[40m
Red\u001b[31m\u001b[41m
Green\u001b[32m\u001b[42m
Yellow\u001b[33m\u001b[43m
Blue\u001b[34m\u001b[44m
Magenta\u001b[35m\u001b[45m
Cyan\u001b[36m\u001b[46m
White\u001b[37m\u001b[47m
Bright Black\u001b[30;1m\u001b[40;1m
Bright Red\u001b[31;1m\u001b[41;1m
Bright Green\u001b[32;1m\u001b[42;1m
Bright Yellow\u001b[33;1m\u001b[43;1m
Bright Blue\u001b[34;1m\u001b[44;1m
Bright Magenta\u001b[35;1m\u001b[45;1m
Bright Cyan\u001b[36;1m\u001b[46;1m
Bright White\u001b[37;1m\u001b[47;1m
Reset\u001b[0m\u001b[0m
 Read on …

[Archive] Multiboot USB

Boot from any ISO file

Hybrid UEFI GPT + BIOS MBR/GPT boot

Preparation

Create 3 partitions on a removable USB stick.

  1. A BIOS boot partition (gdisk type code EF02, or GUID 21686148-6449-6E6F-744E-656564454649) with no filesystem. This partition can be put in any place on the disk but it is recommended to put it at the begginning from sector 34 to 2047. At minimal 1 MiB.
  2. An EFI System partition (gdisk type code EF00) with a FAT32 filesystem. This partition can be as small as 50 MiB but it is better to set at least 256 MiB (550 MiB recommended).
  3. Data partition (use a filesystem supported by GRUB). This partition can take up the rest of the space of the drive.

GRUB Installation

Mount EFI and data partitions. First install GRUB for UEFI:

 Read on …

Different Ways to Write a Major Mode

This post mainly helps myself remember how to quickly write a major mode. My memory is getting worse. So sad. :(

Use define-derived-mode

Doc: https://www.gnu.org/software/emacs/manual/html_node/elisp/Derived-Modes.html

This perhaps the most common way to write a major mode.

Most of the times I derive from fundamental-mode, or nil if the parent mode is not needed (a brand new mode).

;; With a parent mode
(define-derived-mode foo-mode fundamental-mode "Foo"
  (do something))

;; Or nothing
(define-derived-mode foo-mode nil "Foo"
  (do something))
 Read on …
        

LSP Setup for Java

Update on <2023-06-07 Wed>

Found a much easier way to configure this and tried again with the update-to-date lsp-java and it worked magically. Can’t recall why I had configuration issues before.

Simply it would be:

  1. Make sure JDK 17 is installed (According to the requirement of lsp-java).
  2. Create a lib folder and put .jar files into it (or symlinks). See this issue.
  3. Run lsp-restart-workspace.

Voila! Now LSP works as you would expect :).

 Read on …

File-based Blog Management with ox-hugo

Background

I previously wrote a post about managing blog posts with ox-hugo in org mode. I used to follow the recommendation to keep posts under org subtrees. As posts grew, I found that the opening speed is quite slow even I didn’t have many pictures inserted. Although managing the entire site within one file does have some convenience, the slowness is something I can’t bear.

 Read on …

Use lisp-data Files in Emacs

I found that there were few posts mentioning about using lisp-data files. However, it seems to be used widely in various packages.

Emacs manumal has a very detailed description of how to read and write lisp objects. In this post I’ll mainly demonstrate one specific use case.

Read from file

The biggest challenge is to parse file content to Lisp lists. After a quick search with describe-function, read function is able to perfectly handle it in this case.

 Read on …

Arch Linux on Laptop

I recently got my new laptop and I found that some additional tweaks need to be made for laptops. Thus, this post is to have a record in case I forget when I have to reinstall the system.

Some basic setup

Unlike desktop, laptops have to be secure so encrytion is a must.

Details of how-to can be found on Arch wiki. I’m not going to go through that here. However, I’ll note down some considerations and things that need to pay attention to.

 Read on …