Skip to content

Instantly share code, notes, and snippets.

View anoj-kt's full-sized avatar

Anoj Krishna Thirunavukkarasu anoj-kt

View GitHub Profile

O(n) - Linear time

Code Example

my_list = [1, 5, 2, 8]

def sum_list(items):
    total = 0            # 1. This line runs 1 time
 for item in items: # 2. This loop runs 'n' times

Task 1: The Safe Calculator

This task focuses on creating a function with default parameters and handling a potential error using try...except.

  1. Define a function named safe_divide.
  2. This function should accept two parameters: numerator and denominator.
  3. Give the denominator a default parameter value of 1.
  4. Inside the function, use a try...except block.
  5. In the try block, calculate the result of numerator / denominator and return it.
  6. In the except block, catch the ZeroDivisionError (the error Python gives when you divide by 0).

Explanation of resolve(dirname(fileURLToPath(import.meta.url)), './src')

The line in Vite configuration:

resolve(dirname(fileURLToPath(import.meta.url)), './src')

is used to define an alias for the src folder, enabling cleaner import paths. Below is a step-by-step breakdown of how it works:

@anoj-kt
anoj-kt / Intermediate_git.md
Created August 15, 2024 11:31
14.08.2024_Recap: Intermediate Git

Resets

  1. git reset --soft

    • Effect on Commit History: Moves the HEAD (the current branch) to the specified commit without changing the working directory or the staging area.
    • Staging Area: All changes between the current commit and the target commit remain staged.
    • Working Directory: Files in your working directory remain unchanged.
    • Use Case: Use this when you want to undo a commit but keep the changes staged for a new commit.
@anoj-kt
anoj-kt / 27.03.2024_Recap: Higher Order Functions
Created March 27, 2024 18:27
27.03.2024_Recap: Higher Order Functions
//---First class functions
//1. Store in a variable
let greet = function () {
console.log('Hello');
};
// greet();
//2.Store in an object
const object = {
@anoj-kt
anoj-kt / 29.11.2023_Recap: SQL Joins & Aggregate Functions
Created November 30, 2023 08:12
This gist contains the commands used in the recap on 29.11.2023 on SQL joins and aggregate functions.
-- Creating the two tables
CREATE TABLE Customers (
customer_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
age INT,
country VARCHAR(50)
);
CREATE TABLE Orders (