Skip to content

Instantly share code, notes, and snippets.

View TGITS's full-sized avatar

Christophe Vaudry TGITS

View GitHub Profile
@TGITS
TGITS / CopyOfExample.java
Created September 19, 2026 10:06
Exemple d'utilisation de List.copyOf()
///usr/bin/env jbang "$0" "$@" ; exit $?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class CopyOfExample {
public static void main(String args[]) {
@TGITS
TGITS / BetterUnmodifiableListsLimitsExample.java
Created September 19, 2026 09:48
Exemple des limites sur l'immuabilité d'une liste même quand on passe par une copie
///usr/bin/env jbang "$0" "$@" ; exit $?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class GreatHouse {
private String name;
@TGITS
TGITS / ImmutableListCopyExample.java
Last active September 19, 2026 10:29
Création d'une liste mutable à partir d'une liste immutable
///usr/bin/env jbang "$0" "$@" ; exit $?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class ImmutableListCopyExample {
public static void main(String args[]) {
List<String> unmutableGreatHouses = List.of("Stark", "Arryn", "Lannister", "Martell", "Targaryen", "Tully", "Greyjoy", "Tyrell", "Baratheon");
@TGITS
TGITS / ImmutableListsExample.java
Last active September 18, 2026 14:55
Liste immutable en Java avec List.of()
///usr/bin/env jbang "$0" "$@" ; exit $?
import java.util.List;
class ImmutableListsExample {
public static void main(String args[]) {
List<String> greatHouses = List.of("Stark", "Arryn", "Lannister", "Martell", "Targaryen", "Tully", "Greyjoy", "Tyrell", "Baratheon");
System.out.println("Great Houses of Westeros: " + greatHouses);
@TGITS
TGITS / BetterUnmodifiableListsExample.java
Last active September 19, 2026 10:22
Exemple de création de liste non-modifiable à partir d'une copie défensive
///usr/bin/env jbang "$0" "$@" ; exit $?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class BetterUnmodifiableListsExample {
public static void main(String args[]) {
@TGITS
TGITS / UnmodifiableListsExample.java
Last active September 18, 2026 14:37
Exemple de liste non-modifiable avec les limites et risques de l'approche
///usr/bin/env jbang "$0" "$@" ; exit $?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
class UnmodifiableListsExample {
public static void main(String args[]) {
@TGITS
TGITS / equivalent_while_loop_without_break.py
Last active February 20, 2025 12:43
Exemple boucle avec while et sans break équivalente à celles avec le for et un break.
noble_gaz = [
{"name": "HELIUM", "symbol": "He", "atomic number": 2},
{"name": "NEON", "symbol": "Ne", "atomic number": 10},
{"name": "ARGON", "symbol": "Ar", "atomic number": 18},
{"name": "KRYPTON", "symbol": "Kr", "atomic number": 36},
{"name": "XENON", "symbol": "Xe", "atomic number": 54},
{"name": "RADON", "symbol": "Rn", "atomic number": 86},
]
symbol = input("Entrer le symbole d'un gaz noble: ")
@TGITS
TGITS / ex_loop_with_else.py
Last active February 20, 2025 12:43
Exemple d'une boucle for avec une clause else
noble_gaz = [
{"name": "HELIUM", "symbol": "He", "atomic number": 2},
{"name": "NEON", "symbol": "Ne", "atomic number": 10},
{"name": "ARGON", "symbol": "Ar", "atomic number": 18},
{"name": "KRYPTON", "symbol": "Kr", "atomic number": 36},
{"name": "XENON", "symbol": "Xe", "atomic number": 54},
{"name": "RADON", "symbol": "Rn", "atomic number": 86},
]
symbol = input("Entrer le symbole d'un gaz noble: ")
@TGITS
TGITS / ex_loop_without_else.py
Last active February 20, 2025 12:43
Exemple de script avec une boucle for sans clause else
noble_gaz = [
{"name": "HELIUM", "symbol": "He", "atomic number": 2},
{"name": "NEON", "symbol": "Ne", "atomic number": 10},
{"name": "ARGON", "symbol": "Ar", "atomic number": 18},
{"name": "KRYPTON", "symbol": "Kr", "atomic number": 36},
{"name": "XENON", "symbol": "Xe", "atomic number": 54},
{"name": "RADON", "symbol": "Rn", "atomic number": 86},
]
symbol = input("Entrer le symbole d'un gaz noble: ")
@TGITS
TGITS / null_safety_chaining_operator.js
Created December 1, 2024 17:12
Exemple d'utilisation de l'opérateur de chaînage optionnel
let pokemon = {
name: "Bulbasaur",
type: [
"Grass",
"Poison"
],
base: {
hp: 45,
attack: 49,
defense: 49,