Skip to content

Instantly share code, notes, and snippets.

View schedutron's full-sized avatar
🎯
Focusing

Saurabh Chaturvedi schedutron

🎯
Focusing
View GitHub Profile
@schedutron
schedutron / lock_tut.py
Last active August 13, 2017 03:15
A demo script for threading.Lock
from threading import Lock, Thread
lock = Lock()
g = 0
def add_one():
global g # Just used for demonstration. It’s bad to use the ‘global’ statement in general.
lock.acquire()
g += 1
lock.release()
@schedutron
schedutron / semaphore_tut.py
Last active August 13, 2017 03:14
A demo script for threading module's semaphores
import random, time
from threading import BoundedSemaphore, Thread
max_items = 5
container = BoundedSemaphore(max_items) # consider this as a container with a capacity of 5 items.
  # Defaults to 1 if nothing is passed.
def producer(nloops):
for i in range(nloops):
time.sleep(random.randrange(2, 5))
@schedutron
schedutron / rlock_tut.py
Last active August 13, 2017 03:11
A demo script for threading.RLock
import threading
num = 0
lock = Threading.Lock()
lock.acquire()
num += 1
lock.acquire() # This will block.
num += 2
lock.release()
@schedutron
schedutron / event_tut.py
Last active August 13, 2017 03:13
A demo script for threading.Event synchronization primitive
import random, time
from threading import Event, Thread
event = Event()
def waiter(event, nloops):
for i in range(nloops):
print(“%s. Waiting for the flag to be set.” % (i+1))
event.wait() # Blocks until the flag becomes true.
print(“Wait complete at:”, time.ctime())
@schedutron
schedutron / condition_tut.py
Last active August 13, 2017 03:13
A demo script for threading.Condition synchromization primitive.
import random, time
from threading import Condition, Thread
# This will be used to represent the availability of a produced item.
condition = Condition()
box = []
def producer(box, nitems):
for i in range(nitems):
time.sleep(random.randrange(2, 5)) # Sleeps for some time.
@schedutron
schedutron / barrier_tut.py
Last active August 13, 2017 03:12
A demo script for threading.Barrier synchronization primitive
from random import randrange
from threading import Barrier, Thread
from time import ctime, sleep
num = 4
b = Barrier(num) # 4 threads will need to pass this barrier to get released.
names = [“Harsh”, “Lokesh”, “George”, “Iqbal”]
def player():
name = names.pop()
@schedutron
schedutron / chat_serv.py
Created November 22, 2017 13:35
Chat Server Script
#!/usr/bin/env python3
"""Server for multithreaded (asynchronous) chat application."""
from socket import AF_INET, socket, SOCK_STREAM
from threading import Thread
def accept_incoming_connections():
"""Sets up handling for incoming clients."""
while True:
client, client_address = SERVER.accept()
@schedutron
schedutron / chat_clnt.py
Created November 22, 2017 17:55
GUI client script for my chat app
#!/usr/bin/env python3
"""Script for Tkinter GUI chat client."""
from socket import AF_INET, socket, SOCK_STREAM
from threading import Thread
import tkinter
def receive():
"""Handles receiving of messages."""
while True:
@schedutron
schedutron / gsoc_2018_schedutron_work_product.md
Last active November 9, 2018 03:39
GSoC 2018 Work Product | Saurabh Chaturvedi | Open Event Server, Frontend | FOSSASIA

GSoC 2018

Saurabh Chaturvedi | FOSSASIA

Overview:

Throughout the course of this summer, I worked on FOSSASIA's Open Event project for GSoC.

Open Event Server

Majority of my work was done on the server side, i.e, on Open Event Server. The Open Event API Server enables organizers to manage events ranging from concerts to conferences, meet-ups, lecture series and much more. It offers features for events with several tracks and venues. Features also include subtle options like access and discount codes, session tracks, microlocations and so on.

@schedutron
schedutron / DisjointSetMazeGenerator.md
Last active May 3, 2021 10:14
Python3 Maze Generator with Disjoint Set

Generate Mazes with Disjoint Sets!

This script generates mazes that satisfy the following properties:

  • There are no cycles in the maze
  • Maze is always solvable
  • Every cell is reachable from every other cell

The script also animates the maze-building process on the command-line (this was actually trickier than the maze generating algorithm itself)!

Usage