Skip to content

Instantly share code, notes, and snippets.

View kahlys's full-sized avatar
🙀
screaming

kahlys kahlys

🙀
screaming
View GitHub Profile
@kahlys
kahlys / go-project-layout.md
Created April 20, 2023 09:01 — forked from candlerb/go-project-layout.md
Suggestions for go project layout

If someone asked me the question "what layout should I use for my Go code repository?", I'd start by asking back "what are you building: an executable, or a library?"

Single executable

Stage 1: single source file

Create a directory named however you want your final executable to be called (e.g. "mycommand"), change into that directory, and create the following files:

package orderedmap
type Map[K comparable, V any] struct {
store map[K]V
keys []K
}
// NewMap returns a new Map.
func NewMap[K comparable, V any]() *Map[K, V] {
return &Map[K, V]{
@kahlys
kahlys / copier.go
Last active March 17, 2022 14:19
Copy slice of struct A to slice of struct B using generics
package main
import (
"fmt"
)
type A struct {
Name string
}
@kahlys
kahlys / filter_generics.go
Last active February 29, 2024 23:25
golang filters on struct arrays using generics
// https://go2goplay.golang.org/p/YF6fsuohucV
package main
import (
"fmt"
"strings"
)
type Array struct {

HOW TO

Install vue-cli

$ yarn global add @vue/cli

$ vue --version
@vue/cli 4.5.11
@kahlys
kahlys / monitoring_red.go
Last active August 29, 2023 07:00
Golang RED Monitoring with go-metrics and prometheus
package main
import (
"log"
"net/http"
"time"
"github.com/armon/go-metrics"
"github.com/armon/go-metrics/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
package main
import (
"encoding/json"
"flag"
"fmt"
"html"
"io/ioutil"
"log"
"net/http"
package main
import (
"bytes"
"fmt"
"io"
"os"
"strings"
"sync"
"time"
var requestURL =
"https://gist.githubusercontent.com/kahlys/25c733f0ab96d1532066b0727b00ef10/raw/1c62b52fbc53f8debc5464d08c86264192ed666a/superheroes.json";
var request = new XMLHttpRequest();
request.open("GET", requestURL);
request.responseType = "json";
request.send();
request.onload = function () {
var superHeroes = request.response;
console.log(superHeroes);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello Bulma!</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.2/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
</head>