Skip to content

Instantly share code, notes, and snippets.

@lpsmith
lpsmith / pgtest.c
Created January 18, 2011 01:15
Example of binary IO using libpq
// This is a demonstration of binary input into postgres using libpq. It
// is based on postgresql-9.0.2/src/test/examples/testlibpq3.c
//
// Create a table appropriate to this test in a database as follows:
//
// CREATE TABLE test (name BYTEA);
//
// See also http://article.gmane.org/gmane.comp.lang.haskell.cafe/85116
import Distribution.Simple
import Distribution.Simple.Setup
import Distribution.Simple.LocalBuildInfo
import Distribution.PackageDescription
import Distribution.Version
import Text.Groom
-- This checks the direct dependency of the bytestring package being
-- compiled against to set the bytestring_has_itoa_c and
{-# LANGUAGE ScopedTypeVariables #-}
module LogFollower where
import Control.Concurrent (threadDelay)
import Control.Exception
import Data.ByteString.Char8 as BS
import Data.ByteString.Lazy as BL
import Data.IORef
import Data.Function(fix)
@lpsmith
lpsmith / ddclient.service
Created August 24, 2017 21:09
ddclient unit file for systemd
[Unit]
Description=ddclient service
After=network.target
[Service]
ExecStart=/usr/local/sbin/ddclient -file /etc/ddclient/ddclient.conf -daemon 300 -foreground -pid /dev/null
User=ddclient
Restart=always
RestartSec=300
@lpsmith
lpsmith / decodeqr
Created August 29, 2017 06:33
Bash scripts for working with qr codes
#!/bin/bash
DECODEQR_TMPDIR=$(mktemp --tmpdir=$TMPDIR -d)
if [ $? -eq 0 -a ! -z "$DECODEQR_TMPDIR" ]; then
#mkfifo $DECODEQR_TMPDIR/tmp.png
gnome-screenshot -f $DECODEQR_TMPDIR/tmp.png
zbarimg --quiet $DECODEQR_TMPDIR/tmp.png
rm -rf $DECODEQR_TMPDIR
fi
@lpsmith
lpsmith / HHHT.m
Created January 23, 2019 00:37
Expected first sighting of HHHH versus HHHT in a sequence of coin flips of a fair coin.
hhhh_transition_matrix = [
0.5 0.5 0.5 0.5 0 0;
0.5 0 0 0 0 0;
0 0.5 0 0 0 0;
0 0 0.5 0 0 0;
0 0 0 0.5 0 0;
0 0 0 0 1 1
];
hhht_transition_matrix = [