Skip to content

Instantly share code, notes, and snippets.

@splbio
splbio / gist:58519a96b0ae72577975
Last active August 29, 2015 14:23
How to get python stacktraces in gdb on FreeBSD
# First build the python package with DEBUG, and then install the resulting python-gdb.py script into a place where gdb will find it.
/usr/ports/lang/python27 # make config OPTIONS_FILE_SET=DEBUG
/usr/ports/lang/python27 # find . -name python-gdb.py
./work/Python-2.7.8/python-gdb.py
cp ./work/Python-2.7.8/python-gdb.py \
/usr/local/bin/python2.7-gdb.py
# Now install gdb with python support:
/usr/ports/devel/gdb # make config OPTIONS_FILE_SET=PYTHON
@splbio
splbio / parse_inline_rst.py
Last active August 29, 2015 14:23
Parsing inline rst into nodes
import docutils.frontend
# http://docutils.sourceforge.net/docs/dev/hacking.html#parsing-the-document
parser = docutils.parsers.rst.Parser()
src = """
This is a heading
=================
import xml.sax
class FartHandler(xml.sax.ContentHandler):
FART_LEVEL = 3 # the schema is bad and you should feel bad...
def __init__(self):
self.lvl = 0
self.infarts = False
self.curfart = {}
def nextDay(year, month, day):
"""Simple version: assume every month has 30 days"""
if day < 30:
return year, month, day + 1
else:
if month == 12:
return year + 1, 1, 1
else:
return year, month + 1, 1
@splbio
splbio / row_max_association.sql
Last active July 13, 2016 19:18
Prevent creation of too many associated rows in postgresql trigger.
CREATE TRIGGER "Q_limit_answers_per_question" AFTER INSERT or UPDATE on question_answer
FOR EACH ROW EXECUTE PROCEDURE question_answer_insert();
CREATE OR REPLACE FUNCTION question_answer_insert()
RETURNS TRIGGER AS
$body$
BEGIN
-- Lock the existing rows to prevent race condition with other txns.
PERFORM * FROM question_answer WHERE question_id = NEW.question_id for UPDATE;
#!/bin/sh
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 << "EOF"
# install_certifi.py
#
# sample script to install or update a set of default Root Certificates
# for the ssl module. Uses the certificates provided by the certifi package:
# https://pypi.org/project/certifi/