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]

Exploration of My First IntelliJ Project

We’ll try to stay in the project root if possible.

Find all non-hidden files to know the file structure.

$ find -path './.*' -prune -o -type f -print
./Algo-init.iml
./out/production/Algo-init/fr/eql/ai114/algo/init/demo/_1_HelloWorld.class
./src/fr/eql/ai114/algo/init/demo/_1_HelloWorld.java
  • -prune returns true for the chosen path and prevents find from descending.

  • -o means OR, so the paths matching -prune won’t pass through -o.

  • -type f selects files, not folders.

  • By default, AND is used to connect different conditions.

    [Read More]

Reuse Commands with Shell Arguments

My arguments for arguments, functions and alias

Background

We often want to test the output with different values for a parameter. Here’s an example: we have a parameter that pandoc icon pandoc uses to / compile source code files to PDF / M$ Word / etc.

rm output.html; param=0; pandoc input$param.txt -o output.html; \
echo param = $param

In practice, a parameter can be a font, the font size, etc, and there can be multiple parameters.

[Read More]
linux  tcsh 

Some Public APIs to Be Viewed

API description
JSON Placeholder mock REST APIs for development only
Google Translate generate free translations up to a certain limit
Open Weather Map weather prediction across the world
REST Countries info about the world’s countries
IP API data about IP addresses
Random Data API like the first one, but with a sharper focus on random data
Pokemon API info about Pokemon with recent introduction of GraphQL API