Skip to content

Instantly share code, notes, and snippets.

@chandraseta
chandraseta / streamlit_center_text.py
Created February 20, 2022 15:42
Center text for Streamlit with optional container
import streamlit as st
from streamlit.delta_generator import DeltaGenerator
def display_centered_text(text: str, container: Optional[DeltaGenerator] = None):
if container is not None:
container.markdown(
f"<div style='text-align: center;'>{text}</div>",
unsafe_allow_html=True)
@chandraseta
chandraseta / paparazzi_streamlit.py
Created February 20, 2022 10:15
Snippet of Python code for getting an input and displaying output in a Streamlit page
import streamlit as st
def main():
st.title("WikiUpdate")
st.write("Extractive Summarization Based Indonesian Paragraph Generator " +
"for Character Biography")
st.session_state["character_name"] = st.text_input(
label="Character's Name"
@chandraseta
chandraseta / page.html
Created February 20, 2022 08:25
Snippet of HTML code to display result in a webpage using Flask
...
<div>
{% if error is defined and error != '' %}
<div class="card center w-50 card-error">
<h5 class="card-header">Error</h5>
<div class="card-body">
{{error}}
</div>
</div>
@chandraseta
chandraseta / page.html
Created February 20, 2022 08:15
Snippet of HTML code to get an input in a webpage using Flask
...
<div class="container">
<form action="/submit" method="post">
<table class="subContainer">
<h4>Character's Name</h4>
<input class="form-control" type="text" id="input_name" name="input_name">
</table>
<input class="center btn btn-primary" type="submit" value="Generate">
</form>
@chandraseta
chandraseta / bogobogosort.py
Last active February 4, 2022 17:04
Implementation of Bogobogosort in Python
from random import shuffle
from typing import List
def bogobogosort(items: List, reverse: bool = False) -> List:
""" Sorts a list... eventually
Args:
items (List): list of items to be sorted
@chandraseta
chandraseta / bogosort.py
Last active February 4, 2022 17:04
Implementation of Bogosort in Python
from random import shuffle
from typing import List
def bogosort(items: List, reverse: bool = False) -> List:
""" Sorts a list by shuffling the elements
Args:
items (List): list of items to be sorted
@chandraseta
chandraseta / quantum_bogosort.md
Last active October 25, 2024 23:47
Pseudocode of Quantum Bogosort

Quantum Bogosort

  1. Quantumly randomise the list. As there are n! possibilities, this will create n! branches of the universe.
  2. In each universe, check if the list is sorted. If not, destroy the universe.
  3. Surviving universe contains sorted list.
@chandraseta
chandraseta / sleep_sort.py
Last active February 4, 2022 17:05
Implementation of Sleep Sort in Python
from time import sleep
from threading import Timer
from typing import List
def sleepsort(items: List, reverse: bool = False) -> List:
""" Sorts a list by sleeping.
Credit: rosettacode.org
@chandraseta
chandraseta / intelligent_design_sort.py
Last active February 4, 2022 17:05
Implementation of Intelligent Design Sort in Python
from typing import List
def intelligent_design_sort(items: List, reverse: bool = False) -> List:
""" Sorts a list based on Intelligent Design philosophy.
Probability of a list being in its current order is 1/(n!). It is a very
small probability that it is absurd to claim it happens by chance.
The only possible explanation is that the list has been put in that order
@chandraseta
chandraseta / thanos_sort.py
Last active March 27, 2024 15:22
Implementation of Thanos Sort in Python
from random import sample
from typing import List
def thanos_sort(items: List, reverse: bool = False) -> List:
""" Sorts a list by snapping the list until it is sorted.
"Because you murdered half the planet!"
"A small price to pay for salvation."