Caching ποΈ, π²Shell Scripts βοΈ, Concurrency π, Parallelism βΈ, Product Development π | Techletter #55
Caching
Caching the process of storing the data into temporary memory so that it can be easily retrieved for later use if it is required again.
The goal is to maximize hits (an item is in the cache when requested) & minimize misses (an item is not in the cache when requested)
Web browsers cache HTML files, JavaScript, and images in order to load websites more quickly, while DNS servers cache DNS records for faster lookups and CDN servers cache content to reduce latency.
Two caching techniques:
Least Frequently Used(LFU)
Least Recently Used(LRU)
LFU (Least Frequently Used) Caching
How to write shell scripts to automate tasks?
Recently I have started writing shell scripts because the number of repositories on which I work got increased, and taking pull from each is not a feasible solution. Why not automate the repetitive tasks? So here are my scripts to get recent changes, script to create build & push it to the specified branch.
Script to pull the latest changes
#!/bin/bash
stash_and_pull() {
local directory=$1
cd "$directory" || exit 1
echo "----"
echo "INSIDE DIRECTORY $directory"
currentTime=$(date +"%B%d%Y")
git stash save -m "$currentTime"
git switch master
git pull origin master
cd - || exit 1
echo "----"
}
stash_and_pull "DIRECTORY_NAME"
Script to create build & push to a specific repository
#!/bin/bash
build_and_push() {
local directory=$1;
cd "$directory" || exit 1
echo "----"
echo "INSIDE DIRECTORY $directory"
currentTime=$(date +%s)
git stash save -m "$currentTime"
git switch master
git pull origin master
git checkout -b "_build/$currentTime"
yarn build
git add .
git commit -m "Create build"
git push origin "_build/$currentTime"
}
build_and_push "DIRECTORY_NAME"
Print concurrently in GO
package main
import (
"fmt"
"time"
)
func count() {
for i := 0; i < 5; i++ {
fmt.Println(i)
time.Sleep(time.Millisecond * 1)
}
}
func main() {
go count()
time.Sleep(time.Millisecond * 2)
fmt.Println("Hello World")
time.Sleep(time.Millisecond * 5)
}
Multiple returns are possible in Go
package main
import (
"fmt"
)
func Names() (string, string) {
return "Foo", "Bar"
}
func main() {
p1, p2 := Names()
fmt.Println(p1, p2)
p3, _ := Names()
fmt.Println(p3)
}
What is the difference between concurrency & parallelism
Concurrency:
Multiple tasks in progress: Concurrency focuses on having multiple tasks happening seemingly at the same time. However, these tasks might not be executed simultaneously.
Single CPU illusion: Even with a single CPU, concurrency allows different tasks to make progress by rapidly switching execution between them. This creates the illusion of parallel processing.
Examples: Multitasking on a single-core phone, downloading multiple files while browsing the web.
Parallelism:
True simultaneous execution: Parallelism requires multiple processing units (CPUs or cores) to actually execute tasks simultaneously.
Increased speed: Each CPU handles a different task, significantly speeding up overall execution compared to concurrency on a single core.
Examples: Running multiple programs on a multi-core computer, rendering a video with multiple CPU cores.
Some of the challenges faced while developing a product
Value Risk: Will users buy your product?
Usability Risk: Can users understand how to use your product?
Feasibility Risk: Can you build the product?
Business Viability Risk: Does the product work for your whole company?
Articles