Skip to content

Instantly share code, notes, and snippets.

View nhumrich's full-sized avatar

Nick Humrich nhumrich

View GitHub Profile
@nhumrich
nhumrich / pep501test.py
Last active March 14, 2023 19:53
Pep501 proposal with tests
class TemplateLiteral:
__slots__ = ("raw_template", "parsed_template", "field_values", "format_specifiers")
def __new__(cls, raw_template, parsed_template, field_values, format_specifiers):
self = super().__new__(cls)
self.raw_template = raw_template
if len(parsed_template) == 0:
raise ValueError("'parsed_template' must contain at least one value")
self.parsed_template = parsed_template
self.field_values = field_values
@nhumrich
nhumrich / gist:a722fab1ba0d9203f94187651e3e7ac8
Created January 20, 2023 20:42
PEP 501 rewrite for t-strings
PEP: 501
Title: General purpose string template literals
Version: $Revision$
Last-Modified: $Date$
Author: Nick Coghlan <ncoghlan@gmail.com>, Nick Humrich <nick@humrich.us>
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
Requires: 498
Created: 08-Aug-2015
@nhumrich
nhumrich / arch_linux_installation.md
Last active April 19, 2021 02:27 — forked from OdinsPlasmaRifle/arch_linux_installation.md
LVM on LUKS Arch installation with systemd-boot
const { Client } = require('pg')
const client = new Client({user: 'postgres', 'database': 'postgres'})
client.connect()
client.query('BEGIN', [], (err,res) => {
console.log(err ? err.stack : res.rows[0])
})
client.query('CREATE TABLE if not exists foo ( id text, bar double precision )', [], (err,res) => {
@nhumrich
nhumrich / asyncpgsa_benchmark.py
Created August 10, 2017 15:54
asyncpgsa benchmark against aiopg.sa
import asyncio
import aiopg
import aiopg.sa
import asyncpg
import asyncpgsa
import sqlalchemy as sa
pg_tables = sa.Table(
'pg_tables', sa.MetaData(),
sa.Column('schemaname'),
@nhumrich
nhumrich / metaclass_wrapping_vs_getattr.py
Last active June 13, 2017 17:27
metaclass wrapping vs __getattr__
import functools
import inspect
from timeit import timeit
class Bob:
__slots__ = ('a',)
def __init__(self):
self.a = 5
@nhumrich
nhumrich / oreilly.py
Created January 27, 2017 16:29
get free o'reilly books
"""Script to download free O'Reilly ebooks."""
import asyncio
import os
import re
import sys
import aiohttp
filename_matcher = re.compile(r'http://www.oreilly.com/(.*)/free/(.*).csp')
session = None
@nhumrich
nhumrich / async_fib_benchmark.py
Last active September 27, 2018 20:10
async vs threading cpu bound benchmark
import asyncio
from multiprocessing.pool import ThreadPool
from timeit import timeit
from functools import partial
pool = ThreadPool(processes=400)
loop = asyncio.get_event_loop()
def fib(x):
@nhumrich
nhumrich / async_http_benchmark.py
Created November 3, 2016 03:11
async vs threading http benchmark
from timeit import timeit
import asyncio
import requests
from threading import Thread
import aiohttp
client = aiohttp.ClientSession()
@nhumrich
nhumrich / tornado_example.py
Last active August 19, 2018 04:42
async blog tornado example
import tornado.ioloop
from tornado.httpclient import AsyncHTTPClient
urls = ['http://www.google.com', 'http://www.yandex.ru', 'http://www.python.org']
def handle_response(response):
if response.error:
print("Error:", response.error)
else:
url = response.request.url
data = response.body