Skip to content

Instantly share code, notes, and snippets.

View kehiy's full-sized avatar
🏓
pong!

Kay kehiy

🏓
pong!
View GitHub Profile
@kehiy
kehiy / collatz.py
Last active April 16, 2024 15:41
Collatz conjecture or 3n+1 problem in python
import random
def is_odd(num: int):
if (num % 2) == 0:
return False
return True
def collatz(num: int):
@kehiy
kehiy / factorial.c
Last active April 3, 2024 10:10
factorial calculation
#include <stdio.h>
int factorial(int n) {
if (n == 0) {
return 1;
}
return n * factorial(n -1);
}
int main()
@kehiy
kehiy / quic_server.go
Created June 25, 2023 17:50
QUIC protocol simple server
package main
import (
"context"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"encoding/pem"
"fmt"
@kehiy
kehiy / performance.md
Last active June 24, 2023 21:59
Golang performance tips.

golang performance tips!

resources:

1. range instead of i

In Go, using range is typically faster and more efficient than indexing in a for loop.

When you use range in a for loop, the compiler generates code that efficiently iterates over the underlying data structure. In contrast, when you use indexing to access elements in a slice or array, the compiler generates additional instructions to calculate the offset of each element based on its index.

@kehiy
kehiy / client.go
Created June 21, 2023 18:24
UDP broadcast server and client
package main
import (
"bufio"
"fmt"
"net"
"os"
)
func main() {
@kehiy
kehiy / large_file_stream.go
Created June 21, 2023 10:33
Stream large files over a TCP connection.
package main
import (
"bytes"
"crypto/rand"
"encoding/binary"
"fmt"
"io"
"log"
"net"
@kehiy
kehiy / udp_client.go
Created June 20, 2023 08:59
udp client in golang
package main
import "net"
func main() {
Conn, _ := net.DialUDP("udp", nil, &net.UDPAddr{IP:[]byte{127,0,0,1},Port:3000,Zone:""})
defer Conn.Close()
Conn.Write([]byte("hello, gofarsi!"))
}
@kehiy
kehiy / socket_server.go
Last active June 20, 2023 09:00
web socket server in golang
package main
import (
"fmt"
"io"
"net/http"
"golang.org/x/net/websocket"
)
@kehiy
kehiy / udp_server.go
Last active June 20, 2023 08:58
simple UDP server in golang
package main
import (
"fmt"
"net"
)
func main() {
conn, err := net.ListenUDP("udp", &net.UDPAddr{
@kehiy
kehiy / tcp_server.go
Last active June 25, 2023 17:48
Custom TCP Server In Golang
package main
import (
"fmt"
"log"
"net"
)
type Message struct {
from string