Skip to content

Instantly share code, notes, and snippets.

@sunny-b
sunny-b / common.mk
Created May 3, 2023 15:56
test makefile
SHELL := /bin/bash
KUBECONTEXT ?= m-ci-a-ea1-us
KUBECONFIG ?= "${HOME}/.kube/config"
.PHONY: e2e
e2e:
@if [ -f go.mod ]; then \
echo "Running Go tests..."; \
go mod tidy; \
KUBECONFIG=$(KUBECONFIG) KUBECONTEXT=$(KUBECONTEXT) go test -test.v -race -tags=e2e ./...; \
@sunny-b
sunny-b / dockerfile.sh
Created February 3, 2023 04:18
dockerfile tag test
#!/bin/bash
echo 'FROM alpine:3.12\nENTRYPOINT ["echo", "this is version 1"]' > Dockerfile
docker build -t $DOCKER_USER/tag_test .
docker run $DOCKER_USER/tag_test # 'this is version 1'
docker tag $DOCKER_USER/tag_test $DOCKER_USER/tag_test:1
docker push $DOCKER_USER/tag_test
echo 'FROM alpine:3.12\nENTRYPOINT ["echo", "this is version 2"]' > Dockerfile
docker build -t $DOCKER_USER/tag_test:2 .
@sunny-b
sunny-b / Dockerfile
Created January 30, 2023 03:40
multi-stage dockerfile
FROM golang:latest AS build
WORKDIR /src
COPY go.sum go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /bin/app .
FROM alpine
COPY --from=build /bin/app /bin/app
ENTRYPOINT ["/bin/app"]
@sunny-b
sunny-b / Dockerfile
Last active January 30, 2023 03:24
golang dockerfiles
FROM golang:latest
WORKDIR /src
COPY go.sum go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /bin/app .
ENTRYPOINT ["/bin/app"]
@sunny-b
sunny-b / swap_pairs.go
Created February 17, 2022 02:37
swap node pairs leetcode golang
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func swapPairs(head *ListNode) *ListNode {
// input: linked list
// output: linked list but every two nodes swapped
@sunny-b
sunny-b / recv.go
Created October 17, 2021 01:21
recv method
func (c *BufferedChannel) Recv() (interface{}, bool) {
c.lock.Lock()
defer c.lock.Unlock()
if c.buf.IsEmpty() && c.closed {
return nil, false
}
if !c.buf.IsEmpty() {
return c.buf.Dequeue(), true
@sunny-b
sunny-b / send.go
Created October 17, 2021 01:20
send method
func (c *BufferedChannel) Send(val interface{}) {
if c.closed {
panic("channel closed")
}
c.lock.Lock()
defer c.lock.Unlock()
if !c.buf.IsFull() {
c.buf.Enqueue(val)
@sunny-b
sunny-b / buffer.go
Created October 17, 2021 01:19
golang buffer
var (
// ErrBufferFull occurs when the buffer is full
ErrBufferFull = errors.New("buffer full")
)
type buffer struct {
q *list.List
maxLen int
}
@sunny-b
sunny-b / remove_tail.py
Last active January 5, 2021 15:24
remove tail
def remove_tail(self):
# if the list is already empty, bail out
if self.capacity == 0:
return None
removed = self.isolate(self.root.prev)
self.capacity -= 1
return removed
@staticmethod
@sunny-b
sunny-b / move_front.py
Last active January 5, 2021 15:17
move front method
def move_front(self, node):
# guard against empty nodes
if node is None:
return None
# Step 1: remove the node from its current position
node.next.prev = node.prev
node.prev.next = node.next
# Step 2: change the node so it points to the root and the old head node