Optimisation d'une VM GCP et domptage de Neovim

Aujourd’hui, j’ai passé ma configuration de développement sur une VM Google Cloud Platform (GCP). Entre les contraintes de ressources de la machine et le peaufinage de mon environnement Neovim pour mon projet Rust, voici ce que j’ai appris.

1. Transfert de fichiers avec rsync

Pour uploader mes dossiers de projet vers la VM, j’ai utilisé rsync. C’est bien plus efficace que scp car il ne transfère que les modifications.

rsync -avzLP --exclude='.git' \ 
  ~/.local/share/typst/packages/preview/auto-mando/ \
  user@$(gcloud compute instances describe typst-bot-vm \
    --format='get(networkInterfaces[0].accessConfigs[0].natIP)' \
    --zone='us-east1-d'):~/

Le « combo doré » :

[Read More]
GCP  Linux  Neovim  Rust  DevOps 

Rust Project Structure for rust-canto

Lessons from vibe coding

Background

I created my first crate rust-canto even though I didn’t know Rust, so that I can bring automatic Cantonese word segmentation and romanizations into Typst.

This is a great idea. Moving from a complex xtask workspace to a streamlined build.rs and build.sh workflow is a common evolution for Rust projects, especially when targeting WebAssembly.

Five lessons learnt from chat bot

1. Avoid the “Crates.io Path Dependency” Trap

  • The Problem: Using a Workspace with a local helper crate.

    [Read More]

Typst Package for Jyutcitzi

Background

As a native Cantonese speaker, I found it inconvenient to repeat all the time when I have to teach others how to speak my language. I acquired Jyutping (粵拼) a couple of years ago. It’s a popular phonetic system for the Cantonese language. However, some of my fellow countrymen aren’t fond of this romanization scheme.

A soft “introduction” to “Introduction to Jyutcitzi”

Recently, I’ve heard of another phonetic system called Jyutcit (粵切). It’s basically a “cutting sound method” (切音法). Each syllable is “initial + final”. To compose a sound, we take two syllables, from which we keep

[Read More]

Imprimante HP Deskjet 4100 sous Linux

Introduction

J’ai récupéré une imprimante HP DeskJet Plus 4122. Je m’en rarement servais car je pensais à tort que HP ne marchait que sous Windows. J’aime tellement Linux que je me connectais pas souvent à Windows, où l’appli HP Smart est bloquée de temps en temps.

Cet après-midi, après une petite recherche, je me suis rendu compte qu’il y avait une pilote HP Linux Imaging and Printing (HPLIP) pour Linux. J’ai décidé de l’essayer sur mon système Lubuntu 24.04.

[Read More]
HP  Linux  Printer 

Tikz Loop Over Coordinates

This is my belated response to a self-identified dupe on TeX.SE.

Background

The list in a \foreach loop is often long.

\foreach \pointA/\pointB in {{(1,0)}/{(2,2)},{(3,4)}/{(2,1)}} {
  \draw \pointA -- \pointB;
}

Imagine having several other loop variables. The code inside the {…} list won’t be readable.

Problem

How can I make it looks smarter?

\foreach \pointA/\pointB in {
  {(1,0)}/{(2,2)},{(3,4)}/{(2,1)}
} {
  \draw \pointA -- \pointB;
}

doesn’t work.

Inspiration

Recently, I was asked the way to make two graphs to illustrate a complex function.

[Read More]
LaTeX 

Start Oracle From Git Bash

Goal

To run Oracle SQL in Git Bash.

Assumption

You have sqlplus added to your PATH.

export PATH=${PATH}:/c/oraclexe/app/oracle/product/11.2.0/server/bin/

Problem

The option /nolog doesn’t work as expected.

$ sqlplus /nolog

SQL*Plus: Release 11.2.0.2.0 Production on Mer. Juin 7 09:43:47 2023

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


When SQL*Plus starts, and after CONNECT commands, the site profile
(e.g. $ORACLE_HOME/sqlplus/admin/glogin.sql) and the user profile
(e.g. login.sql in the working directory) are run.  The files may
contain SQL*Plus commands.

Refer to the SQL*Plus User's Guide and Reference for more information.

Solution

Luckily, googling “start sqlplus from git bash”, I found the solution in this related Oracle Forum post: using an extra slash will do, i.e. sqlplus //nolog.

[Read More]

Closer Look into ArrayList Iterator

Background

Given an ArrayList of Integers from 0 (inclusive) to 10 (exclusive) with step size 1. We use a while-loop and an Iterator<Integer> to check if this ArrayList hasNext() element, before we remove() the current element.

Problem

The code below throws an IllegalStateException.

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class UnderstandArrayListIterator {
    public static void main(String[] args) {
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            a.add(i);
        }
        Iterator<Integer> iter = a.iterator();
        iter.next();
        while (iter.hasNext()) {
            iter.remove();
        }
    }
}

Discussion

After invoking remove(), lastRet is set to -1, so next time that this method is invoked, the condition lastRet < 0 in the if-block is satisfied, resulting in an IllegalStateException.

[Read More]
Java 

Passed Codingame Java Certification Test

A note to some forgotten methods

String regex replace using capture groups

Since Java SE 9, java.util.regex.Matcher’s replaceAll() method supports lambda expressions.

// import java.util.regex.*;
String varName = "random_string";
Pattern pattern = Pattern.compile("_([a-z])");
Matcher matcher = pattern.matcher(varName);
String result = matcher.replaceAll(m -> m.group(1).toUpperCase());

Source: Arvind Kumar Avinash’s answer on Stack Overflow

Check characters properties using Character’s static methods

The Character class provides some static predicates like

  • isAlphabetic(char c)
  • isDigit(char c)
  • isLowerCase(char c)

Source: Java Character isAlphabetic() Method on Javapoint

[Read More]