Skip to content

Instantly share code, notes, and snippets.

@piyush01123
piyush01123 / quickSelect.cpp
Last active February 17, 2023 19:02
QuickSelect implementation
#include <bits/stdc++.h>
using namespace std;
int randGen (int i) {srand(time(0)); return rand()%i;}
int partition(int A[], int lo, int hi)
{
int pivot = A[hi];
int i = lo-1;
for (int j=lo; j<=hi; j++)
@piyush01123
piyush01123 / quickSort.cpp
Last active February 17, 2023 19:01
QuickSort implementation
#include <bits/stdc++.h>
using namespace std;
int randGen (int i) {srand(time(0)); return rand()%i;}
int ctr = 0;
int partition(int A[], int lo, int hi)
{
int pivot = A[hi];
int i = lo-1;
@piyush01123
piyush01123 / autoWayBack.js
Created February 15, 2023 18:29
Auto WayBack - Load latest snapshot from Wayback Machine
// ==UserScript==
// @name Auto Wayback
// @namespace http://tampermonkey.net/
// @version 3.1.1
// @description Load latest snapshot from Wayback Machine
// @author Piyush Singh
// @match *://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant unsafeWindow
// ==/UserScript==
@piyush01123
piyush01123 / Real-time anomaly detection for a large industrial facility.md
Last active June 19, 2025 01:42
Real-time anomaly detection for a large industrial facility

Anomaly detection for a large industrial facility

About: This document contains summary of a real-time anomaly detection system developed by me (and team) for Anadarko's crude oil extraction facilities during my time at Quantiphi.

Requirements

  • Our client has facilities of 2 types. For both, we want to have models that can do anomaly detection in real time.
  • For type I we have some samples marked as anomalies, so we can either train a supervised ML model (with the challenge of an extreme bias dataset) or we can use the model trained for type II dataset but with some finetuning using the annotation. We go with the 2nd route.
  • For type II we do not have any marked samples and we have to train a model in unsupervised setting
  • We want high recall with decent precision since false negatives incur higher costs (replacing entire components) whereas false positives incur marginal costs (extra component checks)
@piyush01123
piyush01123 / generatePassword.js
Last active March 21, 2023 23:14
Generate and copy to clipboard strong password - Tampermonkey script
// ==UserScript==
// @name Generate Strong Password
// @namespace http://tampermonkey.net/
// @version 3.1.1
// @description Strong password generator of size 12
// @author Piyush Singh
// @match *://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant unsafeWindow
// @grant GM_setClipboard
@piyush01123
piyush01123 / cli_productivity.md
Last active December 2, 2022 11:15
Command Line Productivity Tools

Command Line Productivity Tools

In course of my everyday work, sometimes I need a tool which does not exist. So I build them myself and later release them. Here are 3 command line tools I have built that each serve some specific purpose:

Tool 1: Flask Image Gallery

Generates image gallery from your server. Very useful during ML experimentation. Link to repository.

@piyush01123
piyush01123 / track_visitors.py
Last active November 18, 2022 10:26
Simple flask app to track visitors. Can also be used to test if your proxy server or vpn is running properly.
from flask import Flask, request
from datetime import datetime
import json,os
app = Flask(__name__)
@app.route('/', methods=["GET","POST"])
def index():
if request.method=="POST":
ip_data = request.get_json()
print(ip_data)
@piyush01123
piyush01123 / fisr.cpp
Last active March 16, 2023 01:36
Fast Inverse Square Root - Quake III
float fisr(float n){
long x = 0x5f3759df - (*(long *)&n >> 1); //magic number = 1.5*2^23*(127-mu); mu represents log(1+x)=x+mu; mu=0.0450465
float y = *(float *)&x; // Solution from bit manipulation
y = 1.5F*y - 0.5F*n*y*y*y; // Newton improvement 1
y = 1.5F*y - 0.5F*n*y*y*y; // Newton improvement 2
return y;
}
@piyush01123
piyush01123 / viterbi.py
Last active March 16, 2023 01:36
Hidden Markov Models - Viterbi Algorithm
import numpy as np
def viterbi(mood_sequence, priors, transmission_probs, emission_probs):
n = len(mood_sequence)
weather_matrix = np.zeros((n, 2))
history = [(None,None)]
for i, mood in enumerate(mood_sequence):
if i==0:
weather_matrix[i] = priors['s']*emission_probs['s'+mood], priors['r']*emission_probs['r'+mood]
else:
@piyush01123
piyush01123 / tfidf.py
Last active March 31, 2021 03:32
TF-IDF implementation
from sklearn.feature_extraction.text import TfidfTransformer
import numpy as np
counts = [[3, 0, 1],
[2, 0, 0],
[3, 0, 0],
[4, 0, 0],
[3, 2, 0],
[3, 0, 2]]