Programming Notes ✍️ – Telegram
Programming Notes ✍️
12 subscribers
65 photos
1 file
22 links
Download Telegram
🔥1
Clear dependencies
Clear syntax
Clear semantics
Composition over inheritance
Simplicity provided by the programming model (garbage collection, concurrency)
Easy tooling (the go tool, gofmt, godoc, gofix)
🔥1
Binary search using type casting an interface to []int

var numbers = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28}

func binarySearch(in interface{}, target int) int {
var num = in.([]int)
left, right := 0, len(num)-1
for left <= right {
mid := left + (right-left)/2
guess := num[mid]
if target == guess {
return mid
}
if target > guess {
left = mid + 1 // the guess was too high
}
if target < guess {
right = mid - 1 // the guess was too low
}
}
return -1
}

func main() {
fmt.Println(binarySearch(numbers, 20))
}
🔥1
running simple search & binary search in diffrenet gorutines and signaling using channels :

var TIMEOUT = 2 * time.Second

var numbers = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28}

func simpleSearch(input []int, target int) int {
for i := 0; i < len(input); i++ {
if input[i] == target {
return i
}
}
return 0
}

func binarySearch(in interface{}, target int) int {
var num = in.([]int)
left, right := 0, len(num)-1
for left <= right {
mid := left + (right-left)/2
guess := num[mid]
if target == guess {
return mid
}
if target > guess {
left = mid + 1 // the guess was too high
}
if target < guess {
right = mid - 1 // the guess was too low
}
}
return -1
}

func run(signal chan bool) {
var fun1 chan bool
fun1 = make(chan bool)

go func() {
timeBinary := time.Now()
fmt.Println(binarySearch(numbers, 20))
fmt.Println(time.Since(timeBinary))
fun1 <- true

}()

var fun2 chan bool
fun2 = make(chan bool)
go func() {
timeSimple := time.Now()
fmt.Println(simpleSearch(numbers, 20))
fmt.Println(time.Since(timeSimple))
time.Sleep(10 * time.Second)
fun2 <- true
}()

if <-fun1 && <-fun2 {
signal <- true
}
}

func main() {
sig := make(chan bool)
go run(sig)

fmt.Println("Welcome to the playground!")

select {
case <-sig:
fmt.Println("Runner Finished!!!")
case <-time.After(TIMEOUT):
fmt.Println("Timed out")
}
}


this proccess waits until the sig chan recive true or the time out get triggerd.
🔥1
🔥2
selection sort implementation


func selection(arr []int) []int {
length := len(arr)

for i := 0; i < length; i++ {
for j := i + 1; j < length; j++ {
if arr[i] > arr[j] {
arr[i], arr[j] = arr[j], arr[i]
}
}
}
return arr
}

func main() {
fmt.Println("Welcome to the Playground!")
numbers := nums
numbers = selection(numbers)
fmt.Println(numbers)
}
🔥1
وقتی بالا اوردن یه پروداکت انقدر پیچیدگی داره که حتی توی کتابم ازش صحبتی نمیشه :
API Gateway
SSL Termination proxy

For all incoming HTTPS connections, the load balancer service ends the SSL connection and establishes a plain text HTTP communication with the back-end server. CPU-intensive SSL handshakes and encryption or decryption tasks are shifted away from the back-end servers, allowing them to use all their CPU cycles for processing application traffic.
Linear Data Structures:

Array: A collection of elements of the same type stored in contiguous memory locations.

Linked List: A collection of elements linked together by pointers, allowing for dynamic insertion and deletion.

Queue: A First-In-First-Out (FIFO) structure where elements are added at the end and removed from the beginning.

Stack: A Last-In-First-Out (LIFO) structure where elements are added and removed from the top.

Non-Linear Data Structures:

Tree: A hierarchical structure where each node can have multiple child nodes.

Graph: A collection of nodes connected by edges, representing relationships between data elements.

Hash Table: A data structure that uses a hash function to map keys to values, allowing for fast lookup and insertion.


Applications of Data Structures
Data structures are widely used in various applications, including:

Database Management Systems: To store and manage large amounts of structured data.
Operating Systems: To manage memory, processes, and files.
Compiler Design: To represent source code and intermediate code.
Artificial Intelligence: To represent knowledge and perform reasoning.
Graphics and Multimedia: To store and process images, videos, and audio data.