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 / lru.cpp
Created November 27, 2023 22:32
LRU from Leetcode
class LRUCache {
struct node{
node* next;
node* pre;
int val;
int key;
node() : next(NULL), pre(NULL) {}
};
node* head;
node* tail;
@ajx42
ajx42 / gitrec.MD
Last active March 24, 2023 13:09
Project Organization Guidelines for Projects

Project Organisation Recommendations

Git is an incredible tool for managing your software development projects. Combine this with Github/Gitlab and you have a powerful environment to work on large scale projects as a team. Note that this gist is not a tutorial. Instead it is meant to serve as a guide to how to use what Github/Gitlab provide.

Along with Git and co I've also included general recommendations on how to make progress on your software engineering project.

Most of it is just "opinion" based on my software engineering experience. So you should feel free to experiment and figure out what works out the best for you.

At the end of this gist, you will find a handy list of useful Git commands.

@ajx42
ajx42 / functional_decorator.cpp
Created July 25, 2022 08:10
Functional Decorators (C++)
#include <iostream>
#include <sstream>
#include <string>
#include <functional>
struct Logger
{
Logger( const std::function<void(void)>& func, std::string name )
: func { func }, name { name } {}
@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
## 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 / 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")
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]++;
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
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
@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;