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 / data_class_usage.py
Created May 20, 2020 18:12
Using dataclass decorator only python>=3.7
from dataclasses import dataclass
from math import sqrt
@dataclass
class Position:
x: float = 0.0
y: float = 0.0
def distance_to(self, other):
@akarsh1995
akarsh1995 / pyproject.toml
Created June 28, 2020 07:39
'PosixPath' object has no attribute 'endswith'
[tool.poetry]
name = "artifacts"
version = "0.1.0"
description = ""
authors = ["Akarsh Jain <akarsh.1995.02@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.7"
beorouting = { path = "./beorouting-0.1.1.tar.gz" }
@akarsh1995
akarsh1995 / sample_insta_post.yml
Created July 18, 2020 15:43
insta post format
description: This is the sample code file
requirements:
- gmail
files:
foo.py: |
import os
bar.py: |
def helloworld():
print('helloworld')
@akarsh1995
akarsh1995 / find_substring.py
Created July 19, 2020 16:10
Find the substrings within a string
import re
sample_text = 'Python is a programming language that lets you work quickly ' \
'and integrate systems more effectively'
substring = 'integrate'
# search() function searches the string for a match, and returns a Match
# object if there is a match.
if re.search(substring, sample_text):
@akarsh1995
akarsh1995 / arrange_files.py
Created July 20, 2020 15:26
Group the directory's content using python
import shutil
from pathlib import Path
#General File Type Extentions
exts = {
"Applications": ['.exe'],
"Code": ['.py','.java','.c'],
"Music": ['.mp3','.ogg','.wav'],
}
@akarsh1995
akarsh1995 / extract_zip_file.py
Created July 21, 2020 17:28
# Script --> Extract zip file through python.
import zipfile
# create zipfile object by passing path of zip file
zip_file_object = zipfile.ZipFile(input("Enter zip file path"))
# to list items present inside the zip
contents = zip_file_object.namelist()
output_folder_path = input("Enter path where the zip is to be extracted")
@akarsh1995
akarsh1995 / csv_to_json.py
Created July 22, 2020 13:21
# Script --> Convert csv file to json with this clean and elegant script. Swipe Right # πŸ‘‰πŸ».
import csv
import json
from io import StringIO
default_csv_text = '''album,year,US_peak_chart_post
The White Stripes,1999,-
De Stijl,2000,-
White Blood Cells,2001,61'''
# convert csv to json function
@akarsh1995
akarsh1995 / extract_emails_to_csv.py
Created July 23, 2020 16:29
Script --> Lightweight script to extract emails from the text and dump as csv.
import re
from pathlib import Path
default_text = ("Please contact us at contact-helloworld@pysnippets.com for "
"further information."
" You can also give feedback at pysnippets@tp.com"
" another email: pysnippets@instagram.com")
@akarsh1995
akarsh1995 / app.py
Last active July 24, 2020 18:55
A Flask web app to obtain random premium images of the desired size.Very useful to web developers.
from pathlib import Path
import subprocess
from flask import Flask, request
import sys
current_dir = Path(__file__).parent
image_fetch_script_path = current_dir.joinpath('random_image_fetch.py')
save_dir = current_dir.joinpath('random_images')
@akarsh1995
akarsh1995 / create_thumbnails.py
Created July 25, 2020 15:18
Create thumbnail for all the images in a directory.
SIZE_THUMBS = (75, 75)
FROM_DIR = 'images'
TO_DIR = 'thumbs'
if __name__ == '__main__':
import os
if not os.path.exists(TO_DIR):
os.mkdir(TO_DIR)