Skip to content

Instantly share code, notes, and snippets.

#!/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/
@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;
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
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 = {}
@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
=================
@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
#!/bin/sh
# Make freebsd vm
# fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/VM-IMAGES/10.1-RELEASE/amd64/Latest/FreeBSD-10.1-RELEASE-amd64.raw.xz
VM="FreeBSD10"
RAW_IMG="$1"
BASE_IMG="${RAW_IMG%.raw}"
VMDK_IMG="${BASE_IMG}.vmdk"
# get the dif based on a pull request.
# first get the merge info
% git log --format="%p" -1 refs/pull/1/merge
395a6b6 c07adb2
# find the common parent
% git merge-base 395a6b6 c07adb2
7a6ad5e1339681dda3ba55722307143b09685038
# now get the diff for the entire thing.
% git diff 7a6ad5e1339681dda3ba55722307143b09685038..c07adb2
@splbio
splbio / gist:11020055
Created April 18, 2014 01:17
Fix for pkg+freebsd10-stable
diff --git a/nanobsd/common b/nanobsd/common
index dc7c0a4..f7da3d4 100644
--- a/nanobsd/common
+++ b/nanobsd/common
@@ -291,7 +291,11 @@ do_add_pkg ()
mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \
${NANO_WORLDDIR}/usr/ports/packages
- CR "cd /usr/ports/packages/All;env SIGNATURE_TYPE=none pkg add -f $1.txz && touch $1.txz.added "
+ local delete_it=true
@splbio
splbio / radio.diff
Created April 17, 2014 06:42
radio killed the port star
diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
index c56f7e0..120957f 100644
--- a/Mk/bsd.port.mk
+++ b/Mk/bsd.port.mk
@@ -5911,17 +5911,34 @@ OPTIONS_WRONG_SINGLE+= ${single}
.endfor
.undef single
+#
+# Iterate through each OPTIONS_RADIO