Skip to content

Instantly share code, notes, and snippets.

@ja7ad
ja7ad / main.go
Created March 15, 2021 05:40
Bridge Design Pattern Golang
package main
import "fmt"
type IDrawShape interface {
drawshape(x[5] float32, y[5] float32)
}
type DrawShape struct {}
@ja7ad
ja7ad / GoStrategy.md
Last active April 7, 2021 07:07
Go Project Management Strategy

Project Creator

create project and management with go modules

Intitial your project

  1. go to GOPATH in local cd $GOPATH
  2. if not having src,bin,pkg folder , create they mkdir -p {src,bin,pkg}
  3. go to src folder cd src
  4. create repository your project in github
  5. create folder mkdir -p github.com/username
    • change username to your username
@ja7ad
ja7ad / SampleGroupBy_test.go
Last active September 26, 2021 07:17
Golang Group by slice struct
/*
* MIT License
* Copyright (c) 2021 javad.
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
@ja7ad
ja7ad / proto.md
Last active February 28, 2022 12:07
Protocol Buffers Principles

Protocol Buffers Structures

syntax = "proto3";
option go_package = "github.com/Ja7ad/bookstore";

service Greeter {
  rpc GetBook(GetBookRequest) returns (Book) {}
  rpc AddBook(AddBookRequest) returns (Book) {}
  rpc AddManyBook(AddManyBookRequest) returns (google.protobuf.Empty) {}
  rpc UpdateBook(UpdateBookRequest) returns (Book) {}
@ja7ad
ja7ad / normalize.go
Last active July 20, 2022 06:26
normalize number with any type
package main
import (
"fmt"
"github.com/nyaruka/phonenumbers"
"strings"
"unicode"
)
var numberList = []string{
@ja7ad
ja7ad / main.go
Last active August 2, 2022 06:09
nats embbeded server
package main
import (
"fmt"
"time"
"github.com/nats-io/nats-server/v2/server"
"github.com/nats-io/nats.go"
)
@ja7ad
ja7ad / README.md
Last active September 7, 2022 03:59
mongodb with builder pattern

MongoDB Constructor with Builder Pattern

You can create new object of mongodb client and database

Example

package main

import "log"

Keybase proof

I hereby claim:

  • I am ja7ad on github.
  • I am ja7ad (https://keybase.io/ja7ad) on keybase.
  • I have a public key ASAuJdzUEQ_92uwvICZ6YYfO4naBwTuVlf8Np4Ni3kdsSwo

To claim this, I am signing this object:

openapi: 3.0.1
info:
title: test.proto
version: version not set
servers:
- url: /
tags:
- name: Foo
paths:
/list:
@ja7ad
ja7ad / clear_test.go
Last active April 30, 2023 05:50
benchmark clear feature in go1.21
package main
import (
"testing"
"time"
)
func BenchmarkClearMapWithDelete(b *testing.B) {
b.ReportAllocs()
test := createMap(100000)