Value | Color |
---|---|
\e[0;30m | Black |
\e[0;31m | Red |
\e[0;32m | Green |
\e[0;33m | Yellow |
\e[0;34m | Blue |
\e[0;35m | Purple |
# Python 3.5.2-slim | |
import json | |
from tornado.httpclient import HTTPClient | |
response = HTTPClient().fetch("https://www.howsmyssl.com/a/check").body.decode() | |
data = json.loads(response) | |
tls_version = data["tls_version"] | |
print(tls_version)" # TLS 1.2 |
rpc-secret=maple3142 | |
enable-rpc=true | |
rpc-allow-origin-all=true | |
rpc-listen-all=true | |
max-concurrent-downloads=5 | |
continue=true | |
max-connection-per-server=16 | |
min-split-size=10M | |
split=10 | |
max-overall-download-limit=0 |
from aiohttp import web | |
async def handle(request): | |
response = web.StreamResponse( | |
status=200, | |
reason='OK', | |
headers={'Content-Type': 'text/plain'}, | |
) | |
await response.prepare(request) |
This is a Python 3 HTTP/1.1 server bound to 127.0.0.1 on port 8000 using only the standard library.
I wanted a simple Python 3 web server using HTTP 1.1 that can perform simple HTTP operations and depends only on Python and standard library modules. I couldn't find an example so I made one.
The example demonstrates how to accept different methods, parse the url and query strings, read data sent to the server, parse and return json, return responses with different status codes and headers, handle graceful termination, and override the default error logging.
Sometimes a programming language has a "strict mode" to restrict unsafe constructs. E.g., Perl has use strict
, Javascript has "use strict"
, and Visual Basic has Option Strict
. But what about bash? Well, bash doesn't have a strict mode as such, but it does have an unofficial strict mode:
set -euo pipefail
set -e
- Make sure the isort extension is installed in VSCode
The latest VSCode update brought the requirement to use a python environment 3.8+ for isort:
2025-04-24 13:28:29.888 [info] No interpreter found from setting isort.interpreter
# aproducer.py | |
# | |
# Async Producer-consumer problem. | |
# Challenge: How to implement the same functionality, but no threads. | |
import time | |
from collections import deque | |
import heapq | |
class Scheduler: |
import json | |
import wikitextparser | |
with open("table1.json") as f: # or table2.json | |
data = json.load(f) | |
source = data["source_text"] | |
parsed = wikitextparser.parse(source) | |
print("Processing tables") | |
# This one will hang |