Skip to content

Instantly share code, notes, and snippets.

# Simplest server socket example
#
import socket
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(('127.0.0.1',8080))
s.listen(1)
conn,addr = s.accept()
@ghazanhaider
ghazanhaider / task_scheduler.c
Created April 26, 2023 21:51
Simple task scheduler
#include<stdio.h>
// task functions
void taskOne (void) { puts("Thread 1\n"); }
void taskTwo (void) { puts("Thread 2\n"); }
void taskThree (void) { puts("Thread 3\n"); }
// Function array of tasks
void *funcArray[] = {
&taskOne,
# How to increase the size of an LVM based disk
# Step1: Increase underlying disk size (qemu, vmware etc)
# Step2:
cfdisk /dev/nvme0n1p3
pvresize /dev/nvme0n1p3
lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv -r
@ghazanhaider
ghazanhaider / gist:15328e1c82389afdf705c40abe857c5d
Last active September 11, 2024 22:50
Setting up SAM-BA across architectures
# Microchip SAM-BA is only released for x86_64 architecture and will not run on arm64
# These steps allow it to be run under Ubuntu arm64 using qemu-user successfully
- Install Ubuntu (24.04.01)
- sudo apt install:
qemu-user
qemu-user-static
gcc-aarch64-linux-gnu
binutils-aarch64-linux-gnu
@ghazanhaider
ghazanhaider / driver.md
Last active September 5, 2025 14:57
Kernel driver model

Bus

  • Bus probes all devices
  • Bus registers all drivers usable for the bus
  • Bus then 'binds' driver to each device discovered:
    • When device_register is called for a device, it is inserted into the end of this list.
    • The bus object also contains a list of all drivers of that bus type.
    • These are the two events which trigger driver binding.
    • If a match is found, the device's driver field is set to the driver and the driver's probe callback is called.
    • This gives the driver a chance to verify that it really does support the hardware, and that it's in a working state.
  • When a driver is attached to a device, the device is inserted into the driver's list of devices.
@ghazanhaider
ghazanhaider / gist:3c1a09be62e9a9859263eb37fbc2c359
Created February 22, 2026 06:07
Installing Joplin Server on Amazon Linux 2023
sudo yum install docker
sudo systemctl start docke
sudo systemctl enable docker.service
sudo usermod -aG docker $USER
sudo curl -SL https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m) -o /usr/libexec/docker/cli-plugins/docker-compose
sudo chmod +x /usr/libexec/docker/cli-plugins/docker-compose
docker compose version
# Shows: "Docker Compose version v5.0.2"
cat <<EOF > docker-compose.yml
version: '3'