Skip to content

Instantly share code, notes, and snippets.

@thorsphere
thorsphere / repository_sqlite.go
Last active May 27, 2026 19:25
SQLite prototype for the tsecon economic‑calendar EventRepository: This is the SQLite implementation of the EventRepository interface from my economic‑calendar package. It was used for local prototyping and testing. I’m keeping it here as a reference/snapshot, while the actual production code now relies on Firestore. Contains an upsert query, pa…
// Copyright (c) 2026 thorsphere.
// All Rights Reserved. Use is governed with GNU Affero General Public License v3.0
// that can be found in the LICENSE file.
package tsecon
// Import standard library packages and third-party packages for database/sql, time, and custom error handling and file I/O utilities.
import (
"context"
"database/sql" // database/sql for interacting with the SQLite database
"time" // time for handling event timestamps
@thorsphere
thorsphere / safe_var.go
Last active August 13, 2023 15:26
Safe_var.go provides thread-safe variables of any type.
// Safe_var.go provides thread-safe variables of any type. The value of the variable is retrieved by Get.
// The value of the variable is set with Set.
//
// Version v1.0
// Date 13 Aug 2023
//
// Copyright (c) 2023 thorstenrie.
// All Rights Reserved. Use is governed with GNU Affero General Public License v3.0
// that can be found in the LICENSE file.
package main
@thorsphere
thorsphere / context-tutorial.go
Last active July 15, 2023 21:06
Go context tutorial
package main
import (
"context"
"fmt"
"time"
)
// A key for context.WithValue should be of its own type and should not be a built-in type like string
// to avoid collisions between packages using contexts.
@thorsphere
thorsphere / exercise-web-crawler.go
Created April 10, 2022 21:02
A solution to the exercise in A Tour of Go
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
Fetch(url string) (body string, urls[]string, err error)
}
@thorsphere
thorsphere / exercise-images.go
Last active April 10, 2022 09:01
A solution to the exercise in A Tour of Go
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct{
w, h int
@thorsphere
thorsphere / exercise-loops-and-functions.go
Created April 9, 2022 18:39
A solution to the exercise in A Tour of Go
package main
import (
"fmt"
"math"
)
// Constants
const i_max int = 100
const v_test float64 = 123.987