Skip to content

Instantly share code, notes, and snippets.

View Magnus167's full-sized avatar
🧘
thinking...

Palash Tyagi Magnus167

🧘
thinking...
View GitHub Profile
@Magnus167
Magnus167 / .gitconfig
Last active March 11, 2024 17:31
Print off pull requests associated with a branch (Github only)
[alias]
pr = "!f() { BRANCH=$(git branch --show-current); REPOURL=$(git config --get remote.origin.url); python ~/Code/work_HK/getpr.py $REPOURL $BRANCH; }; f"
@Magnus167
Magnus167 / get_pr_full.py
Last active March 26, 2024 09:28
Print list of PRs for a GitHub branch
import json
import urllib.request
import sys
import os
# get repo and branch from sys.argv
if len(sys.argv) < 3:
print("Usage: python getpr.py <repo> <branch>")
sys.exit(1)
@Magnus167
Magnus167 / pmerge.sh
Last active February 26, 2024 01:17
git pmerge - pull & merge. Use with Windows (powershell) or Unix-like alike
# Usage:
# git checkout featureX
# git pmerge main
# When merging branch `main` into `featureX`,
# one often has to pull from `main` to ensure
# merging into the correct head.
# Assume you're on branch featureX
# >> git pmerge main
# executes:
@Magnus167
Magnus167 / analyse_commit_info.py
Created February 6, 2024 17:31
Commit frequency plotter
# load commit_data.csv
from typing import List, Optional
import pandas as pd
df = pd.read_csv("commit_data.csv")
# filter where username is Palash Tyagi or Spalash
df = df[(df["username"] == "Palash Tyagi") | (df["username"] == "Spalash")]
@Magnus167
Magnus167 / 01_expl_monte_carlo_simulation.md
Last active November 22, 2023 16:43
What is a Monte Carlo simulation anyway?

In a nutshell, what is a Monte Carlo simulation anyway?

Monte Carlo simulations are typically used to get estimates of results, when the actual problem is too vast to be solved in entirety (or in a reasonable amount of time).

There are 3 examples, each closer to the real world version than the last. Example 1 is the best 😄

Example 1: Estimating the number of potholes in London

@Magnus167
Magnus167 / double_pend.py
Created August 10, 2023 14:13
Neat MPL script for a quick & dirty double pendulum calculation
# adapted from https://matplotlib.org/stable/gallery/animation/double_pendulum.html#sphx-glr-gallery-animation-double-pendulum-py
from numpy import sin, cos
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from collections import deque
G = 9.8 # acceleration due to gravity, in m/s^2
L1 = 1.0 # length of pendulum 1 in m
L2 = 1.0 # length of pendulum 2 in m
#include <stdio.h>
#include <string.h>
#define MAX 256
#define INT_BITS 32
void countingSort(int arr[], int n, int exp) {
int output[n]; // output array
int i, count[MAX] = {0};
@Magnus167
Magnus167 / dependencies.py
Created July 10, 2023 16:47
getting function level dependencies from a python package or a set of notebooks
"""
Scans Jupyter Notebooks for functions used from a given package.
The return
"""
from typing import List, Dict, Set, Tuple, Type, Callable
import ast
# import functools
import glob
import nbformat

NOTICE:

TLDR : Not my original work, I copied it over as I needed it to be in markdown formatting.

This is not my own content, and is merely curated here for accessibilty and sharing. The below article has been copied from https://www.joelsleppy.com/blog/gunicorn-application-preloading/, with all rights to intellectual property reserved by the authors/domain-owners.

Gunicorn Application Preloading

import copy
original_list = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
list_a = original_list
original_list[0][0] = "a"
assert list_a[0][0] == "a"
list_b = copy.deepcopy(original_list)
original_list[0][0] = "b"