Skip to content

Instantly share code, notes, and snippets.

@kai5263499
kai5263499 / lint-test-semver.yml
Created January 26, 2022 14:36
go test and lint github action
name: build lint and test
on: push
jobs:
lint:
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@v2
@kai5263499
kai5263499 / log-compacted-topic.go
Last active September 16, 2021 14:47
Create log compacted topic in golang
package main
import (
"context"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/kafka"
"github.com/caarlos0/env"
@kai5263499
kai5263499 / goofy_sort.go
Created July 21, 2021 21:20
Turn a string of ints like "1,3,2" into a sorted string like "1,2,3"
func sortStringOfInts(unsorted string) (string, error) {
unsortedStringElements := strings.Split(unsorted, ",")
intSlice := make([]int, len(unsortedStringElements))
for i, s := range unsortedStringElements {
intSlice[i], _ = strconv.Atoi(s)
}
sort.Ints(intSlice)
@kai5263499
kai5263499 / go_meetup_challenge.go
Created July 10, 2019 02:33
Irvine Golang Meetup Code Challenge 7/9/2019
package main
import (
"html/template"
"net/http"
"reflect"
)
type UserData struct {
FullName string `name:"fullname" desc:"Full name"`
@kai5263499
kai5263499 / main.c
Last active March 13, 2018 23:38
Packing two events into one binary blob and parsing them back out again
#include <stdio.h>
#include <stdlib.h>
#include "test.pb-c.h"
int main(int argc, const char * argv[]) {
Myproto *msg;
// the bytes from the combined tracer and msg proto generated from go
char msg_bytes[] = { 0xA8, 0x38, 0x01, 0xB2, 0x38, 0x0D, 0x6D, 0x79, 0x20, 0x74, 0x72, 0x61, 0x63, 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0xBA, 0x38, 0x0F, 0x6D, 0x6F, 0x72, 0x65, 0x20, 0x74, 0x72, 0x61, 0x63, 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x08, 0x02, 0x12, 0x07, 0x6d, 0x79, 0x20, 0x74, 0x65, 0x73, 0x74 };
size_t msg_len = sizeof(msg_bytes);
@kai5263499
kai5263499 / grpc.go
Created February 7, 2018 14:56
start a grpc server
type Config struct {
GrpcPort int `config:"default=8080;usage="`
UseTLS bool `config:"default=false;usage="`
SSLCertFile string `config:"default=ssl.crt;usage=SSL public key file"`
SSLKeyFile string `config:"default=ssl.key;usage=SSL private key file"`
}
type Server struct {
conf *Config
contentProcessorServer *request_processor.ContentProcessorServer
@kai5263499
kai5263499 / vim-notes.vim
Last active December 30, 2017 00:19
Vim notes
Pretty-print json:
%!python -m json.tool
@kai5263499
kai5263499 / tls_server.go
Created November 10, 2017 16:38
Serve TLS using an in-memory byte slice instead of a cert file
func ListenAndServeTLS(srv *http.Server, certPEMBlock, keyPEMBlock []byte) error {
addr := srv.Addr
if addr == "" {
addr = ":https"
}
config := &tls.Config{}
if srv.TLSConfig != nil {
*config = *srv.TLSConfig
}
if config.NextProtos == nil {
@kai5263499
kai5263499 / go_tools.md
Last active November 4, 2017 17:55
Misc Golang development tools
@kai5263499
kai5263499 / fix-author.sh
Created October 30, 2017 15:53
Fix author attribution in git repo
git rebase -i $HASH
git commit --amend --author="Wes Widner <kai5263499@gmail.com>" --no-edit