This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from functools import reduce | |
try: | |
from itertools import pairwise | |
except ImportError: | |
# Simple alternative for pypy | |
def pairwise(seq): | |
seq = list(seq) | |
return zip(seq, seq[1:]) | |
import multiprocessing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PID=$1 | |
function curtime() { | |
date "+[%H:%M:%S]" | |
} | |
function check() { | |
curl -vk https://localhost:8008/ 2>&1 | grep -q $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/patroni/dcs/kubernetes.py b/patroni/dcs/kubernetes.py | |
index ade15ff..9fbd9e7 100644 | |
--- a/patroni/dcs/kubernetes.py | |
+++ b/patroni/dcs/kubernetes.py | |
@@ -107,7 +107,8 @@ class Kubernetes(AbstractDCS): | |
try: | |
return func(*args, **kwargs) | |
except (RetryFailedError, k8s_client.rest.ApiException, | |
- HTTPException, HTTPError, socket.error, socket.timeout): | |
+ HTTPException, HTTPError, socket.error, socket.timeout) as e: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE data (id serial primary key, name text, data jsonb); | |
INSERT INTO data (name, data) VALUES ('testing', '{"foo": 1, "bar": 2}'); | |
INSERT INTO data (name, data) DEFAULT VALUES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In main part of the application | |
db, err := sql.Open("postgres", connectString) | |
defer db.Close() | |
checkErr(err) | |
// In single request | |
tx, err := db.BeginTx(context.TODO(), TxOptions{sql.LevelRepeatableRead}) // Gets a single connection from pool and start transaction | |
checkErr(err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z "$1" ]; then | |
(>&2 echo "Usage: $0 \"host=.. user=.. dbname=..\"") | |
exit 1 | |
fi | |
CONNSTRING=$1 | |
cat - <<PRELUDE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gistup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssl-encrypt: ssl-encrypt.c | |
gcc -O2 ssl-encrypt.c -lcrypto -o ssl-encrypt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import RLock, Thread | |
import time | |
running = True | |
def long_lock_loop(mutex): | |
while running: | |
mutex.acquire() | |
print "Long acquired" | |
time.sleep(3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, struct, re | |
def cached_property(accessor): | |
cache_name = '_cached_%s' % accessor.__name__ | |
def property_cacher(obj): | |
try: | |
return getattr(obj, cache_name) | |
except AttributeError: | |
value = accessor(obj) | |
setattr(obj, cache_name, value) |
NewerOlder