Skip to content

Instantly share code, notes, and snippets.

View thuwarakeshm's full-sized avatar

Thuwarakesh Murallie thuwarakeshm

View GitHub Profile
# Imports
# -----------------------------------------------------------
import os
import streamlit as st
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
application = get_wsgi_application()
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
@thuwarakeshm
thuwarakeshm / check_password.py
Last active February 15, 2024 17:18
Streamlit with Django
def check_password():
"""Returns `True` if the user had a correct password."""
def password_entered():
"""Checks whether a password entered by the user is correct."""
user = authenticate(
username=st.session_state['username'],
password=st.session_state['password']
)
rank ensemble_weight type cost duration
1 0.540 random_forest 0.340 2.307
2 0.040 random_forest 0.399 1.863
3 0.060 random_forest 0.419 2.268
4 0.020 lda 0.427 0.685
5 0.080 lda 0.443 0.597
6 0.040 liblinear_svc 0.443 0.692
7 0.060 lda 0.447 0.612
8 0.020 random_forest 0.458 1.556
9 0.020 liblinear_svc 0.474 3.518
bboxes = [[0, 128, 300, 420], [366.7, 340, 270, 230]]
category_ids = [1, 2]
transform = A.Compose(
[A.HorizontalFlip(p=0.5), A.Rotate()],
bbox_params=A.BboxParams(format="coco", label_fields=["category_ids"]), # Configuring pipeline for annotation
)
# Passing annotation coordinates and categories with the image
transformed = transform(image=image, bboxes=bboxes, category_ids=category_ids)
import os
# testing Fibonacci number function
def fib(n: int) -> int:
return n if n < 2 else fib(n-1)+fib(n-2)
def test_fibonacci():
assert fib(int(os.environ["FIB_INPUT"])) == 55 # It was 54 before
import unittest
def fib(n: int):
return n if n < 2 else fib(n - 1) + fib(n - 2)
class TestFibonacciFunction(unittest.TestCase):
def test_big_fibonacci(self):
self.assertEqual(fib(10), 55)
from pipe import chain
nested_list = [[1, 2, 3], [4, 5, 6], [7, [8, 9]]]
unfolded_list = list(nested_list
| chain
)
print(unfolded_list)
@thuwarakeshm
thuwarakeshm / customcode.py
Last active December 17, 2021 14:55
Python comments, why they are important?
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# Your app
"myawesomeapp",
]
from django.urls import path
from views import sum_odd_numbers
urlpatterns = [
path("sum_odd_numbers/<int:n>", sum_odd_numbers),
]