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 ast | |
import inspect | |
class NameVisitor(ast.NodeVisitor): | |
def __init__(self, default_value=None): | |
self.default_value = default_value | |
def visit_Name(self, node): | |
if isinstance(node.ctx, ast.Load): |
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
module Main exposing (main) | |
import Html exposing (div) | |
import Navigation | |
x = | |
42 | |
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
enum Status { | |
Todo, | |
Complete, | |
Deleted | |
} | |
record Unit {} | |
record Todo { | |
id Int | |
deadline DateTime |
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
### Keybase proof | |
I hereby claim: | |
* I am Bogdanp on github. | |
* I am bogdanp (https://keybase.io/bogdanp) on keybase. | |
* I have a public key whose fingerprint is E05E B778 DDF1 30C5 22C6 3B03 F3FF 10E0 16B3 1890 | |
To claim this, I am signing this object: |
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 | |
HOST = "127.0.0.1" | |
PORT = 9000 | |
# By default, socket.socket creates TCP sockets. | |
with socket.socket() as server_sock: | |
# This tells the kernel to reuse sockets that are in `TIME_WAIT` state. | |
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
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
with socket.socket() as server_sock: | |
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
server_sock.bind((HOST, PORT)) | |
server_sock.listen(0) | |
print(f"Listening on {HOST}:{PORT}...") | |
client_sock, client_addr = server_sock.accept() | |
print(f"New connection from {client_addr}.") |
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
RESPONSE = b"""\ | |
HTTP/1.1 200 OK | |
Content-type: text/html | |
Content-length: 15 | |
<h1>Hello!</h1>""".replace(b"\n", b"\r\n") | |
with socket.socket() as server_sock: | |
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
server_sock.bind((HOST, PORT)) |
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
RESPONSE = b"""\ | |
HTTP/1.1 200 OK | |
Content-type: text/html | |
Content-length: 15 | |
<h1>Hello!</h1>""".replace(b"\n", b"\r\n") | |
with socket.socket() as server_sock: | |
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
server_sock.bind((HOST, PORT)) |
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 typing | |
def iter_lines(sock: socket.socket, bufsize: int = 16_384) -> typing.Generator[bytes, None, bytes]: | |
"""Given a socket, read all the individual CRLF-separated lines | |
and yield each one until an empty one is found. Returns the | |
remainder after the empty line. | |
""" | |
buff = b"" | |
while True: |
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
with socket.socket() as server_sock: | |
server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
server_sock.bind((HOST, PORT)) | |
server_sock.listen(0) | |
print(f"Listening on {HOST}:{PORT}...") | |
while True: | |
client_sock, client_addr = server_sock.accept() | |
print(f"New connection from {client_addr}.") | |
with client_sock: |
OlderNewer