Posts

What are Caught and Uncaught Exceptions in JavaScript?

In JavaScript, there are two types of exceptions: Caught exceptions: These are exceptions that are handled by a try/catch block. For example: try { // Code that may cause an exception throw new Error("Something went wrong!"); } catch (err) { // This will catch the exception and handle it console.log(err.message); // Prints "Something went wrong!" } Here the exception is caught and handled. Uncaught exceptions: These are exceptions that are thrown but not caught by a try/catch block. For example: throw new Error("Something went wrong!"); Here the exception is thrown but not caught, so it bubbles up and causes the JS execution to stop. These can crash your program if unhandled. It's good practice to use try/catch blocks to catch exceptions you expect, and have a general catch block at a high level to catch any uncaught exceptions and handle them gracefully. For example: try { // Code that may cause exceptions } catch (err)

Working with OS module in Python

import os def soldier(a,b,c): os.chdir(a) i = 1 items = os.listdir(a) for item in items: if item.endswith(b): os.rename(item, item.capitalize()) if item.endswith(c): os.rename(item, f"{i}.{c}") i += 1 fpath = r"D:\abdur codes\space\thisisit\fffffffffffffffff" filename = ".py" format = ".png" soldier(fpath, filename, format) ###################################################################### import os def soldier(fpath, filename, format): os.chdir(fpath) i = 1 files = os.listdir(fpath) with open(filename) as f: # this file contains files names which we will not tamper with filelist = f.read().split("\n") for file in files: if file not in filelist: os.rename(file, file.capitalize()) # if os.splitext(fpath)[1]==format: if os.path.splitext(fil

Command Line Utility of a Faulty Calculator

import argparse import sys def calc(args): if args.o == "+": if (args.a == 56 and args.b == 9) or (args.a == 9 and args.b == 56): return 77.0 else: return args.a + args.b elif args.o == "-": return args.a - args.b elif args.o == "*": if (args.a == 45 and args.b == 3) or (args.a == 3 and args.b == 45): return 555.0 else: return args.a * args.b elif args.o == "/": if args.a == 56 and args.b == 6: return 4.0 else: return args.a / args.b else: return "Something went wrong. Try again!" parser = argparse.ArgumentParser() parser.add_argument("--a", type=float, default=1, help="Enter your first number plz") parser.add_argument("--b", type=float, default=0, help="Enter your second number plz") parser.add_argument("--o", type=str, defaul

Python Puzzle Game

This code implements a simple puzzle game using the Pygame library. It loads a background image and puzzle piece images, creates a 3x3 grid of puzzle pieces, and allows the player to click and drag pieces to swap them. The game checks if the puzzle is solved after each move, and displays a congratulatory message if the puzzle is solved. Here's a brief summary of the code: The Pygame library is imported and initialized. The game window is set up with a width of 483 pixels and a height of 480 pixels, and a caption of "Make Abdur - Puzzle Game". The background music and sound effects are loaded from sound files. The puzzle piece images are loaded from files and stored in a list called pieces. The game loop starts, which repeatedly draws the background image and puzzle pieces on the screen and waits for user input. User input is handled using Pygame's event handling system. Specifically, the game listens for QUIT, MOUSEBUTTONDOWN, MOUSEBUTTONUP, and MOUSEMOTION events. Wh

How to enable 'God Mode' in Windows 10?

'God Mode' in Windows 10 Make a new folder anywhere on your computer and rename it to the following; GodMode.{ED7BA470-8E54-465E-825C-99712043E01C} That is it!

Command Line Arguments in Python

Open the following as this in cmd: python filename.py argument from sys import argv if len(argv) == 2: print(f"Hello, {argv[1]}!") else: print("Hello, World!") # to see what is there in argv for arg in argv: print(arg)

Extract Tables from a PDF and Save into a CSV

# first of all install the 2 dependencies # pip install tk # pip install ghostscript # and then # pip install camelot-py import camelot table = camelot.read_pdf("table.pdf", pages="1") print(table) # exports the list of tables to specified file format table.export("mytab.csv", f="csv", compress=True) # only the specified table is exported table[0].to_csv("mytab.csv")