Skip to content

Instantly share code, notes, and snippets.

View Parv3sh's full-sized avatar
💭
Ancora imparo

Parvesh Kumar Parv3sh

💭
Ancora imparo
View GitHub Profile
# Reading input function with validation
def read_int_input(prompt):
try:
target = int(input(prompt))
except ValueError:
print("not an int! Please try again")
return read_int_input(prompt)
# Since it's a recursive function and assuming the sanity of the user, it's assumed that the wrong input won't be
# passed more than thousand times. Since the recursive functions have some limits and the above, although correct,
# will throw a runtime error of max space reached or something similar.
from itertools import chain, starmap
def flatten_json_iterative_solution(dictionary):
"""Flatten a nested json file"""
def unpack(parent_key, parent_value):
"""Unpack one level of nesting in json file"""
# Unpack one level only!!!
if isinstance(parent_value, dict):
@Parv3sh
Parv3sh / gist:64799b3bcb1ece7136d597cd43a622f6
Created September 24, 2019 23:02 — forked from rafaan/gist:4ddc91ae47ea46a46c0b
Convert Nested JSON to Pandas DataFrame and Flatten List in a Column
import json
from pandas.io.json import json_normalize
import pandas as pd
with open('C:\filename.json') as f:
data = json.load(f)
df = pd.DataFrame(data)
normalized_df = json_normalize(df['nested_json_object'])
@Parv3sh
Parv3sh / extract.py
Created October 7, 2019 00:34
Recursively extract the nested zips in their respective directories
import logging
from pathlib import Path
from shutil import unpack_archive
import os
import sys
zip_files = Path(f"{sys.argv[1]}").rglob("*.zip")
while True:
try:
path = next(zip_files)
@Parv3sh
Parv3sh / iterm2-solarized.md
Created October 26, 2019 08:34 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@Parv3sh
Parv3sh / install_pyenv.sh
Created December 22, 2020 05:29 — forked from hemna/install_pyenv.sh
install pyenv and then install python 3.6.3 in that pyenv
# !/bin/bash
# Step 1. Install pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
source ~/.bashrc
#!/usr/bin/env python3
import ast
import os
from collections import defaultdict
from typing import List, Dict, Set, Tuple
import sys
class FunctionVisitor(ast.NodeVisitor):
def __init__(self, file_path: str):
self.file_path = file_path