Skip to content

Instantly share code, notes, and snippets.

View leoantony72's full-sized avatar
:shipit:
dSByIGEgbmVyZA==

Leo Antony leoantony72

:shipit:
dSByIGEgbmVyZA==
View GitHub Profile
@leoantony72
leoantony72 / redis.go
Created October 19, 2022 15:14
Go Redis Pub/Sub
package config
import (
"context"
// "fmt"
"go/chat/utils"
"github.com/go-redis/redis/v9"
)
@leoantony72
leoantony72 / redis.go
Created October 19, 2022 15:13
Go redis config file
package config
import (
"go/chat/utils"
"github.com/go-redis/redis/v9"
)
var Conn redis.Client
func NPool() {
@leoantony72
leoantony72 / msg.go
Created October 19, 2022 15:12
Go websockets - send message gorilla websocket
var clients = make(map[string]*websocket.Conn)
func Send() {
for {
msg := <-broadcast
message := Message{}
if err := json.Unmarshal([]byte(msg.Payload), &message); err != nil {
panic(err)
}
JsonData, err := json.Marshal(message)
utils.CheckErr(err)
@leoantony72
leoantony72 / msg.go
Created October 19, 2022 15:11
Go webscoket - receive messages
type Message struct {
Id string
Message string `json:"msg"`
Sender string
Receiver string `json:"receiver,omitempty"`
Group bool `json:"group"`
GroupName string `json:"group_name,omitempty"`
}
func ReceiveMessage(conn *websocket.Conn) {
@leoantony72
leoantony72 / ws.go
Created October 19, 2022 15:07
Go websocket config file
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
func Wshandler(w http.ResponseWriter, r *http.Request, c *gin.Context) {
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
fmt.Printf("Failed to set websocket upgrade: %+v", err)
return
@leoantony72
leoantony72 / push.git
Created October 19, 2022 15:05
Push all commits,branches into new repo
git remote remove origin
git remote add origin new-repo-url
git push --all
git push --tags
@leoantony72
leoantony72 / bloom filter.md
Created June 23, 2022 05:38
Introduction to Bloom filter with real life use cases🐱‍💻

Suppose you are creating an account on Twitch or any other website, you will immediately think of a cool username like noobmaster69🙃 and when you submit the form you immediately get User Name Already Taken😡 you will try out other cool names or even your own name but you get the same Err Message, Quite Frustrating right😂.

But have ever thought about how this works behind the scenes?🤔

Social media platforms like twitch/youtube have millions of users but still, these companies quickly check the availability of usernames by searching millions of usernames. hearing searching makes you think about linear & binary search Are they using these that we learned in high school? Nop Something far better

Suppose I have an SQL database with 10 million users, with a Unique key on the usernames column. To check if the username is taken or not I will Write the following Query

SELECT username FROM users WHERE username = $1;