Skip to content

Instantly share code, notes, and snippets.

Avatar

Grant Jenks grantjenks

View GitHub Profile
View tcp_proxy.py
"""Simple TCP Proxy
Receive connections on one port and forward them to another port.
Example:
$ python3 -m http.server 8080 # Start an http server on port 8080
$ python3 tcp_proxy.py 5000 8080 # Proxy port 5000 to 8080
Open http://localhost:5000/ in Chrome
@grantjenks
grantjenks / reboot.service
Created May 3, 2020
Weekly reboots using systemd.
View reboot.service
# /etc/systemd/system/reboot.service
[Unit]
Description=Reboot Service
[Service]
Type=oneshot
ExecStart=/bin/systemctl --force reboot
View Steve-Yegge-Google-Platforms-Rant-2011-10-11.md

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't real

@grantjenks
grantjenks / xml_rpc_client_unix_domain_socket.py
Created Oct 22, 2019
Python 3 XML-RPC Using Unix Domain Sockets
View xml_rpc_client_unix_domain_socket.py
import http.client
import socket
import xmlrpc.client
class UnixStreamHTTPConnection(http.client.HTTPConnection):
def connect(self):
self.sock = socket.socket(
socket.AF_UNIX, socket.SOCK_STREAM
)
@grantjenks
grantjenks / bottlebench.py
Last active Oct 28, 2021
Server-side I/O Performance in Python
View bottlebench.py
"""Server-side I/O Performance in Python
Based on the article and discussion at:
https://www.toptal.com/back-end/server-side-io-performance-node-php-java-go
The code was posted at:
https://peabody.io/post/server-env-benchmarks/
View make_groups.py
"""Make Groups
# Problem
https://www.reddit.com/r/Python/comments/7awlm1/
I am a teacher and every year we have overnight excursions where we have to
organize rooms for around 100 students however there are a number of
requirements when organise these rooms:
@grantjenks
grantjenks / mutable_namedtuple_comparison.py
Created Dec 20, 2016
Performance Comparison of namedtuple, namedlist, and recordclass
View mutable_namedtuple_comparison.py
import sys
class Record(object):
__slots__ = ()
def __init__(self, *args):
assert len(self.__slots__) == len(args)
for field, value in zip(self.__slots__, args):
setattr(self, field, value)