Skip to content

Instantly share code, notes, and snippets.

View iamkhush's full-sized avatar

Ankush Chadda iamkhush

View GitHub Profile
@iamkhush
iamkhush / pg-client.py
Last active March 27, 2021 19:59
Python implementation for a PG Client
#! python3
from io import BytesIO
import struct
import socket
from enum import auto, Enum
from contextlib import closing
class PGEntities(Enum):
AuthenticationOk = auto()
@iamkhush
iamkhush / merge_sort.py
Created March 1, 2020 19:21
Implement Merge Sort
import math
def merge_sort(data, p: int, q: int):
# If something goes wrong
if q < p :
return data
# Base case
if q - p == 1:
if data[q] < data[p]:
return data[:p] + [data[q], data[p]] + data[q+1:]
@iamkhush
iamkhush / python-crawler-sitemap.py
Created November 14, 2017 07:46
Simple Crawler which outputs sitemap for the given website
"""Simple Crawler which outputs sitemap."""
import re
import sys
from urllib.parse import urlparse
import requests
class Crawler:
@iamkhush
iamkhush / zip.py
Created December 17, 2013 10:45
Read zip fie from form upload..
try:
# Get Compressed folder information
read_compressed_folder(request.FILES['compressed_folder'].temporary_file_path())
except Exception:
# When storing in memory
if not os.path.exists(os.path.join(tempfile.gettempdir(), 'temp_compressed_folder')):
os.makedirs(os.path.join(tempfile.gettempdir(), 'temp_compressed_folder'))
zip_file = zipfile.ZipFile(request.FILES['compressed_folder'])
zf = zipfile.ZipFile(os.path.join(tempfile.gettempdir(), 'zipfile_write.zip'), mode='w')
@iamkhush
iamkhush / find_and_destroy.py
Created September 6, 2013 04:05
This module " finds and destroys " errors in a json file by applying regex on error message, getting the column number and replacing the element on that column. Loop this thing and when no error comes save this into a new file
import json, re
f = open('random_json_file')
d = f.read()
import time
starttime = time.time()
while True:
try:
e = json.loads(d)