Sekai 🌐 🗺

Sekai (世界) is the kanji for “the world”. That’s a great word because of the scale that it designates.

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 

Upgraded to Hugo v0.135

Background

  1. 18 months ago, I used latest Docker image in GitLab container resgitry for Hugo extended at commit 168fe3d.
  2. Six years ago, I integrated static comments to this blog.
  3. Last week end, when my friend tested static comments here, she reported that @StaticmanLab’s GitLab token had been expired. As a result, I updated it and re-deployed my Staticman instance.

Problem

I wrote a sample comment containing math equations to test if it’s still working. The back-end processes were fine, but the site rebuilding wasn’t successful, as commit c531a0b reveals.

[Read More]
hugo 

Exponential Function Series Definition

An alternative definition of the exponential function through infinite series

Motivation

My previous post about the definition of the exponential function has provided no connection between a well-known characterization (or an alternative definition) of the exponential function:

$$\exp(s) = \lim_{n\to\infty} \sum_{k=1}^n \frac{s^k}{k!}.$$

The term to be summed is simpler than the one in the binomial expansion of $(1 + s / n)^n$.

Solution

We want this sum to be as small as possible as $n \to \infty$.

$$\sum_{k=2}^n \left( 1 - \frac{n \cdot \dots \cdot (n + 1 - k)} {\underbrace{n \cdot \dots \cdot n}_{n^k}} \right) \, \frac{x^k}{k!}$$

Observe that the fraction is a product

[Read More]
limits 

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 

Notes du Jour

Plus importante que les techno

Dans le classique schéma pour la gestion du projet, on met le besoin du client d’abord. C’est important de l’entendre avant de commencer le traf. Sinon, on risque de perdre des heures (ou pire des jours) sur une chose que le client ne valide pas. Avant d’y mettre l’effort, il est bon de lui montrer idée générale et de lui demander un avis, afin d’éviter de lui délivrer un produit qu’il ne veut pas.

[Read More]

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]