Skip to content

Instantly share code, notes, and snippets.

View thuwarakeshm's full-sized avatar

Thuwarakesh Murallie thuwarakeshm

View GitHub Profile
@thuwarakeshm
thuwarakeshm / matmul.py
Last active August 13, 2023 17:57
faster_arrays
import numpy as np
import timeit
def matrix_muliplication_with_np(matrix1, matrix2):
return np.matmul(matrix1, matrix2)
def matrix_multiplication_with_for_loop(matrix1, matrix2):
result = np.zeros((len(matrix1), len(matrix2[0])))
import argparse
def send_email(email="default@mydomain.abc"):
# All your email sending logics goes here
print(f"Sending email...: to {email}")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
...
import argparse
...
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Watchdog script to watch for new CSV files and load them into the database"
)
@thuwarakeshm
thuwarakeshm / email-domains.py
Last active August 9, 2022 00:50
Regex with PRegEx
from pregex.classes import AnyButWhitespace
from pregex.groups import Capture
from pregex.quantifiers import OneOrMore, AtLeastAtMost
pattern = (
OneOrMore(AnyButWhitespace())
+ "@"
+ Capture(
OneOrMore(AnyButWhitespace()) + "." + AtLeastAtMost(AnyButWhitespace(), 2, 3)
try:
import tomllib
except ModuleNotFoundError:
import tomli as tomllib
@thuwarakeshm
thuwarakeshm / schedule-hello.py
Last active August 3, 2022 02:38
python-scheduling
import time
import schedule
def say_hello():
print("Hello World!")
schedule.every(5).seconds.do(say_hello)
@thuwarakeshm
thuwarakeshm / gradio_1.py
Last active June 29, 2022 15:17
Gradio demo
def find_palindroms(text: str) -> str:
# A placeholder for the palindromes found
palindromes = []
# loop through all the words in the text
for word in text.split():
# and check if they are palindromes
if word == word[::-1]:
# if they are, add them to the list
palindromes.append(word)
---
title: Create K-Means clusters
description: Specify title and number of clusters and get a plot of clustered dataset
show-code: False
format:
    theme: moon
params:
    title:
        input: text
schema = pa.DataFrameSchema(
{
"order_value": Column(
"int64",
[
Check.less_than(1000),
Check.greater_than(100),
Check(lambda x: x.sum() > 1000),
],
),
@thuwarakeshm
thuwarakeshm / bsort.py
Last active May 27, 2022 14:59
Python benchmarking
import random
from timeit import timeit
from typing import List
def bubble_sort(items: List[int]) -> List[int]:
n = len(items)
for i in range(n - 1):