Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
sudo docker run --rm --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=1 -d postgres | |
sudo docker exec -it postgres bash | |
psql -U postgres -h localhost -W | |
create database test; | |
grant all privileges on database test to postgres; |
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 sqlalchemy | |
import databases | |
import pydantic | |
import fastapi | |
DATABASE = "postgresql://postgres:1@localhost:5432/test" | |
metadata = sqlalchemy.MetaData() | |
posts = sqlalchemy.Table("posts", metadata, |
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 | |
def d(f): | |
async def wrapper(*args, **kwargs): | |
print("Decorator") | |
await f() | |
return wrapper | |
@d | |
async def f(): |
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 | |
import socket | |
class A: | |
async def __aenter__(self): | |
self.s = socket.socket() | |
self.s.setblocking(False) | |
await loop.sock_connect(self.s, ('127.0.0.1', 5000)) | |
return self | |
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 | |
import socket | |
class A: | |
async def __aenter__(self): | |
self.s = socket.socket() | |
self.s.setblocking(False) | |
await loop.sock_connect(self.s, ('127.0.0.1', 5000)) | |
return self | |
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
def coroutine(f): | |
gen = f() | |
next(gen) | |
return gen | |
@coroutine | |
def coro(): | |
print("Coro start") | |
i = yield | |
print("Coro:", i) |
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 socket | |
import select | |
def handle(c): | |
data = c.recv(1024) | |
if not data: | |
connections.remove(c) | |
c.close() | |
return |
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 socket | |
import time | |
s = socket.socket() | |
s.connect(('127.0.0.1', 5000)) | |
try: | |
while True: | |
s.sendall(b"Hello") | |
data = s.recv(1024) | |
print(data) |
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
#include <iostream> | |
#include <thread> | |
#include <mutex> | |
#include <condition_variable> | |
#include <vector> | |
#include <functional> | |
#include <deque> | |
#include <atomic> | |
class ThreadPool; |
NewerOlder