Skip to content

Instantly share code, notes, and snippets.

View abursavich's full-sized avatar

Andy Bursavich abursavich

  • AppLovin
  • Berkeley, CA
View GitHub Profile
@abursavich
abursavich / native.go
Created November 29, 2020 02:49
native endianness
package foo
import (
"encoding/binary"
"unsafe"
)
var NativeEndianV1 = func() binary.ByteOrder {
switch *(*uint32)(unsafe.Pointer(&[4]byte{1, 2, 3, 4})) {
case 0x01020304:
@abursavich
abursavich / clone.go
Created August 14, 2020 00:42
deep clone
type seenMap map[interface{}]reflect.Value
// Clone returns a deep clone of v.
// Any unexported fields will be unset.
func Clone(v interface{}) interface{} {
src := reflect.ValueOf(v)
dst := reflect.New(src.Type()).Elem()
reflectCopy(dst, src, seenMap{})
return dst.Interface()
}
@abursavich
abursavich / config.go
Last active July 30, 2020 20:46
WIP: prometheus service discovery dependency inversion
// Copyright 2016 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@abursavich
abursavich / sealedsecrets.py
Last active June 1, 2021 04:38
kubespec usage example
import hashlib
from typing import Dict, List
import yaml
from kubespec import context, types
from kubespec.k8s import base
from kubespec.k8s.api.apps import v1 as appsv1
from kubespec.k8s.api.core import v1 as corev1
from kubespec.k8s.api.rbac import v1 as rbacv1
from kubespec.k8s.apiextensions.apiextensions import v1beta1 as apiextv1b1
// Package gogomarshal contains marshaling code extracted from
// github.com/grpc-ecosystem/grpc-gateway/runtime and altered
// to depend on gogo versions of the proto and jsonpb packages.
package gogomarshal
import (
"bytes"
"encoding/json"
"fmt"
"io"
package oauth2
import (
"errors"
"io"
"net/http"
"sync"
"time"
"github.com/golang/groupcache/singleflight"
package main
import "fmt"
func main() {
fmt.Println("Hello, gist")
}
package main
import "fmt"
func main() {
fmt.Println(hello)
}
/*
$ go test --bench .
PASS
Benchmark_TypeMap_Get-8 50000000 39.0 ns/op
Benchmark_RWMutex_RLock-8 50000000 48.4 ns/op
Benchmark_RWMutex_Lock-8 50000000 66.5 ns/op
Benchmark_Mutex_Lock-8 50000000 49.4 ns/op
Benchmark_Concurrent_RWMutex_RLock-8 50000000 39.5 ns/op
Benchmark_Concurrent_RWMutex_Lock-8 10000000 241 ns/op
Benchmark_Concurrent_Mutex_Lock-8 10000000 228 ns/op