Skip to content

Instantly share code, notes, and snippets.

View KianYang-Lee's full-sized avatar

Kian Yang Lee KianYang-Lee

  • Pan United Pte. Ltd.
  • Kuala Lumpur, Malaysia
View GitHub Profile
@KianYang-Lee
KianYang-Lee / 01 - Pandas For Time Series.ipynb
Created March 21, 2021 03:56
notebook/Solution/01 - Pandas For Time Series.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@KianYang-Lee
KianYang-Lee / hello_world.py
Created January 23, 2022 04:33
"Hello World" in Python
my_output = "hello world"
print(my_output)
@KianYang-Lee
KianYang-Lee / HelloWorld.java
Created January 23, 2022 04:36
"Hello World" in Java
class HelloWorld {
public static void main(String[] args) {
String my_output = "Hello world";
System.out.println(my_output);
}
}
@KianYang-Lee
KianYang-Lee / walrus_example.py
Last active February 5, 2022 10:39
Demonstrating the difference between using walrus operator and not using walrus operator with simple example
#!/usr/bin/python3
# Prior to Python 3.8
# Assigning a value to variable and then evaluating the expression in different lines
python_version = 3.7
print(f'Python version with walrus operator? : {python_version >= 3.8}')
print(f'Applicable for Python version: {python_version}')
# Reset variable
python_version = None
@KianYang-Lee
KianYang-Lee / walrus_while_example.py
Created February 5, 2022 10:42
Demonstrate the simplicity which walrus operator provides when writing a while loop
#!/usr/bin/python3
# Longer version without walrus operator
digit_list = []
user_input = input('Type anything other than digits, and this prompt will quit: ')
while user_input.isdigit():
digit_list.append(user_input)
user_input = input('Type anything other than digits, and this prompt will quit: ')
print('The digits entered by user are: ', digit_list)
@KianYang-Lee
KianYang-Lee / prep_breakfast_linear.py
Created March 17, 2022 03:27
Simple program to mimic how to cook breakfast in a linear fashion
from time import sleep, time
def prep_breakfast():
start_time = time()
def boil_water():
print(">>> Start to boil water...")
sleep(8) # Sleep for 10 secs to mimic water boiling situation
print(">>> Water is boiled!")
@KianYang-Lee
KianYang-Lee / prep_breakfast_concurrent.py
Created March 17, 2022 03:31
Simple program to mimic how to cook breakfast in a concurrent fashion using asyncio
from time import time
import asyncio
async def prep_breakfast():
start_time = time()
async def boil_water():
print(">>> Start to boil water...")
await asyncio.sleep(8) # Sleep for 10 secs to mimic water boiling situation
print(">>> Water is boiled!")
@KianYang-Lee
KianYang-Lee / beginner_synchronous_code.py
Created March 17, 2022 03:48
A rather simple example demonstrating synchronous code
from time import sleep
print(">>> I am just learning how to program")
print(">>> Let's do something awesome")
sleep(1000) # Certain tasks that are IO-bound or CPU-bound that takes up a long time
print(">>> One awesome task is done! Let's do another awesome task!")
sleep(1000) # Repeat the process again... until you learn about a better way to do this
@KianYang-Lee
KianYang-Lee / simple_subprocess_demo.py
Created July 25, 2022 14:56
A simple demo on using `subprocess` module to generate subprocess to run shell script
import subprocess
from time import sleep
print("Program started...")
count = 0
while count < 3:
sleep(5)
print("Calling subprocess...")
completed_process = subprocess.run("./check_users.sh", shell=True)
# You can then call attribute or methods of completedProcess here
@KianYang-Lee
KianYang-Lee / understanding_decorator_in_python.py
Created September 4, 2022 13:41
Gist for codes used in the article 'Understanding Decorator (@) in Python'
import time
import typing
def add_two_integers(a: int, b: int) -> int:
return a + b
def add_two_integers(a: int, b: int) -> int:
start_time = time.time()