Skip to content

Instantly share code, notes, and snippets.

View ajx42's full-sized avatar
⚔️
sword emoji

Aditya Jain ajx42

⚔️
sword emoji
View GitHub Profile
@ajx42
ajx42 / allSyntax.cpp
Last active August 22, 2018 06:35
CS353 : Operating Systems Notes
/*
--- Representational Code Only: Not to compile
--- Aditya Jain ------------------------------
--- IIT INDORE -------------------------------
*/
// libraries
#include <semaphore.h>
/*
Adjacency Matrix Representation
*/
// undirected dense graph (with lesser nodes eg N = 1e3)
int adj_matrix[N][N];
int main(){
int num_nodes, num_edges;
cin >> num_nodes >> num_edges;
for(int i = 0, u, v; i < num_edges; ++i){
/*
Adjacency List in Vector
*/
vector <vector <int> > adj_list;
int main(){
int num_nodes, num_edges;
cin >> num_nodes >> num_edges;
adj_list.resize(num_nodes+1);
@ajx42
ajx42 / dfs.cpp
Last active July 14, 2024 15:04
bool vis[N]; // mark nodes which we have already visited
vector <vector <int> > adj; // adjacency list vectors
void dfs(int node){
if(vis[node]) // if already visited, return
return;
vis[node] = 1; // mark this node as visited
// do something
// example
cout << "Reached node: " << node << endl;
vector <vector <int> > adj; // adjacency list vectors
void dfs(int i, int par){
// set parent of i as the value passed in par
parent[i] = par;
if(par == -1) // means i is root
level[i] = 0;
else // otherwise
level[i] = level[parent[i]]+1
vector < vector <int> > adj;
int attending[N];
void dfs(int i, int par){
int sm = 0;
for(auto j: adj[i]){
if(j == par)
continue;
dfs(j, i); // call dfs on child node to compute its answer
sm += attending[j]; // add to the sum
cin >> x >> u; // input id for newly added node and its to-be manager
// lets assume we have the parent array created for us already
// lets add parent for newly added node x
parent[x] = u;
// add 1 to all nodes on path towards root
int curr = x;
while(curr != -1){
attending[curr]++;
@ajx42
ajx42 / pyro4-examples.py
Created September 17, 2018 05:35
PYRO4 Self Help
# START NAME SERVER AS:
$ pyro4-ns --host 172.22.134.7 --port 9090
# SERVER CODE
import Pyro4
@Pyro4.expose
class RemoteClass:
def __init__(self, x):
print("initialising remote object")
## This keeps adding 90 to the idd value in Server
## Never name the method (for setter and value) same as the attr name, will result in recursive calls (seg fault)
# SERVER
import Pyro4
@Pyro4.expose
class RemoteClass:
def __init__(self, x):
print("initialising remote object")
@ajx42
ajx42 / decorator.cpp
Last active July 25, 2022 04:51
Decorator Design Pattern
#include <iostream>
#include <sstream>
#include <string>
struct Shape
{
virtual std::string str() const = 0;
};
struct Circle : Shape