AmitKumarDas / fun-with-programming

ABC - Always Be Coding
2 stars 2 forks source link

go code 0000 #84

Closed AmitKumarDas closed 2 years ago

AmitKumarDas commented 3 years ago
// tags: 
// --remote, local, 
// --schema, validation, 
// --registry, openapi, 
// --use as a go module / library
// --config, flags, 
// --cache, in-memory, ondisk, 
// --performance, goroutines, stream,
//
// til: testing output formats:
// --junit 
// --json 
// --tap 
// --text
//
// [til]:
// Kubeconform publishes Docker Images to Github's new Container Registry, ghcr.io. 
// These images can be used directly in a Github Action, once logged in using a Github Token.
//
// https://github.com/yannh/kubeconform
// https://github.com/yannh/kubeconform/blob/master/pkg/config/config.go
// 
AmitKumarDas commented 3 years ago
// https://searchitoperations.techtarget.com/tutorial/Kubernetes-performance-testing-tutorial-Load-test-a-cluster
AmitKumarDas commented 3 years ago
// tags: 
// --probes, rolling update, max surge, max unavailable
//
// https://medium.com/platformer-blog/enable-rolling-updates-in-kubernetes-with-zero-downtime-31d7ec388c81
AmitKumarDas commented 3 years ago
// [tags]: 
// --Ability to tamper with network devices at the transport level (Layer 4)
// --Ability to tamper with the TCP session layer (Layer 5)
// --HTTP requests/responses at the HTTP protocol level (Layer 7)
// --Supports custom proxy routing (aka basic reverse proxy)
// --Advanced matching rules allow you to target specific requests
// --Introduce randomness into symptoms
// --Simulate real-world network connectivity problems/partitions for mobile devices, distributed systems etc.
// --Ideal for use in CI/Test Suites to test resilience across languages/technologies
// --Simple native binary installation with no dependencies
// --Extensible and modular architecture
// --An official Docker container to simplify uses cases such as Docker Compose
//
// https://github.com/mefellows/muxy
AmitKumarDas commented 3 years ago
// [tags]
// --A TCP proxy to simulate network and system conditions for chaos and resiliency testing
//
// https://github.com/Shopify/toxiproxy
AmitKumarDas commented 3 years ago
// til: http roundtripper, github, auth, tokens, jwt, fellow
//
// https://github.com/bradleyfalzon/ghinstallation
AmitKumarDas commented 3 years ago
// til: code review
//
// https://www.netlify.com/blog/2020/03/05/feedback-ladders-how-we-encode-code-reviews-at-netlify/
// https://conventionalcomments.org/
AmitKumarDas commented 3 years ago
// tag: notifications engine, k8s, plugins, integrations, 
//
// https://blog.argoproj.io/notifications-engine-is-here-ca961cd67b87
// https://docs.google.com/document/d/1nw0i7EAehNnjEkbpx-I3BVjfZvRgetUFUZby4iMUSWU/edit#heading=h.efmu907hcczu
//
AmitKumarDas commented 3 years ago
// tags: k8s controller design, 
//
// https://github.com/argoproj/notifications-engine/blob/master/pkg/controller/controller.go
AmitKumarDas commented 3 years ago
// til: code reviews, golang, effective coding, when in doubt refer here,
// til: look out for functional options, global variables,
// til: best practices
//
// https://github.com/uber-go/guide/blob/master/style.md [fellow]
// https://github.com/Pungyeon/clean-go-article [nice]
// https://github.com/golang/go/wiki/CodeReviewComments
// https://avelinorun.medium.com/7-subjects-and-github-repositories-to-become-a-better-go-developer-2af3f2a1aaa6
AmitKumarDas commented 3 years ago
// tags: dsa in go
//
// https://github.com/TheAlgorithms/Go
AmitKumarDas commented 3 years ago
// [wip]
//
// https://martinfowler.com/articles/data-monolith-to-mesh.html
AmitKumarDas commented 3 years ago
// til: github action, docker container action
//
// https://github.com/dsaltares/fetch-gh-release-asset
AmitKumarDas commented 3 years ago
// tags: watch resources / all-in-one, goreleaser, pprof, 
// til: run from docker & connect to k8s -> host mount your kubeconfig
// til: run from docker & connect to EKS
//
// https://github.com/salesforce/sloop/
// https://github.com/salesforce/sloop/blob/master/pkg/sloop/ingress/kubewatcher.go [nice]
AmitKumarDas commented 3 years ago
// tags: job titles, fellow, resume, management vs technical
//
// https://www.holloway.com/s/trh-job-titles-levels-fundamentals-for-software-engineering?login_success=1
AmitKumarDas commented 3 years ago
// tags: makefile, fellow, build, watch, golang
//
// https://kodfabrik.com/journal/a-good-makefile-for-go
AmitKumarDas commented 3 years ago
// hash the file by reading it in chunks
// avoid use of lots of memory
func main() {
  file, err := os.Open("test.txt")
  if err != nil {
    log.Fatal(err)
  }
  defer file.Close()

  buf := make([]byte, 30*1024) // chunked buffer
  sha256 := sha256.New()
  for {
    n, err := file.Read(buf) // read into chunked buffer
    if n > 0 {
      // keep writing into hash instance
      _, err := sha256.Write(buf[:n]) // write from chunked buffer // look n
      if err != nil {
       log.Fatal(err)
      }
    }
    if err == io.EOF {
      break
    }
    if err != nil {
      log.Printf("Read %d bytes: %v", n, err)
      break
    }
  }

  sum := sha256.Sum(nil)
  log.Printf("%x\n", sum)
}
AmitKumarDas commented 3 years ago
// function currying
// functional programming
func HashString64(f func() hash.Hash64) func(string) uint64 {
  return func(s string) uint64 {
    h := f()
    h.Write([]byte(s))
    return h.Sum64()
  }
}
AmitKumarDas commented 3 years ago
// compare via xor
func Compare(a, b []byte) bool {
    a = append(a, b...)
    c := 0
    for _, x := range a {
        c ^= int(x)
    }
    return c == 0
}
AmitKumarDas commented 3 years ago
func main() {
    // Initialize the encoder and decoder.  Normally enc and dec would be
    // bound to network connections and the encoder and decoder would
    // run in different processes.
    var network bytes.Buffer        // Stand-in for a network connection
    enc := gob.NewEncoder(&network) // Will write to network
    dec := gob.NewDecoder(&network) // Will read from network

    // Encode (send) the value
    err := enc.Encode(P{3, 4, 5, "Pythagoras"})
    if err != nil {
        log.Fatal("encode error:", err)
    }

    // Decode (receive) the value
    var q Q
    err = dec.Decode(&q)
    if err != nil {
        log.Fatal("decode error:", err)
    }

    fmt.Printf("%q: {%d,%d}\n", q.Name, *q.X, *q.Y)
}
AmitKumarDas commented 3 years ago
// https://github.com/mitchellh/hashstructure/blob/master/hashstructure.go
//
// Format specifies the hashing process used. Different formats typically
// generate different hashes for the same value and have different properties.
type Format uint

const (
    // To disallow the zero value
    formatInvalid Format = iota

    // FormatV1 is the format used in v1.x of this library. This has the
    // downsides noted in issue #18 but allows simultaneous v1/v2 usage.
    FormatV1

    // FormatV2 is the current recommended format and fixes the issues
    // noted in FormatV1.
    FormatV2

    formatMax // so we can easily find the end
)
AmitKumarDas commented 3 years ago
// naming, go, design, modular, pattern
// model, behaviour, constructor & options

type hashable struct {
  Labels      map[string]string
  Annotations map[string]string
  Finalizers  []string
}

// HashOptions is useful to create new instances of
// Hashing
type HashOptions struct {
  hashable
}

// Hashing computes the hash
type Hashing struct {
  h *hashable
}

// NewHasher returns a new instance of Hashing
func NewHasher(opts HashOptions) *Hashing {
  return &Hashing{
    h: &hashable{
      Labels:      opts.Labels,
      Annotations: opts.Annotations,
      Finalizers:  opts.Finalizers,
    },
  }
}

// Sum computes the final hash
func (e *Hashing) Sum() (uint64, error) {...}