Skip to content

Instantly share code, notes, and snippets.

View davidblewett's full-sized avatar
🤦‍♂️
^

David Blewett davidblewett

🤦‍♂️
^
View GitHub Profile
@jboner
jboner / latency.txt
Last active April 19, 2024 23:08
Latency Numbers Every Programmer Should Know
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
@IanColdwater
IanColdwater / twittermute.txt
Last active April 3, 2024 19:43
Here are some terms to mute on Twitter to clean your timeline up a bit.
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
@seanjensengrey
seanjensengrey / rust-python-cffi.md
Last active April 3, 2024 11:55
Calling Rust from Python/PyPy using CFFI (C Foreign Function Interface)

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
@matheusoliveira
matheusoliveira / json_manipulator.sql
Last active February 17, 2024 15:14
Simple PostgreSQL functions to manipulate json objects. (Note: performance is not a concern for those functions)
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)

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.

@ymirpl
ymirpl / gist:1052094
Created June 28, 2011 20:21
Python unicode e-mail sending
#coding: utf-8
from cStringIO import StringIO
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from email import Charset
from email.generator import Generator
import smtplib
# Example address data
@bdarnell
bdarnell / streaming.py
Created January 11, 2015 21:23
Demo of streaming requests with Tornado
"""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
@davidblewett
davidblewett / expiring_counter.py
Last active February 28, 2020 18:07
Expiring Counter Implementation
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):
# 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)

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