Skip to content

Instantly share code, notes, and snippets.

View thepushkarp's full-sized avatar
🐒
embracing chaos

Pushkar Patel thepushkarp

🐒
embracing chaos
View GitHub Profile
@thepushkarp
thepushkarp / delete_unnecessary_folders.py
Last active June 5, 2023 15:29
Deletes unnecessary folders that take huge space. Useful when moving directories.
import os
import shutil
def delete_folders(path):
for root, dirs, files in os.walk(path):
if 'node_modules' in dirs:
shutil.rmtree(os.path.join(root, 'node_modules'))
print(f"Deleted node_modules folder in {root}")
if '.next' in dirs:
@thepushkarp
thepushkarp / extract_gz.py
Created July 13, 2022 10:10
Extract gzipped files
import gzip
import os
root_folder = "mock-data"
for root, dirs, files in os.walk(root_folder):
# if file is a .csv.gzip, extract it
for file in files:
if file.endswith(".gz"):
file_path = os.path.join(root, file)
@thepushkarp
thepushkarp / numpy_encoder.py
Last active July 6, 2022 07:41
Store a numpy.ndarray or any nested-list composition as JSON
# Link: https://stackoverflow.com/a/47626762/10307491
class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a.shape)
json_dump = json.dumps({'a': a, 'aa': [2, (2, 3, 4), a], 'bb': [2]},
@thepushkarp
thepushkarp / .gitattributes
Created November 21, 2021 20:31
For maintaining consistent LF line endings in Windows and Unix Systems
# For maintaining consistent LF line endings in Windows and Unix Systems
* text=auto eol=lf
@thepushkarp
thepushkarp / jupyter_autotime.py
Created November 15, 2021 11:34
This snippet shows execution time for each cell in a Jupyter Notebook
try:
%load_ext autotime
except:
!pip install ipython-autotime
%load_ext autotime
# Reference: https://stackoverflow.com/a/66931419/10307491
@thepushkarp
thepushkarp / colabPreventDisconnect.js
Last active April 9, 2021 12:41
Prevent Colab from Disconnecting
// https://medium.com/@shivamrawat_756/how-to-prevent-google-colab-from-disconnecting-717b88a128c0
function ClickConnect() {
console.log("Working");
document.querySelector("colab-toolbar-button").click()
}
setInterval(ClickConnect, 60000)
@thepushkarp
thepushkarp / NoticeThePattern.c
Last active April 18, 2021 20:17
Tech Hunt 2021 Level 5 Hint
// Notice the pattern? 👀
#include <stdio.h>
int main() {
int k = 0, l = 0, m =5,n = 5, val = 1;
//
//
//
int a[m][n];
while (k < m && l < n) {
const { Builder, By, Key } = require("selenium-webdriver");
async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function breakCtf() {
console.log("Breaking CTF...");
const driver = await new Builder().forBrowser("chrome").build();
@thepushkarp
thepushkarp / localStorage.js
Created December 5, 2020 07:07
Retrieve all local storage items
// https://stackoverflow.com/a/17748203/10307491
function allStorage() {
var archive = {}, // Notice change here
keys = Object.keys(localStorage),
i = keys.length;
while ( i-- ) {
archive[ keys[i] ] = localStorage.getItem( keys[i] );
}