Skip to content

Instantly share code, notes, and snippets.

:octocat:
Focusing

kamal namdeo kamal-github

:octocat:
Focusing
Block or report user

Report or block kamal-github

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kamal-github
kamal-github / Go Visitor Pattern
Created Sep 26, 2019
Go Visitor Pattern to pass and apply options
View Go Visitor Pattern
type Logger struct {
Prop1 string
Prop2 string
}
type Option func(l *Logger) error
func Prop1Option() Option {
return func(l *Logger) error {
l.Prop1 = "hello"
View serviceK8s.md

Notes for K8s Services

  • create a simple service
  • expose stable address
  • expose through Env var and DNS
  • services should be created b4 client pods for th8 service
  • service name is hostname for service apart from IP, which is maintained in DNS server pod in kube-system namespace
  • Expose/Impose the external machines to Cluster and make them available to pods in the cluster -> 1) create service without selector and create Endpoints resource with external IPs. now Pods can access out of cluster nodes throough that service.
View Summary-Go for industrial programming by Peter Bourgan.md

Main/Summary points of Go for Industrial Programming, Video

  • Do not decide your project Structure at the very end, it evolves!
  • Make configuration based sysytem, and flags are the best way to change the behaviour of your syetem function.
  • Manage goroutines lifecycle, thy are prone to leak, Always think of how this gorouting will finish/interrupt. Always try to pass some sort of interrupt func/context to interrupt e.g. func foo(execFunc func(...args interface{}) error, interupptFunc func() error) or listening to context.Done
  • Use interface at the consumer side not at the implementation package, interfaces are really good to mock the dependencies.
  • Must watch, Advanced Testing with go
  • Do not misuse context, make context Value only request scoped like request ID for DT or au
@kamal-github
kamal-github / DockerStorage.md
Last active Nov 4, 2018
Docker: Bind Mount vs Volumes
View DockerStorage.md

Bind Mount vs Volumes

  • When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its full or relative path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.
  • The file or directory does not need to exist on the Docker host already. It is created on demand if it does not yet exist.
  • Both allow sharing contents amoung containers
  • Prepopulated contents obsucured in case of Bind Mount while Volume sync the contents from containers to Docker host.
  • Bind Propagation exixt only in Bind Mount.
  • Unlike a bind mount, you can create and manage volumes outside the scope of any container.
    • Create a volume: $ docker volume create my-vol
@kamal-github
kamal-github / squash-commits.sh
Created Oct 18, 2018 — forked from jbub/squash-commits.sh
git squash last two commits into one
View squash-commits.sh
git rebase --interactive HEAD~2
# we are going to squash c into b
pick b76d157 b
pick a931ac7 c
# squash c into b
pick b76d157 b
s a931ac7 c
@kamal-github
kamal-github / ZshSetup.md
Last active Oct 16, 2018
Zsh Setup with Ohmyzsh
View ZshSetup.md
@kamal-github
kamal-github / GoPattAllStartAtSameTime
Last active Jul 24, 2018
Pattern to start all go routines only after all are created
View GoPattAllStartAtSameTime
// Pattern to start all go routines only after all are created.
func goRoutine() {
<-start
// do whatever
}
func main() {
start := make(chan, struct{})
@kamal-github
kamal-github / sync_pool.go
Last active Jun 19, 2018
Pool implementation using buffered channel
View sync_pool.go
// Pool holds Clients.
type Pool struct {
pool chan *Client
}
// NewPool creates a new pool of Clients.
func NewPool(max int) *Pool {
return &Pool{
pool: make(chan *Client, max),
}
@kamal-github
kamal-github / priority_queue.go
Created Apr 6, 2018
using heap given by go library
View priority_queue.go
// This example demonstrates a priority queue built using the heap interface.
package main
import (
"container/heap"
"fmt"
)
// An Item is something we manage in a priority queue.
type Item struct {
You can’t perform that action at this time.