Skip to content

Instantly share code, notes, and snippets.

func GetVal(data map[string]any, key string) (result any, found bool) {
for k, v := range data {
if k == key {
return v, true
} else {
switch v.(type) {
case map[string]any:
if result, found = GetVal(v.(map[string]any), key); found {
return
}
@kitlabcode
kitlabcode / example_test.go
Created April 27, 2023 01:01
Setup and teardown unit test in go.
package main
import (
"log"
"testing"
)
func doubleMe(x float64) float64 {
return x * 2
}
@kitlabcode
kitlabcode / StartOverLoop.go
Created April 20, 2023 15:38
When loop meets a condition start the loop over again.
package main
import "fmt"
func main() {
slice := []int{1, 2, 3, 4, 5}
var count int
for i := 0; i < len(slice); i++ {
@kitlabcode
kitlabcode / snippet.go
Created April 13, 2023 22:04
try function until
// You can edit this code!
// Click here and start typing.
package main
import (
"context"
"fmt"
"time"
)
@kitlabcode
kitlabcode / copy_slice_and_append.go
Created April 13, 2023 20:10
copy slice and append - used to build permutations
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
type Item struct {
name string
number int
}
rtmp {
server {
listen 1935;
chunk_size 4000;
# TV mode: one publisher, many subscribers
application tv {
@kitlabcode
kitlabcode / gist:0f9e3003e731af5ed6a0
Created October 12, 2015 20:21
create ts files from H.264 or MPEG-2 files with ffmpeg
ffmpeg -i input.avi -vcodec copy -acodec copy -f mpegts output-file.ts
@kitlabcode
kitlabcode / Finding a dot product
Created May 27, 2015 10:03
Finding a dot product
int[] v1 = {1,2,3};
int[] v2 = {3,2,1};
// dot product of vector
int[] dotProducts = v1.DotProduct(v2);
// output:
// 3
// 4
// 3
public static int[] DotProduct(this int[] vector1, int[] vector2)
@kitlabcode
kitlabcode / LINQ Full Outer Exclusive Join
Last active August 29, 2015 14:21
LINQ Full Outer Exclusive Join
var fullOuterExclusiveJoin = Context.Artists.FullOuterExclusiveJoin(Context.Albums, artist => artist.Id, album => album.ArtistId,
(artist, album) => new { ArtistName = artist != null ? artist.Name : "Not Found", AlbumName = album != null ? album.Name : "Not Found" });
@kitlabcode
kitlabcode / LINQ Right Exclusive Join
Created May 24, 2015 19:31
LINQ Right Exclusive Join
var rightExclusiveJoin = Context.Artists.RightExclusiveJoin(Context.Albums, artist => artist.Id, album => album.ArtistId,
(artist, album) => new { ArtistName = artist != null ? artist.Name : "Not Found", AlbumName = album != null ? album.Name : "Not Found" });