Skip to content

Instantly share code, notes, and snippets.

View mihirs16's full-sized avatar
🔧
Tinkering

Mihir Singh mihirs16

🔧
Tinkering
View GitHub Profile
@mihirs16
mihirs16 / Ants.md
Last active May 21, 2023 21:18
This is toy problem for practicing fundamentals of a programming language along with concurrency and parallelism. Inspired from a coursework by https://www.eecs.qmul.ac.uk/~pbo/

Task: You will implement an app that uses threads and concurrent computation. Your task to simulate a social network. The main program should spawn num_ants number of threads, and each of these threads model an Ant (user) in the social network. The Ants should then (at random intervals) choose one of the other Ants (at random) and send a random message to that Ant.

  • Your project should define an appropriate data type Ant, which should include their username, and a Message type to keep track of messages between ants.
  • Your project should also contain a main thread which creates num_ants "ants" (num_ants values of type Ant), and spawns num_ants threads, one for each of these ants.
  • Each user thread should behave as follows: at random time intervals, the thread should select one of the other ants at random, and send a random message to that ant.
  • Your system should simulate num_messages messages, and then terminate and output the final count of how many messages each user received.
@mihirs16
mihirs16 / init-remote.sh
Last active September 14, 2022 15:41
Initializes a bare repository with a server-side post-receive hook.
# to initialize a remote repository
# ./init-remote.sh repo-name
#!/usr/bin/env/ bash
# check for filename argument
if [ -z $1 ]
then
echo "! please specify repo-name !"
exit 1
fi
@mihirs16
mihirs16 / post-receive.sh
Last active September 14, 2022 15:38
Server-side post-receive hook for git repositories.
# use this hook by creating a /.ci-cd/ directory at the root of your repo
# the default script to be called is ./ci-cd/post-receive.sh
# don't forget to make this hook executable (chmod +x)
#!/usr/bin/env bash
# begin deployment of new commit
echo "======= deploying ======="
# checkout main at new commit
git --work-tree=/home/git/<repo-name>.git/main/ --git-dir=/home/git/<repo-name>.git/ checkout -f main
@mihirs16
mihirs16 / install-docker.sh
Created September 8, 2022 14:55
Installing Docker on Ubuntu 20.04 (probably similar process with a different repository for newer versions).
#!/usr/bin/env bash
# update list of packages
apt update
# https prerequisites for apt
apt install apt-transport-https ca-certificates curl software-properties-common
# add GPG key for official docker repository
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@mihirs16
mihirs16 / generateRandomID.js
Last active February 1, 2022 00:53
Generates a random ID for MongoDB mock-primary key.
function generateAssignmentID() {
var id_elem = [];
var dateObj = new Date();
function convertToString(id_elem) {
return id_elem.toLocaleString('en-US', {
minimumIntegerDigits: 2,
useGrouping: false
});
}
@mihirs16
mihirs16 / utils.py
Created September 10, 2020 04:52
Utility functions for debug messages and errors
from printy import printy, inputy
import sys
# Mode Variables---------------------------
DEBUG_MODE = True
APP_PREFIX = 'api'
#------------------------------------------
# class for handling CLI messages
class _message:
@mihirs16
mihirs16 / convertStringToList.py
Last active July 4, 2020 03:37
To convert a .csv stored string representing a list to a python list
def func(raw_tags):
tags_clean = raw_tags[1:-1].split(", ")
return tags_clean
df['tags'] = df['tags'].apply(lambda x: func(x))
print(type(df.tags[0]))
df.head()