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 logging | |
import os | |
import sys | |
import time | |
import threading | |
import psycopg2 | |
""" | |
This script demonstrates the following race condition under PostgreSQL: | |
One connection, in transaction, drops table "mytable," then renames |
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 | |
""" | |
Get PID of n'th parent | |
This works in linux only | |
""" | |
def pnid(n=1, pid=os.getpid()): | |
for i in range(n): | |
try: | |
procfile = open("/proc/%s/status" % pid) |
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 multiprocessing | |
import sys | |
def rsetgen(count, floor, ceiling): | |
""" | |
Recursively generate all possible sets of | |
count unique numbers between floor and ceiling | |
""" | |
if 1 == count: | |
for i in xrange(floor, ceiling): |
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 operator | |
import random | |
import sys | |
# https://en.wikipedia.org/wiki/Prisoners_and_hats_puzzle#Countably_Infinite_Hat_Problem_with_Hearing | |
def answer(death_row, answers): | |
return reduce(operator.xor, death_row + answers) | |
def main(death_row): |
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
sec = 512 | |
k = 1024 | |
m = k * k | |
g = m * k | |
bs = 4 * m /sec | |
# Generate a partition table for consumption by sfdisk | |
# (partition plan is hardcoded below) | |
partplan = ( |
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
tohex = lambda a:'.'.join('%02X' % p for p in a) | |
fromhex = lambda h:[int(p,16) for p in h.split('.')] | |
tobin = lambda a:'.'.join('{0:08b}'.format(p) for p in a) | |
frombin = lambda h:[int(p,2) for p in h.split('.')] | |
class IPAddr(object): | |
def __init__(self, address): | |
if isinstance(address, (int,long)): | |
self.long = address | |
else: |
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
""" | |
Performance benchmark: pandas DataFrame.pivot against crosstab | |
""" | |
from datetime import datetime, timedelta | |
import io | |
import random | |
import sys | |
import time | |
import pandas as pd |
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 contextlib | |
import itertools | |
import operator | |
import os | |
import sys | |
import time | |
import psycopg2 | |
import pgcopy | |
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
#!/usr/bin/python3 | |
# | |
# usage: python3 docker_descendants.py <image_id> ... | |
import sys | |
from subprocess import check_output | |
def main(images): | |
image_ids = set(images) |
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 mcr.microsoft.com/dotnet/core/sdk:3.1 | |
RUN apt-get update && apt-get install -y netcat | |
COPY Test.fsproj Program.fs /Test/ | |
WORKDIR /Test | |
RUN dotnet restore # --verbosity detailed |
OlderNewer