Skip to content

Instantly share code, notes, and snippets.

@christophberger
christophberger / graphite-demo-test-script.sh
Created August 9, 2024 15:20
Graphite Demo Verification Script
#!/usr/bin/env bash
# This script runs all steps from the article.
#
# If the folder "graphite-demo" exists,
# it trashes this folder and deletes the repo on GitHub.
MMDD=$(date "+%m-%d")
# cleanup
@christophberger
christophberger / graphite-demo-test-script.sh
Created August 9, 2024 12:59
Graphite Demo Verification Script
# This script trashes the current local repo
# and recreates all steps from the article.
#
# Start in the parent dir of the cloned repo "graphite-demo".
# Ensure the repo is deleted on GitHub (via the browser as I gave gh no delete rights.)
trash graphite-demo
# gh repo delete christophberger-articles/graphite-demo # if gh delete is activated
gh repo create christophberger-articles/graphite-demo --private --clone
@christophberger
christophberger / futures.go
Last active November 28, 2022 07:42
Code from appliedgo.net/futures
package main
import (
"fmt"
"time"
)
func main() {
c := make(chan int)
@christophberger
christophberger / append_question.go
Last active October 1, 2019 05:35
I don't know the theory;please give me a answer!!thank you
package main
import (
"fmt"
)
func main() {
x := make([]int, 1, 10)
var a []int
The Package reflect in the Go standard library implements run-time reflection, allowing a program to manipulate objects with arbitrary types.
We can build with the reflection package a kind of generic functionality. Because this package give us the possibility to determine the meta information of a function and it's input and output arguments while runtime.
Be careful when you start to use the reflection package it's hard to debug run time errors. For more information about reflection, I can recommend the following article about reflection.
See "The Laws of Reflection" for an introduction to reflection in Go: https://golang.org/doc/articles/laws_of_reflection.html
If you want see reflection in action below is a example:
@christophberger
christophberger / tui4main.go
Created April 4, 2017 09:38
Code snippet from github.com/appliedgo/tui: main
func main() {
if len(os.Args) <= 1 {
log.Println("Usage: go run tui.go [termui|gocui]")
return
}
if os.Args[1] == "termui" {
runTermui()
return
}
if os.Args[1] == "gocui" {
@christophberger
christophberger / tui3gocui.go
Last active April 4, 2017 09:39
Code snippet from github.com/appliedgo/tui: gocui
func runGocui() {
// Create a new GUI.
g, err := c.NewGui(c.OutputNormal)
if err != nil {
log.Println("Failed to create a GUI:", err)
return
}
defer g.Close()
// Activate the cursor for the current view.
@christophberger
christophberger / tui2termui.go
Last active April 4, 2017 09:39
Code snippet from github.com/appliedgo/tui: termui
func runTermui() {
// Initialize termui.
err := t.Init()
if err != nil {
log.Fatalln("Cannot initialize termui")
}
// `termui` needs some cleanup when terminating.
defer t.Close()
// Get the height of the terminal.
@christophberger
christophberger / tui1start.go
Last active April 4, 2017 09:38
Code snippet from github.com/appliedgo/tui: start
package main
// Under normal circumstances, importing two UI libraries at the
// same time is probably not a good idea, as each has its own event
// loop. This demo code takes care of using only one of these
// libraries at a time.
import (
"fmt"
"log"
"os"
@christophberger
christophberger / tui_code_1_start.go
Last active April 4, 2017 09:30
Code from github.com/appliedgo/tui
package main
// Under normal circumstances, importing two UI libraries at the
// same time is probably not a good idea, as each has its own event
// loop. This demo code takes care of using only one of these
// libraries at a time.
import (
"fmt"
"log"
"os"