This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastapi import APIRouter, WebSocketDisconnect, WebSocket | |
router = APIRouter() | |
@router.websocket("/") | |
async def lab_socket(websocket: WebSocket): | |
async def on_connect(): | |
# websocket connect event | |
await websocket.accept() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure("2") do |config| | |
config.vm.box = "ubuntu/bionic64" | |
config.vm.box_url = "ubuntu/bionic64" | |
config.vm.network "private_network", ip: "192.168.33.25" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
async def async_pipe(init_value, *callables): | |
""" | |
pipe for async function. work similar like toolz.pipe | |
:parameter init_value: value or invoked function/async function | |
:parameter callable: callable functions | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def multiply_by_random_number(number): | |
""" function ini mengambalikan hasil number dikalikan angka random """ | |
return number * random.randint(1, 1000) | |
multiply_by_random_number(2) # contoh, 925 | |
multiply_by_random_number(2) # contoh, 12 | |
multiply_by_random_number(2) # contoh, 564 | |
multiply_by_random_number(2) # contoh, 623 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
@functools.lru_cache | |
def fake_heavy_computation(value): | |
""" function ini mensimulasikan komputasi berat""" | |
time.sleep(2) # menunggu 2 detik untuk lanjut ke statement berikutnya | |
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
memoized_fake_heavy_computation(4) # selesai dalam 2 s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[memoized_fake_heavy_computation(3) for _ in range(10000)] # selesai dalam 600 ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
memoized_fake_heavy_computation(3) # selesai dalam 2 ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
memoized_fake_heavy_computation(3) # selesai dalam 2 s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
memoized_fake_heavy_computation = memoize(fake_heavy_computation) | |
memoized_fake_heavy_computation(3) # selesai dalam 2 s | |
memoized_fake_heavy_computation(3) # selesai dalam 4 ms | |
memoized_fake_heavy_computation(4) # selesai dalam 2 s | |
[memoized_fake_heavy_computation(3) for _ in range(10000)] # selesai dalam 600 ms |
NewerOlder