Skip to content

Instantly share code, notes, and snippets.

View pallabpain's full-sized avatar
👨‍💻

Pallab Pain pallabpain

👨‍💻
View GitHub Profile
@pallabpain
pallabpain / bubblesort
Created October 20, 2014 18:21
Bubble sort program in Python
def swap(p,q):
return q,p
a=[]
x=int(input("Enter the number of elements you want to sort : "))
i=0
while (i < x):
y=int(input("Enter element " + str(i+1) + " : "))
a.append(y)
@pallabpain
pallabpain / page_replacement
Created October 20, 2014 18:23
Page Replacement simulation in Python
a = []
#Function to accept reference string and frame size.
def accept():
global a,n,m
n = input("\n Enter the size of reference string : ")
for i in range(n):
a.append(input(" Enter [%2d] : " % (i+1)))
m = input("\n Enter page frame size : ")
@pallabpain
pallabpain / cpu_sched
Created October 20, 2014 18:25
CPU Scheduling simulation in C
#include<stdio.h>
#include<stdlib.h>
typedef struct process{
char name[5];
int bt;
int at;
int prt;
int wt,ta;
int flag;
@pallabpain
pallabpain / bankers_algo
Created October 20, 2014 18:26
Banker's Algorithm in C
#include<stdio.h>
#include<stdlib.h>
void print(int x[][10],int n,int m){
int i,j;
for(i=0;i<n;i++){
printf("\n");
for(j=0;j<m;j++){
printf("%d\t",x[i][j]);
}
@pallabpain
pallabpain / mem_mgmt
Created October 20, 2014 18:28
Fixed Partition Memory Management simulation in C
#include<stdio.h>
#include<stdlib.h>
typedef struct process{
int psize;
int pflag;
}process;
typedef struct block{
int bsize;
@pallabpain
pallabpain / matrix_mul
Created February 6, 2015 13:07
THREAD MANAGEMENT USING PTHREAD LIBRARY
/*
THREAD MANAGEMENT USING PTHREAD LIBRARY
Implement matrix multiplication using multithreading. Application should
have pthread_create, pthread_join, pthread_exit. In the program, every
thread must return the value and must be collected in pthread_join in the
main function. Final sum of row-column multiplication must be done by main
thread (main function).
*/
@pallabpain
pallabpain / search.py
Created September 21, 2016 18:11
Searching in an unsorted binary tree
class Node(object):
def __init__(self, value, left, right):
self.value = value
self.left = left
self.right = right
def find(root, target):
if root is None:
return None
if root.value == target:
@pallabpain
pallabpain / directory_walk.py
Last active May 31, 2020 15:36
A simple Python script to perform a walk on a directory and store the directory tree as a list
import os
def generate_directory_tree(dir_path):
paths = []
for root, _, files in os.walk(dir_path):
paths.append(root)
paths.extend(os.path.join(root, _file) for _file in files)
return paths
@pallabpain
pallabpain / trie_traversal.py
Last active May 31, 2020 17:21
Re-building directory tree from a list of random paths using pygtrie
import pygtrie
# 0 denotes a directory and 1 denotes a file
path_entries = [
("./pcache/pcache.egg-info/dependency_links.txt", 1),
("./pcache/LICENSE", 1),
("./pcache/build/lib/pcache/__init__.py", 1),
("./pcache/pcache.egg-info/top_level.txt", 1),
("./pcache/pcache/pcache.py", 1),
("./pcache/pcache/__init__.py", 1),
@pallabpain
pallabpain / merkle_tree.py
Last active August 15, 2020 11:36
A simple Merkle Tree implementation (Courtesy: https://www.codementor.io/blog/merkle-trees-5h9arzd3n8)
from hashlib import sha256
class Node:
"""A Merkle tree node
Stores the computed hash and the parent of the node
Args:
hash: Hash of the (left + right) children