blog
Table des matières
- 2026:
- 2025:
4 billet(s) pour juillet 2026
| Procédure simple augmentation de la SWAP | 2026/07/17 15:49 | Jean-Baptiste |
| Exemple git clone avec Ansible | 2026/07/16 14:47 | Jean-Baptiste |
| Windows exe - Comparaison de fichiers binaires | 2026/07/16 10:25 | Jean-Baptiste |
| Pb git | 2026/07/01 17:36 | Jean-Baptiste |
Go lang - regex
// Source - https://stackoverflow.com/a/41551456 // Posted by Mr_Pink, modified by community. See post 'Timeline' for change history // Retrieved 2026-05-14, License - CC BY-SA 3.0 func IsMatchingRegex(s string, regex string) bool { return regexp.MustCompile(regex).MatchString(s) }
Go lang - goroutines
Voir :
Pb sortie de main avant terminaisons des goroutines - Attendre la fin de toutes les goroutines avant de terminer le programme (la fonction main)
Voir :
Solution naïve
import ( "runtime" "time" ) func wait_all_goroutines() { for runtime.NumGoroutine() > 1 { time.Sleep(500 * time.Millisecond) } } func main() { defer fmt.Println("FIN") // Last defer defer wait_all_goroutines() ch := make(chan int) go evenSum(1, 100, ch) }
Afficher les résultats des goroutine de la plus rapide à la plus longue
Voir :
ch1 := make(chan int) ch2 := make(chan int) go evenSum(1, 10, ch1) go squareSum(1, 10, ch2) for range 2 { select { case r1 := <-ch1: fmt.Println(r1) case r2 := <-ch2: fmt.Println(r2) } }
Notes code dev - qualité de code - bonnes pratiques - sécu
Voir :
Points:
- Testing
- Negative testing (tests that should cause failures)
- Detect and check unreachable code, e.g., via warning flags (static analysis)
- Forbid misleading indentation (static analysis)
- Detect duplicate lines in source code (static analysis)
- Make access failure the default (static analysis)
- Make your methods do only one thing
- Use readable, descriptive variable names
4 tools:
- ASan (Address Sanitizer)
- MSan (Memory Sanitizer)
- UBSan (Undefined Behaviour Sanitizer)
- Valgrind
- fuzzing
Source : https://www.cl.cam.ac.uk/~nk480/C1819/lecture5.pdf
Autres
- AddressSanitizer (detects addressability issues) and LeakSanitizer (detects memory leaks)
- ThreadSanitizer (detects data races and deadlocks) for C++ and Go
- MemorySanitizer (detects use of uninitialized memory)
- HWASAN, or Hardware-assisted AddressSanitizer, a newer variant of AddressSanitizer that consumes much less memory UBSan, or UndefinedBehaviorSanitizer
Source : https://github.com/google/sanitizers
Go lang - notebook - Jupyter
Voir aussi :
Voir la liste des Kernels pour Jupyter :
podman run -it -p 8888:8888 docker.io/gopherdata/gophernotes
Source : https://github.com/gopherdata/gophernotes
Install NOK sous Debian mais fonctionne en conteneur
Introspection / reflection
Voir :
Utile pour l’introspection :
reflect.TypeOf
import "reflect" reflect.TypeOf(print) // fast.Builtin reflect.TypeOf(fmt.Println) // func(...interface {}) (int, error)
Go lang - GUI
Par nature Go n'est pas orienté utilisateur.
L'interface graphique “naturelle” à Go est le Web (WebUI)
Cependant il est possible d'utiliser :
- Tk9 https://pkg.go.dev/modernc.org/tk9.0 pour des applis simple et portable CGo-free il est vraiment natif Go et crossplatform
- Qt avec https://github.com/mappu/miqt Qt est la référence
- Wails projet prometteur, mais pas compatible pour les anciennes versions. nécessite Node (Svelte, React, Vue, Preact, Lit, Vanilla)
- Flutter : Pour Android
Qt - miqt
package main import ( "fmt" "os" "github.com/mappu/miqt/qt" ) func main() { qt.NewQApplication(os.Args) btn := qt.NewQPushButton3("Hello world!") btn.SetFixedWidth(320) var counter int = 0 btn.OnPressed(func() { counter++ btn.SetText(fmt.Sprintf("You have clicked the button %d time(s)", counter)) }) btn.Show() qt.QApplication_Exec() fmt.Println("OK!") }
blog.txt · Dernière modification : de 127.0.0.1
