Skip to content

Instantly share code, notes, and snippets.

View asadamatic's full-sized avatar
🎯
Focusing

ASAD HAMEED asadamatic

🎯
Focusing
  • Islamabad, Pakistan
  • 14:17 (UTC +05:00)
View GitHub Profile
@asadamatic
asadamatic / si_to_int.py
Last active February 16, 2020 07:51 — forked from gajeshbhat/strToInt.py
Convert k to Integer thousand Python.
def convert_si_to_number(x):
total_stars = 0
if 'k' in x:
if len(x) > 1:
total_stars = float(x.replace('k', '')) * 1000 # convert k to a thousand
elif 'M' in x:
if len(x) > 1:
total_stars = float(x.replace('M', '')) * 1000000 # convert M to a million
elif 'B' in x:
total_stars = float(x.replace('B', '')) * 1000000000 # convert B to a Billion
@asadamatic
asadamatic / downloadImage.py
Created March 5, 2020 05:05
Code to donwload images using requests library in python.
import requests
import time
imageUrl = 'https://images.unsplash.com/photo-1558981396-5fcf84bdf14d'
image = requests.get(imageUrl)
imageBytes = image.content
fileName = imageUrl.split('/')[3] + '.png' #getting photo name from the url
@asadamatic
asadamatic / downloadImages.py
Created March 5, 2020 05:09
Code to download multiple images using requests library in python.
import requests
import time
imageUrls = ['https://images.unsplash.com/photo-1558981396-5fcf84bdf14d',
'https://images.unsplash.com/photo-1583314059352-663691cfa23f',
'https://images.unsplash.com/photo-1583314238585-21664bba94ab',
'https://images.unsplash.com/photo-1583317094917-8aac805fed5a' ,
'https://images.unsplash.com/photo-1583307266943-e0055bb40037' ]
@asadamatic
asadamatic / sayHello.py
Created March 19, 2020 10:48
A python program that converts a text message to audio, saves it and plays it using default audio player.
from gtts import gTTS
import os
message = 'Hello Asad!'
output = gTTS(text = message, lang= 'en', slow = False)
output.save('sayHello.mp3')
os.system('start sayHello.mp3')
@asadamatic
asadamatic / textFileToAudio.py
Created March 19, 2020 11:01
A python program that reads text from a file and converts it to audio, saves it and plays it using default audio player.
from gtts import gTTS
import os
with open('message.txt') as file:
message = file.read()
output = gTTS(text = message, lang = 'hi', slow = False)
output.save('messageFromFile.mp3')
@asadamatic
asadamatic / readSinglePdfPage.py
Created March 19, 2020 11:18
Python program to extract data from a specific page of a pdf file. I have used PyPDF2 library for this module.
from PyPDF2 import PdfFileReader
with open('Sommerville-Software-Engineering-10ed.pdf', 'rb') as pdf:
pdfReader = PdfFileReader(pdf)
page = pdfReader.getPage(0)
pageText = page.extractText()
@asadamatic
asadamatic / readCompletePdf.py
Created March 19, 2020 11:49
Python program to extract all the text from a pdf file and saving it as a text file. I have used PyPDF2 library for this module.
from PyPDF2 import PdfFileReader
fileName = '' #Enter the name of pdf file here
with open(fileName + '.pdf', 'rb') as pdf:
pdfReader = PdfFileReader(pdf)
totalPages = pdfReader.numPages
@asadamatic
asadamatic / SpamFilter.py
Created March 31, 2020 12:27
This is a spam messages filter is based on naive Bayes Classifier.
spamMessage = {'million': 156, 'dollars': 29, 'adclick': 51, 'conferences': 2}
hamMessage = {'million': 98, 'dollars': 119, 'adclick': 1, 'conferences': 12}
spamWordCount = 95791
hamWordCount = 306438
probabilitySpam = 0.00
probabilityHam = 0.00
def likelihood(word):
@asadamatic
asadamatic / audioRecording.py
Created April 14, 2020 11:12
Python script to record audio using 'sounddevice' module.
import sounddevice as sound
from scipy.io.wavfile import write
duration = 5
sampleRate = 4100
sound.default.samplerate = sampleRate
sound.default.channels = 2
@asadamatic
asadamatic / fileSearch.py
Created April 16, 2020 12:24
Finding a file in current working directory using python.
import os
def searchFile(requiredFile):
if requiredFile in os.listdir():
return True
else: