Skip to content

Instantly share code, notes, and snippets.

View fantix's full-sized avatar
🤯

Fantix King fantix

🤯
View GitHub Profile
@fantix
fantix / gist:9246648
Created February 27, 2014 08:54
long -> integer_types
def __init__(self, fileno, mode=None, close=True):
- if not isinstance(fileno, (int, long)):
+ if not isinstance(fileno, integer_types):
raise TypeError('fileno must be int: %r' % fileno)
use std::comm::{Select, Receiver};
use std::collections::HashMap;
trait Endpoint {
fn register(&self, selector: &Select) -> uint;
fn on_event(&self);
}
@fantix
fantix / test_ssl_renegotiation.py
Created June 20, 2018 03:04
Verify OpenSSL renegotiation
import ssl
from OpenSSL import SSL
ctx = SSL.Context(SSL.TLSv1_2_METHOD)
ctx.set_options(SSL.VERIFY_NONE)
ctx.use_privatekey_file('tests/certs/ssl_key.pem')
ctx.use_certificate_chain_file('tests/certs/ssl_cert.pem')
server = SSL.Connection(ctx, None)
server.set_accept_state()
@fantix
fantix / leak.py
Created October 9, 2018 12:39
uvloop#197 reproduced crash
import asyncio
import ssl
import threading
import socket
import gc
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
@fantix
fantix / only-once.patch
Created October 11, 2018 02:13
#203 create transport only once
diff --git a/uvloop/sslproto.pxd b/uvloop/sslproto.pxd
index 30efa5c..e3f79a2 100644
--- a/uvloop/sslproto.pxd
+++ b/uvloop/sslproto.pxd
@@ -27,6 +27,7 @@ cdef class SSLProtocol:
object _waiter
object _loop
_SSLProtocolTransport _app_transport
+ bint _app_transport_created
@fantix
fantix / README.md
Last active January 22, 2024 15:16
Wire Protocol of PostgreSQL Queries in a Nutshell
@fantix
fantix / gist:f00260e40b92e6a7910bc3d25330cc5c
Created January 29, 2020 15:25
Gen3 Metadata Service API
{"openapi": "3.0.2", "info": {"title": "DCFS Metadata Service", "version": "1.2.0a0"}, "paths": {"/version": {"get": {"summary": "Get Version", "operationId": "get_version_version_get", "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {}}}}}}}, "/metadata_index": {"get": {"tags": ["Index"], "summary": "List Metadata Indexes", "description": "List all the metadata key paths indexed in the database.", "operationId": "list_metadata_indexes_metadata_index_get", "responses": {"200": {"description": "Successful Response", "content": {"application/json": {"schema": {}}}}}, "security": [{"HTTPBasic": []}]}}, "/metadata_index/{path}": {"post": {"tags": ["Index"], "summary": "Create Metadata Indexes", "description": "Create a database index on the given metadata key path.", "operationId": "create_metadata_indexes_metadata_index__path__post", "parameters": [{"required": true, "schema": {"title": "Path"}, "name": "path", "in": "path"}], "responses": {"201": {"descript
@fantix
fantix / openapi.json
Created February 11, 2020 22:40
Gen3 Metadata Service
{"openapi":"3.0.2","info":{"title":"DCFS Metadata Service","version":"1.2.0a0"},"paths":{"/version":{"get":{"summary":"Get Version","operationId":"get_version_version_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/_status":{"get":{"summary":"Get Status","operationId":"get_status__status_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}}}},"/metadata_index":{"get":{"tags":["Index"],"summary":"List Metadata Indexes","description":"List all the metadata key paths indexed in the database.","operationId":"list_metadata_indexes_metadata_index_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{}}}}},"security":[{"HTTPBasic":[]}]}},"/metadata_index/{path}":{"post":{"tags":["Index"],"summary":"Create Metadata Indexes","description":"Create a database index on the given metadata key path.","operationId":"create_metadata_indexes_metadata_index__path_
@fantix
fantix / sa_fastapi.py
Created September 16, 2020 06:22
Why you shouldn't use SQLAlchemy 1.3 with FastAPI
"""
This code demonstrates how FastAPI server freezes with SQLAlchemy under concurrency,
if you're mixing blocking operations with async calls inproperly.
(pip install sqlalchemy httpx fastapi uvicorn)
You will see 15 (not 20!) "Handling xxx", then the server freezes for minutes,
refusing to serve any request.
This is caused by "resource starvation" - the default SQLAlchemy connection pool size
<!DOCTYPE html>
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css" rel="stylesheet"
type="text/css"/>
<script charset="utf-8" src="https://d3js.org/d3.v3.js"></script>
<style>
html {