Skip to content

Instantly share code, notes, and snippets.

View meysampg's full-sized avatar
🖖
bit bit 0 bit

Meysam P. Ganji meysampg

🖖
bit bit 0 bit
View GitHub Profile
Aspect Cooperative Multitasking (General) Go's Concurrency Model (Goroutines and Channels)
Control Transfer Tasks yield control voluntarily. Goroutines yield control voluntarily or at specific points. They can also explicitly yield using runtime.Gosched().
Scheduling Responsibility Tasks are responsible for yielding control. Go's runtime scheduler is responsible for managing goroutine execution.
Task Cooperation Tasks must cooperate to ensure fairness. Goroutines cooperate by yielding control, but the scheduler can preemptively switch them as well.
Deadlock Risk Risk of deadlock if tasks don't yield. Similar risk of deadlock if goroutines don't yield or release resources.
Resource Sharing Resource sharing
Property Group Monoid Semigroup
Closure Closed under binary operation Closed under binary operation Closed under binary operation
Associativity Operation is associative Operation is associative Operation is associative
Identity Exists an identity element Exists an identity element Identity might not be present
Inverse Each element has an inverse Inverses might not be present Inverses might not be present

Examples:

  • Group:
@meysampg
meysampg / 99proxy_docker
Created August 6, 2023 10:40
Set proxy for docker repository by creating /etc/apt/apt.conf.d/99proxy with this content
Acquire::http::Proxy {
download.docker.com "http://localhost:8118";
};
Acquire::https::Proxy {
download.docker.com "http://localhost:8118";
};
@meysampg
meysampg / druid_segment_statistics.sql
Created February 3, 2023 08:29
Information of druid segments for a given data source
SELECT
"start",
"end",
version,
COUNT(*) AS num_segments,
AVG("num_rows") AS avg_num_rows,
MIN("num_rows") AS min_num_rows,
max("num_rows") AS max_num_rows,
SUM("num_rows") AS total_num_rows,
MIN("size") / 1024 / 1024 AS min_size,
from PIL import Image, ImageDraw, ImageFont
def get_text_dimensions(text_string, font):
# https://stackoverflow.com/a/46220683/9263761
ascent, descent = font.getmetrics()
text_width = font.getmask(text_string).getbbox()[2]
text_height = font.getmask(text_string).getbbox()[3] + descent
return (text_width, text_height)
# See: https://github.com/provectus/kafka-ui
version: '2'
services:
kafka-ui:
image: provectuslabs/kafka-ui
container_name: kafka-ui
restart: always
network_mode: host
environment:
- SERVER_PORT=6969
#!/bin/sh
# Check system
if [ ! -f /etc/lsb-release ];then
if ! grep -Eqi "ubuntu|debian" /etc/issue;then
echo "\033[1;31mOnly Ubuntu or Debian can run this shell.\033[0m"
exit 1
fi
fi
import scala.language.postfixOps
class VectorClock(private var name: String, private var countMap: Map[String, Int] = Map()) {
if (!countMap.isDefinedAt(name)) countMap = countMap ++ Map(name -> 1)
// increment
def ++ = VectorClock(
name,
countMap ++ Map(name -> (countMap.getOrElse(name, 0) + 1))
)
import scala.language.postfixOps
class LamportClock(private var count: Int = 0) {
// increment
def ++ = LamportClock(count + 1)
// merge
def +(other: LamportClock) = new LamportClock(math.max(count, other.count) + 1)
override def toString: String = s"LamportClock($count)"
@meysampg
meysampg / coingecko-to-kafka.py
Created July 20, 2022 09:39
Produce Coingecko Recorrds to Kafka
import requests
import datetime
from kafka import KafkaProducer
from json import dumps
from kafka.errors import KafkaError
def produce():
producer = KafkaProducer(bootstrap_servers=['localhost:9092'], value_serializer=lambda x: dumps(x).encode('utf-8'))
response = requests.get('https://api.coingecko.com/api/v3/exchange_rates').json()['rates']