Skip to content

Instantly share code, notes, and snippets.

View tiemma's full-sized avatar
🎯
Focusing

Bakman tiemma

🎯
Focusing
View GitHub Profile
'''
Given N number of coins ranging from 1 up to N, find the minimum number of
coins that sum up to K such that the coins are only used once.
'''
def solution(N, K):
print()
@tiemma
tiemma / metrics
Created February 28, 2021 20:08
simple counter
failedImageDownloads = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "image_download_failures",
Help: "Number of failed image downloads",
},
[]string{"name", "namespace", "kind", "image", "err_type"},
)
@tiemma
tiemma / recover.go
Created February 28, 2021 17:58
this is not so nice
// excerpt from https://yourbasic.org/golang/recover-from-panic/
func main() {
n := foo()
fmt.Println("main received", n)
}
func foo() (m int) {
defer func() {
if err := recover(); err != nil {
fmt.Println(err)
@tiemma
tiemma / panic.go
Created February 28, 2021 17:43
panic everywhere
// errors in go are a type
func returnErr() (string, error) {
return "", fmt.Errorf("An error occurred")
}
// errors do not propagate
// we do not try-catch
// we handle the error like "Real Men"
res, err := returnErr()
@tiemma
tiemma / error_handle.go
Created February 28, 2021 17:39
Handling errors in go
// errors in go are a type
func returnErr() (string, error) {
return "", fmt.Errorf("An error occurred")
}
// errors do not propagate
// we do not try-catch
@tiemma
tiemma / graph-utils.js
Created November 9, 2020 16:26
Describes cycle detection and topological sorting methods for a project
const Queue = require('./structures');
const { debugLogger } = require('./logger');
const logger = debugLogger(__filename);
const resolveDependencyIfUnknown = (node) => {
if (node && node.dependencies) {
return node.dependencies;
}
func getFnIndex(numberOfDigits int) int{
// From my analysis, the fibonacci number follows a plot along 5x of the number
// approximately in relation to its number of digits
maxDelta := 5 * (numberOfDigits)
for maxDelta > 0 {
if numberOfDigits > getDigitLengthBinet(maxDelta) {
fmt.Println("Approximate value", 5 * numberOfDigits)
fmt.Println("Actual value", maxDelta + 1)
func plotFunc(num float64){
p, err := plot.New()
if err != nil {
panic(err)
}
p.Title.Text = "Functions"
p.X.Label.Text = "X(5*k)"
p.Y.Label.Text = "Y(k)"
func plotDifference(num float64){
p, err := plot.New()
if err != nil {
panic(err)
}
p.Title.Text = "Differences"
p.X.Label.Text = "X"
p.Y.Label.Text = "Y"
exp := plotter.NewFunction(func(x float64) float64 {
func getDigitLengthBinet(n int) int {
// We use a reverse implementation of the Binet formula
// Binet Formula gives the fibonacci digit but we can apply
// A log to that formula to obtain the digit count
var phi float64= (1 + math.Sqrt(5)) / 2
nDigits := float64(n) * math.Log10(phi) - (math.Log10(5) / 2)
return int(math.Ceil(nDigits))