Skip to content

Instantly share code, notes, and snippets.

@Ja7ad
Ja7ad / pactus_zmq_client.go
Last active January 22, 2025 07:19
Pactus blockchain zmq subscriber with decode message: https://pips.pactus.org/PIPs/pip-36
package main
import (
"bytes"
"context"
"encoding/binary"
"encoding/hex"
"fmt"
"github.com/go-zeromq/zmq4"
"github.com/pactus-project/pactus/crypto/hash"
@Ja7ad
Ja7ad / conn.go
Created December 9, 2024 06:13
Pactus client swarm
package pactus
import (
"context"
"fmt"
"sync"
"time"
pactus "github.com/pactus-project/pactus/www/grpc/gen/go"
"google.golang.org/grpc"
func Hash256(data []byte) []byte {
h := blake2b.Sum256(data)
return h[:]
}
func CalcHashWithXXHash64(data []byte) []byte {
xh := xxhash.New64()
_, _ = xh.Write(data)
@Ja7ad
Ja7ad / http.go
Created October 21, 2024 16:12
grpc gateway transport
package transport
import (
"context"
"github.com/Ja7ad/swaggerui"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"net/http"
"time"
@Ja7ad
Ja7ad / cbor_bench_test.go
Created September 29, 2024 08:19
Benchmark cbor
package bench
import (
"github.com/ugorji/go/codec"
"testing"
)
type Sample struct {
Name string
Age int
@Ja7ad
Ja7ad / map.go
Created August 10, 2024 07:06
PickByNestedKey
package utils
import (
"strconv"
"strings"
)
// PickByNestedKey find a value in nested map
// for nested key need set every key in one string and seperated with dot.
// For example "foo.bar.x.y.z" this is mean you need z key value.
package core
import (
"context"
"encoding/json"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/google/uuid"
@Ja7ad
Ja7ad / message.go
Created October 10, 2023 08:53
decorated jetstream.Msg for NakWithDynamicDelay
package nats
import (
"github.com/hashicorp/golang-lru/v2/expirable"
"github.com/nats-io/nats.go/jetstream"
"time"
)
type Msg interface {
jetstream.Msg
@Ja7ad
Ja7ad / main.go
Last active October 10, 2023 08:54
nats nak with dynamic delay (step by step)
package main
import (
"context"
"encoding/json"
"errors"
"github.com/brianvoe/gofakeit/v6"
"github.com/hashicorp/golang-lru/v2/expirable"
"github.com/lithammer/shortuuid/v3"
"github.com/nats-io/nats.go"
@Ja7ad
Ja7ad / lottery.go
Last active August 6, 2023 05:21
Lottery Game and Add to number
package main
import (
"encoding/json"
"fmt"
"log"
"math/rand"
"net/http"
"time"
)