Skip to content

Instantly share code, notes, and snippets.

View joeltok's full-sized avatar

joeltok joeltok

  • Singapore
View GitHub Profile
# inputs.py
import torch
inputs = torch.FloatTensor([
[1,1],
[2,2],
])
# Network.py
import torch
import torch.nn as nn
import torch.nn.functional as F
class Network(nn.Module):
def __init__(self):
super(Network, self).__init__()
self.fc1 = nn.Linear(2, 10)
@joeltok
joeltok / sync_async.py
Last active January 19, 2024 21:03
synchronous async
import asyncio
async def async_func():
await asyncio.sleep(1) # <- replace this with your async code
loop = asyncio.get_event_loop()
coroutine = async_func()
loop.run_until_complete(coroutine)
@joeltok
joeltok / main.dart
Created November 8, 2020 09:39
flutter_desktop_app_example
import 'package:flutter/material.dart';
void main() {
runApp(ExampleApp());
}
class ExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@joeltok
joeltok / python3_asyncio_error_fails_silently_do_nothing.py
Created October 12, 2020 13:21
python3_asyncio_error_fails_silently_do_nothing.py
import asyncio
async def func():
raise ValueError('encountered some error')
async def run(loop):
task = asyncio.create_task(func())
await asyncio.sleep(1)
await asyncio.sleep(1)
await asyncio.sleep(1)
@joeltok
joeltok / python3_asyncio_error_fails_silently_use_side_effects.py
Created October 12, 2020 13:16
python3_asyncio_error_fails_silently_use_side_effects.py
import asyncio
async def func():
try:
raise ValueError('encountered some error')
except ValueError as e:
# do something with the error
async def run(loop):
task = asyncio.create_task(func())
@joeltok
joeltok / python3_asyncio_error_fails_silently_await_eventually.py
Created October 12, 2020 13:11
python3_asyncio_error_fails_silently_await_eventually.py
import asyncio
async def func():
raise ValueError('encountered some error')
async def run(loop):
task = asyncio.create_task(func())
while True:
await asyncio.sleep(1)
print('ping an external api')
@joeltok
joeltok / python3_asyncio_error_fails_silently_await_directly.py
Created October 12, 2020 13:10
python3_asyncio_error_fails_silently_await_directly.py
import asyncio
async def func():
raise ValueError('encountered some error')
async def run(loop):
await asyncio.create_task(func())
while True:
await asyncio.sleep(1)
print('ping an external api')
@joeltok
joeltok / python3_asyncio_error_fails_silently_fail_example_result
Created October 12, 2020 12:40
python3_asyncio_error_fails_silently_fail_example_result
ping an external api
ping an external api
ping an external api
ping an external api
ping an external api
ping an external api
@joeltok
joeltok / python3_asyncio_error_fails_silently_fail.py
Created October 12, 2020 12:38
python3_asyncio_error_fails_silently_fail.py
import asyncio
async def func():
raise ValueError('encountered some error')
async def run(loop):
task = asyncio.create_task(func())
while True:
await asyncio.sleep(1)
print('ping an external api')