Skip to content

Instantly share code, notes, and snippets.

View mohit-s96's full-sized avatar
🏠
Working from home

Mohit Srivastava mohit-s96

🏠
Working from home
View GitHub Profile
@mohit-s96
mohit-s96 / torrent_router.json
Last active October 28, 2025 19:52
torrent_router.json
{
"tpb": "https://thpibay.xyz/search",
"bitsearch": "https://bitsearch.to/search"
}
@mohit-s96
mohit-s96 / useUsEffectWithChangeLogs.js
Created July 26, 2024 14:31
Track which dependency caused useEffect to run
/**
Sometimes with a lot of dependencies it becomes tedious to track what changed.
In such cases `useEffect` can be replaced with this during dev to monitor changes in state.
**/
const useUsEffectWithChangeLogs = (
callback,
dependency,
id = "Changes for anonymous effect"
) => {
const last = useRef(dependency);
@mohit-s96
mohit-s96 / spoof_location.js
Last active June 9, 2022 14:50
spoof location/GPS with the geolocation API
/*
* Run this in your console with the desired latitude and longitude values just before the page requests location / after the page loads..
*
* getCurrentPosition takes a callback function which is normally called when the user gives persmission to access location.
* Here we shim the function with our own implementation which resolves after sometime with the fake coordinate data.
*
* we're no-op'ing the watchPosition function because websites can use this to track changes in the location which can be used
* to detect the last position.
*/
navigator.geolocation.getCurrentPosition = (fn) => {
@mohit-s96
mohit-s96 / draw_binary_tree.cpp
Last active July 18, 2021 16:34
Draws a binary tree representation on the console / terminal
// Draws a binary tree representation on the console / terminal
#include <iostream>
#define LOG(x) std::cout << x;
class Tree
{
private:
struct _Tree
{
@mohit-s96
mohit-s96 / flatten_object_array.js
Last active June 11, 2021 08:43
Flatten array of objects in javascript
// Recursive flatten function (Doesn't flatten arrays)
function flatten(obj, target){
for(const key in obj){
if(obj.hasOwnProperty(key)){
if(!Array.isArray(key) && typeof(obj[key]) === "object" && obj[key] !== null){
flatten(obj[key], target);
}else{
target[key] = obj[key];
}
}