Skip to content

Instantly share code, notes, and snippets.

Avatar
🤦‍♂️
^

David Blewett davidblewett

🤦‍♂️
^
View GitHub Profile
@IanColdwater
IanColdwater / twittermute.txt
Last active Sep 3, 2021
Here are some terms to mute on Twitter to clean your timeline up a bit.
View twittermute.txt
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet
@davidblewett
davidblewett / expiring_counter.py
Last active Feb 28, 2020
Expiring Counter Implementation
View expiring_counter.py
import warnings
from collections import (
Counter, MutableMapping, OrderedDict, deque,
)
from datetime import timedelta
from tornado import gen
from tornado.ioloop import IOLoop, PeriodicCallback
class ExpiringCounter(MutableMapping):
View types.markdown

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

View README.md

aws-cli bash helper functions

The official AWS command line tools, have support for configuration profiles. See Configuring the AWS Command Line Interface - Named Profiles.

Managing multiple profiles with the AWS CLI itself is relatively straight forward, switching between them with --profile flag on the command line or the AWS_PROFILE environment variable.

These helpers extend that functionality for convenience with other tools in the ecosystem.

aws-profile

@seanjensengrey
seanjensengrey / rust-python-cffi.md
Last active Sep 12, 2021
Calling Rust from Python/PyPy using CFFI (C Foreign Function Interface)
View rust-python-cffi.md

This is a small demo of how to create a library in Rust and call it from Python (both CPython and PyPy) using the CFFI instead of ctypes.

Based on http://harkablog.com/calling-rust-from-c-and-python.html (dead) which used ctypes

CFFI is nice because:

  • Reads C declarations (parses headers)
  • Works in both CPython and PyPy (included with PyPy)
  • Lower call overhead than ctypes
@bdarnell
bdarnell / streaming.py
Created Jan 11, 2015
Demo of streaming requests with Tornado
View streaming.py
"""Demo of streaming requests with Tornado.
This script features a client using AsyncHTTPClient's body_producer
feature to slowly produce a large request body, and two server
handlers to receive this body (one is a proxy that forwards to the
other, also using body_producer).
It also demonstrates flow control: if --client_delay is smaller than
--server_delay, the client will eventually be suspended to allow the
server to catch up. You can see this in the logs, as the "client
@matheusoliveira
matheusoliveira / json_manipulator.sql
Last active Sep 16, 2021
Simple PostgreSQL functions to manipulate json objects. (Note: performance is not a concern for those functions)
View json_manipulator.sql
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json)
RETURNS json
IMMUTABLE
LANGUAGE sql
AS $$
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json
FROM (
SELECT * FROM json_each(data)
UNION ALL
SELECT * FROM json_each(insert_data)
View postgresql.conf
# The following are suggested values
# They should be set in all configs,
# so that if a secondary needs to be promoted
# it will be generating the correct WAL level
wal_level = hot_standby
archive_mode = on # allows archiving to be done
# (change requires restart)
archive_command = 'cp -f %p /data/pgsql/archive/%f </dev/null' # command to use to archive a logfile segment
max_wal_senders = 5 # max number of walsender processes
# (change requires restart)
View chunkypushproducer.py
if __name__ == '__main__':
import sys
import chunkypushproducer
raise SystemExit(chunkypushproducer.main(sys.argv))
from zope.interface import implementer
from twisted.internet.interfaces import IPushProducer
from twisted.internet.task import react, deferLater, cooperate
from twisted.internet.protocol import Protocol
@jboner
jboner / latency.txt
Last active Sep 22, 2021
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD