Skip to content

Instantly share code, notes, and snippets.

View geeksambhu's full-sized avatar
🎯
Focusing

Shiva Gaire geeksambhu

🎯
Focusing
View GitHub Profile
@geeksambhu
geeksambhu / download.py
Last active June 5, 2020 06:09
python request download file with progress bar
def download_file_from_url(url, folderpath):
r = requests.get(url, allow_redirects=True, headers=headers, stream=True)
if r.status_code == 200:
print("\nDownloading.. %s"% url.split('/')[-1])
with open('%s/%s'%(folderpath, url.split('/')[-1]), 'wb') as f:
total_length = r.headers.get('content-length')
if total_length is None: # no content length header
f.write(r.content)
else:
dl = 0
@geeksambhu
geeksambhu / tree_iterators.py
Created June 6, 2019 16:27 — forked from alexbowe/tree_iterators.py
Method to simplify many programming interview tree questions.
'''
Interview hack: Memorize preorder/inorder/postorder tree ITERATORS (no recursion) and their reverses.
It simplifies a disproportionate number of questions to simple for loops (see below).
I consider the implementations below the simplest way to memorize the iterative tree traversal algorithms,
because they are so similar to each other, and to their respective recursive versions.
Notes:
- We only visit a node after we have expanded its children (i.e. added them to the stack) in the desired order.
- `x is curr` does the expanded flagging for us, because we always expand the current node.
@geeksambhu
geeksambhu / json_to_csv.py
Last active January 2, 2019 08:47
JSON to CSV converter in python that maintains order of JSON Key value pairs too
import json, csv
from collections import OrderedDict
_json=json.loads(open('data.json', 'r').read(), object_pairs_hook=OrderedDict)
out=open('converted.csv', 'w')
writer = csv.writer(out)
writer.writerow(_json[0].keys())
for row in _json:
writer.writerow(row.values())
@geeksambhu
geeksambhu / # xapian - 2018-05-15_17-17-40.txt
Created July 3, 2018 04:35
xapian on macOS 10.13.4 - Homebrew build logs
Homebrew build logs for xapian on macOS 10.13.4
Build date: 2018-05-15 17:17:40
@geeksambhu
geeksambhu / example.yml
Created February 16, 2018 05:43
Publish or update HTML file(single or multiple) to zendesk Help Centre using v2 API.
# This is an example config for the mass publish script
# The outermost item is the section_id the articles belong in.
# The next level is the directory the articles are in, note that you can have
# multiple directories for one section_id, but not multiple entries of the same
# section_id. The final level is the names of the articles in the directory.
115001566429:
html:
- index.html:
- installation.html:
import re
class LogProcess:
DATE_REGEX = r"\d{4}\-\d{1,2}\-\d{1,2}"
LOG_LEVEL_REGEX = r"(?<=\[)\w+(?=\])"
def __init__(self, filename):
self.logfile = filename
self.data = {}
self.logvalues = {}
def quick_sort(given_list):
if len(given_list) < 1:
return given_list
else:
pivot_element = given_list[0] #here I am choosing the first element to be a pivot
left = quick_sort([element for element in given_list[1:] if element < pivot_element]) # moving smaller to left
right = quick_sort([element for element in given_list[1:] if element > pivot_element]) #moving greater to right
return left + [pivot_element] + right
@geeksambhu
geeksambhu / about.md
Created December 27, 2016 18:33 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer