Skip to content

Instantly share code, notes, and snippets.

View kamal-github's full-sized avatar
:octocat:
Focusing

Kamal Namdeo kamal-github

:octocat:
Focusing
View GitHub Profile
@kamal-github
kamal-github / generic_priority_queue.go
Created March 15, 2024 06:55
generic_priority_queue
package collections
type Item[T any] struct {
Item T
Priority int
Index int
}
type PriorityQueue[T any] []*Item[T]
@kamal-github
kamal-github / async.dart
Created November 13, 2022 15:09
Async await sample which explains the flow of execution.
import 'dart:async';
Future<void> printOrderMessage() async {
print('printOrderMessage: Awaiting user order... fetches and returns Future<void>');
var order = await fetchUserOrder();
print('This and following execute only after Future is complete');
print('Your order is: $order');
}
Future<String> fetchUserOrder() {

Understand error on materized view refresh concurrently.

ERROR:  cannot refresh materialized view "public.mvw_prod" concurrently
HINT:  Create a unique index with no WHERE clause on one or more columns of the materialized view.

Works

create materialized view mvw_prod as select productid, productname, supplierid from products join categories using(categoryid) where productid>5;
Docker file best practices
  1. order instruction by least to most frequent changing content
  2. Avoid COPY . (Copy only what is needed if possible)
  3. Don’t use latest tag, add a specific version
  4. Multi stage build -
    1. DRY
    2. small image size
    3. Build different image for test/run/lint from base buiilt image
@kamal-github
kamal-github / postgres kill runaway queries.md
Created March 17, 2021 17:42
postgres kill runaway queries
Check current acticity or running query

select pid, query from pg_stat_activity where state='active';

To Cancel

select pg_cancel_backend();

@kamal-github
kamal-github / Go - Remove first element from slice
Created January 22, 2021 12:38
Remove first element from slice
// https://play.golang.org/p/7oTksbq9ioW
package main
import (
"fmt"
)
func main() {
package main
import (
"fmt"
"log"
"net/http"
"net/http/pprof"
)
// HTTP request handler
func handler(w http.ResponseWriter, r *http.Request) {
@kamal-github
kamal-github / fan-out-in.go
Last active November 21, 2020 17:00
Fan out and Fan in pattern in Go
package main
import (
"fmt"
"runtime"
"sync"
)
func main() {
// can be a input stream such as CSV/Network/File.
@kamal-github
kamal-github / OrDoneChannel.go
Last active November 22, 2020 08:27
Or Done channel - Concurrency in Go Book
package main
import (
"fmt"
"time"
)
// Simpler version for Or
func OrVer2(ch ...chan struct{}) <-chan struct{} {
switch len(ch) {
@kamal-github
kamal-github / rabbitmq.go
Created September 17, 2020 16:54 — forked from ribice/caller.go
A robust rabbitmq client for Go
const (
// When reconnecting to the server after connection failure
reconnectDelay = 5 * time.Second
)
// Client holds necessery information for rabbitMQ
type Client struct {
pushQueue string
logger zerolog.Logger
connection *amqp.Connection