Skip to content

Instantly share code, notes, and snippets.

View pot-code's full-sized avatar
💻
Idle

Potpot pot-code

💻
Idle
View GitHub Profile
@pot-code
pot-code / bfs.go
Last active April 6, 2020 04:05
[BFS] breadth first search #algorithm
var directions = [4][2]int{{0, 1}, {0, -1}, {-1, 0}, {1, 0}}
func bfs(grid [][]int) {
var (
queue [][]int
m = len(grid)
n = len(grid[0])
)
for len(queue) > 0 {
@pot-code
pot-code / canvas_base.js
Last active April 6, 2020 04:05
[canvas] canvas collection #canvas
const $graph = document.getElementById("graph");
const pixelRatio = Math.ceil(window.devicePixelRatio);
const context = $graph.getContext("2d");
const width = $graph.offsetWidth;
const height = $graph.offsetHeight;
$graph.height = height * pixelRatio;
$graph.width = width * pixelRatio;
@pot-code
pot-code / main.go
Last active April 6, 2020 04:05
[zmq] zeromq snippets #MQ
func main() {
if len(os.Args) < 2 || os.Args[1] != "client" {
for i := 0; i < 4; i++ {
go worker()
}
broker()
} else {
client()
}
}
@pot-code
pot-code / find.go
Created April 9, 2020 13:14
[union find] #algorithm
type unionFind[]int
func (uf unionFind) find(i int) int {
if uf[i] != i {
uf[i] = uf.find(uf[i])
}
return uf[i]
}
func (uf unionFind) union(x, y int) {
@pot-code
pot-code / basic.go
Last active April 9, 2020 13:15
[goroutine] snippet
func worker(queue chan string, signal *sync.WaitGroup) {
for work := range queue {
}
signal.Done()
}
func main() {
count := runtime.NumCPU() - 1
queue := make(chan string, 10)
signal := new(sync.WaitGroup)
@pot-code
pot-code / heap.go
Created April 9, 2020 15:57
[data structure] heap and some stuff
type MinHeap []int
func (h MinHeap) Len() int { return len(h) }
func (h MinHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h MinHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *MinHeap) Push(x interface{}) {
*h = append(*h, x.(int))
}
func (h *MinHeap) Pop() interface{} {
old := *h
@pot-code
pot-code / kahn.go
Created April 14, 2020 04:27
[graph] graph algorithms #algorithm
func topoTraverse(n int, edge [][]int) {
graph := make(map[int][]int)
inTable := make([]int, n)
for _, edge := range edge {
graph[edge[0]] = append(graph[edge[0]], edge[1])
inTable[edge[1]]++
}
var queue []int
for i, v := range inTable {
@pot-code
pot-code / border.go
Last active April 14, 2020 04:28
[Array] array related snippets #array #algorithm
m := len(grid)
n := len(grid[0])
for i := 0; i < m; i++ {
dfsClosedIsland(grid, i, 0)
dfsClosedIsland(grid, i, n-1)
}
for i := 0; i < n; i++ {
dfsClosedIsland(grid, 0, i)
dfsClosedIsland(grid, m-1, i)
@pot-code
pot-code / initializer.go
Created March 25, 2021 08:49
[go-wire]
//+build wireinject
package api
import (
"github.com/google/wire"
"github.com/pot-code/go-producer/api/notification"
ut "github.com/pot-code/go-producer/api/notification/transport"
"github.com/pot-code/go-producer/pkg/db"
"github.com/pot-code/go-producer/pkg/uuid"
@pot-code
pot-code / nextjs
Last active April 13, 2021 07:24
[frontend starter] #frontend #starter
yarn create next-app
npx create-next-app