Skip to content

Instantly share code, notes, and snippets.

View akarsh1995's full-sized avatar
🌐
Finding a startup

Akarsh akarsh1995

🌐
Finding a startup
View GitHub Profile
@akarsh1995
akarsh1995 / stopwatch.py
Created July 26, 2020 15:43
A stopwatch to keep the track of your activity right in the terminal/cmd.
import time
print('Press ENTER to begin, Press Ctrl + C to stop')
while True:
try:
input()
start_time = time.time()
print('Started')
while True:
print(
@akarsh1995
akarsh1995 / requirements.txt
Created July 27, 2020 14:58
Keep your loved ❣️ ones happy πŸ€ͺ using python.
selenium==3.12.0
schedule~=0.6.0
@akarsh1995
akarsh1995 / troll_trump.py
Created July 28, 2020 14:50
This script is only meant for Trump trollers 🀣.
import http.client
def send_request(host, path, headers):
conn = http.client.HTTPSConnection(host)
try:
conn.request("GET", path, headers=headers)
with conn.getresponse() as response:
return response.read()
finally:
conn.close()
@akarsh1995
akarsh1995 / project_stats.py
Last active July 29, 2020 15:22
All Devs...!!🐍 Wanna know your project stats better. Have insights using this simple py script.
import sys
from collections import Counter
from pathlib import Path
def count_lines(file: Path):
with file.open('r') as f:
i = 0
for i, l in enumerate(f):
pass
return i
@akarsh1995
akarsh1995 / hello.py
Created July 30, 2020 15:47
Writing api in just 4 lines of python code!!! wait what ?? 😨 Yes even shorter than flask !
import hug
@hug.get()
def hello():
return 'Hello!'
@akarsh1995
akarsh1995 / combine_pdfs.py
Created July 31, 2020 14:34
Pythonically merge pdfs in the blink of an eye πŸ‘ !
import PyPDF2
# Get all the PDF filenames.
def combine(pdfs):
pdfFiles = pdfs
pdfWriter = PyPDF2.PdfFileWriter()
# Loop through all the PDF files.
@akarsh1995
akarsh1995 / timeit_decor.py
Created August 1, 2020 17:40
Timeit ⏳ decorator to measure the execution speed of the python function. Use anywhere you like...🐍
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw:
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((te - ts) * 1000)
@akarsh1995
akarsh1995 / requirements.txt
Last active August 2, 2020 18:10
Using python to hit concurrent "GET" requests in almost no time.
aiohttp
requests
@akarsh1995
akarsh1995 / my_date_my_rules.py
Last active August 4, 2020 15:57
Ever got confused with the dates in different timezones. Experess dates in natural language and get the curated output.
import dateparser
if __name__ == '__main__':
import sys
human_readable_date = sys.argv[-1]
fmt = '%d, %b %Y, %I:%M %p'
print(dateparser.parse(human_readable_date).strftime(fmt))
@akarsh1995
akarsh1995 / send_email_gmail.py
Created August 5, 2020 16:23
To send an email programmatically from python.
import smtplib
import ssl
print(
"In case if you do not have app password"
"Follow this guide to get the app password from gmail..."
"https://www.lifewire.com/"
"get-a-password-to-access-gmail-by-pop-imap-2-1171882\n"
)