Skip to content

Instantly share code, notes, and snippets.

View justinvanwinkle's full-sized avatar

Justin Van Winkle justinvanwinkle

View GitHub Profile
class Pool:
def __init__(self,
connection_factory,
target_size=0,
decay_time=0):
self.connection_factory = connection_factory
self.target_size = target_size
self.decay_time = decay_time
self._connections = {}
self.pool_lock = RLock()
scratch=# CREATE TABLE bub (bub_id UUID PRIMARY KEY DEFAULT uuid_generate_v4());
CREATE TABLE
scratch=# CREATE TABLE foo (foo_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), bub_id UUID NOT NULL REFERENCES bub (bub_id) ON DELETE CASCADE);
CREATE TABLE
scratch=# CREATE TABLE subfoo (message TEXT) INHERITS (foo);
CREATE TABLE
scratch=# insert into bub DEFAULT VALUES;
INSERT 0 1
scratch=# insert into bub DEFAULT VALUES;
INSERT 0 1
@justinvanwinkle
justinvanwinkle / broken.py
Last active March 22, 2024 22:52
Every python rate-limiting library (that I can find) is broken, at least a little.
# I was looking for a rate limiting library to call rate limited apis as closely
# as possible to their enforced limits. I looked at the first few python libraries
# that I found, and when I glanced at the source, they were all clearly broken.
# Curious how this could be, I took all the top google and pip search results for: python rate limiting
# and tried to get them to do the wrong thing and fail to rate limit in situations that could come up
# in normal use (though in some cases very specific use)
# https://github.com/tomasbasham/ratelimit
# Where broken:
import numpy as np
from itertools import groupby
def fuck_my_face():
A = np.ones((5, 2)) # A is array([[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]])
B = np.ones((5, 2)) # B is array([[1, 1], [1, 1], [1, 1], [1, 1], [1, 1]])
cramdb=# select d->'isbn_10' from bub where d ? 'isbn_10' limit 5;
?column?
------------------------------
["0521641985", "0521645719"]
["039455583X"]
["0738706884"]
["1603200495"]
["0665890753"]
(20 rows)
inline vector<string> glob(string pattern, bool only_files = false) {
unique_ptr<glob_t, decltype(&globfree)> glob_buffer(new glob_t(), globfree);
glob(pattern.c_str(), GLOB_TILDE, NULL, glob_buffer.get());
strings fns;
for (size_t i = 0; i < glob_buffer->gl_pathc; ++i) {
fns.push_back(string(glob_buffer->gl_pathv[i]));
}
from os.path import join as join_path
from os import listdir
from os import mkdir
from os.path import exists as path_exists
from os.path import expanduser
from OpenSSL.crypto import X509Extension
from OpenSSL.crypto import X509
from OpenSSL.crypto import dump_privatekey
from OpenSSL.crypto import dump_certificate
rt.local (0.0.0.0) Mon Jun 16 21:09:50 2014
Keys: Help Display mode Restart statistics Order of fields quit
Packets Pings
Host Loss% Snt Last Avg Best Wrst StDev
1. router.asus.com 0.0% 60 3.4 0.9 0.7 3.4 0.5
2. 24.7.116.1 30.5% 60 27.5 12.2 9.0 27.8 6.0
3. te-0-2-0-11-sur03.sanjose.ca.sfba.comcast.net 33.9% 60 9.5 11.7 9.1 47.0 6.9
4. te-1-13-0-0-ar01.sfsutro.ca.sfba.comcast.net 23.7% 60 11.8 18.1 10.6 102.5 15.0
5. he-3-10-0-0-cr01.sanjose.ca.ibone.comcast.net 25.4% 59 32.5 22.1 12.2 105.1 23.1
6. be-15-pe02.11greatoaks.ca.ibone.comcast.net 22.4% 59 16.3 18.4 15.4 36.7 5.3
x = 5
def foo():
print x
x = 10
print x
foo()