Skip to content

Instantly share code, notes, and snippets.

View audacioustux's full-sized avatar
🐧

Tanjim Hossain audacioustux

🐧
View GitHub Profile

The Dining Philosophers Code

Generated with ChatGPT

This code implements a solution to the Dining Philosophers Problem, a classic synchronization problem in computer science. The problem describes a scenario where a group of philosophers sits around a circular table. Each philosopher alternates between thinking and eating, and they require two chopsticks (shared resources) to eat. The challenge is to prevent deadlock and ensure that all philosophers can eat eventually.

Modules Overview

1. Chopstick

The Chopstick module simulates a single chopstick. It keeps track of whether the chopstick is in use and handles requests from philosophers to either pick up or release the chopstick.

#!/bin/bash
EXT_DRIVE="/Volumes/Untitled/important"
MAIN_DRIVE="/Users/tanjimhossain/Pictures"
# Ensure fd is installed
if ! command -v fd &>/dev/null; then
echo "Error: 'fd' is not installed. Please install it before running this script."
exit 1
fi

/etc/systemd/system/ssh_watchdog.service
/usr/local/bin/ssh_watchdog.sh

x-postgres-environment: &postgres-environment
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
# POSTGRES_DB: ${POSTGRES_DB:-postgres}
POSTGRESQL_REPLICATION_USER: ${POSTGRESQL_REPLICATION_USER:-replicator}
POSTGRESQL_REPLICATION_PASSWORD: ${POSTGRESQL_REPLICATION_PASSWORD:-replicator}
POSTGRESQL_LOG_HOSTNAME: ${POSTGRESQL_LOG_HOSTNAME:-true}
x-postgres-healthcheck: &postgres-healthcheck
test: [ "CMD", "pg_isready", "-U", "postgres" ]
interval: 5s
#!/bin/bash
cd /tmp
wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
echo '{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "cwagent"
},
#!/bin/bash
# Function to create swap files
create_swap_files() {
local count=$1
local swap_directory=${2:-/var/}
local swap_file_prefix="swapfile"
for ((i=1; i<=count; i++)); do
swap_file="${swap_directory}/${swap_file_prefix}${i}"
git diff --word-diff
git config --global rerere.enabled true
git config --global rerere.autoUpdate true
git config --global branch.sort -committerdate
git config --global column.ui auto
git push --force-with-lease
@audacioustux
audacioustux / ca-issuer.yaml
Last active December 30, 2023 12:37
open Edx configs
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: self-signed
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
@audacioustux
audacioustux / main.rs
Last active December 15, 2023 19:57
ec billing - initial draft
use std::{any::Any, collections::HashMap, net::SocketAddr, ops::Range, sync::Arc, time::Duration};
use anyhow::{anyhow, bail, Error, Result};
use axum::{
// debug_handler,
extract::{FromRef, Path, State},
http::{header::HeaderMap, StatusCode},
routing::{get, post},
Json,
Router,
version: "3"
tasks:
default: task --list-all
# provision
prod:up: INFRA=prod bin/up.sh
dev:up: bin/up.sh
# access
argo:password: echo "Bearer $(kubectl get secret -n argo default.service-account-token -o=jsonpath='{.data.token}' | base64 --decode)"
argo:port-forward: kubectl port-forward -n argo svc/argo-server 2746