Skip to content

Instantly share code, notes, and snippets.

View GoodManWEN's full-sized avatar
😇
他走的很安详

GoodManWEN

😇
他走的很安详
View GitHub Profile
@erikbern
erikbern / loop_hack.py
Last active April 3, 2022 21:35
Example of how to use async/await programming in Python for non-asyncio purposes
# First, let's create an awaitable object.
# In this case it's a very dumb container of integers.
# Any time a coroutine runs `await Thing(n)` it just resolves to n
# However, we could resolve it to something completely different if we wanted to
class Thing:
def __init__(self, n):
self._n = n
def __await__(self):
@cleiveliu
cleiveliu / Python-context-manager-example.md
Last active August 13, 2021 03:19
Python context manager example

source

import contextlib
import sys


def your_task():
    print("The test !")
@Kirill89
Kirill89 / SlayTheSpire-json-to-save.js
Created August 19, 2020 17:07
Slay The Spire save edit
const fs = require('fs');
let data = fs.readFileSync('IRONCLAD.autosave.json', 'utf8');
const out = [];
for (let i = 0; i < data.length; i++) {
const key = 'key';
out.push(data.charCodeAt(i) ^ key.charCodeAt(i % key.length));
}
@nkhitrov
nkhitrov / logger.py
Last active March 18, 2025 12:43
Configure uvicorn logs with loguru for FastAPI
"""
WARNING: dont use loguru, use structlog
https://gist.github.com/nkhitrov/38adbb314f0d35371eba4ffb8f27078f
Configure handlers and formats for application loggers.
"""
import logging
import sys
from pprint import pformat
@dabeaz
dabeaz / aecho.py
Last active October 17, 2023 03:26
Live-coded examples from my PyCon Brasil 2015 Keynote
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
China stock api
1.163_API(0-sh,1-sz):http://api.money.126.net/data/feed/1002151,0600036,hkHSI,hkHSCEI,hk00005
2.QQ_API(sh,sz,s_simple data):http://qt.gtimg.cn/r=0.8409869808238q=s_sz000559,s_sz002434,s_sz002472,s_sz002488,hk00700
3.sina_API(sh,sz,s_simple data):http://hq.sinajs.cn/list=sh600000,sh600004,hk00700,sz002594
# 4.xueqiu_API:http://xueqiu.com/v4/stock/quote.json?code=02318,01211,SH000001,DJI30,HKHSI
163
日内实时盘口(JSON):
http://api.money.126.net/data/feed/1000002,1000001,1000881,0601398,money.api
@messa
messa / asyncio_ssl_example.py
Created June 26, 2015 12:43
Python asyncio + SSL TCP client/server example
#!/usr/bin/env python3
import asyncio
import multiprocessing
import os
import ssl
from time import sleep
port = 9000