Skip to content

Instantly share code, notes, and snippets.

@thsutton
thsutton / README.md
Created December 31, 2010 12:40
Example of looping in Heist templates

Looping tags in Heist templates

This is a small example demonstrating how to implement looping template tags ("splices") with the Heist template system that is the default with the Snap Framework.

The src/Site.hs file contains the interesting bits:

  • The loop handler which simply renders the [loop.tpl
@thsutton
thsutton / normalise-path.php
Created January 10, 2011 03:02
Normalise paths in PHP
<?php
/**
* Normalise a file path string so that it can be checked safely.
*
* Attempt to avoid invalid encoding bugs by transcoding the path. Then
* remove any unnecessary path components including '.', '..' and ''.
*
* @param $path string
* The path to normalise.
* @param $encoding string
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as C (pack, unpack)
import qualified Data.ByteString.Lazy as L (fromChunks)
import qualified Data.ByteString.Lazy.Char8 as LC (pack)
import Data.Digest.Pure.SHA (hmacSha1, showDigest)
import Data.List (sort)
import Network.URL (URL(..), importURL, exportURL, exportParams, add_param)
-- | Calculate the SHA-1 HMAC of the parameters and include it as the parameter "h".
signParameters :: ByteString -- | The key for HMAC.
# modules/apache/manifests/init.pp
#
# Configure and manage Apache (in the Debian manner).
#
class apache {
# Configuration that might need to be tweaked.
$apache2_mods = "/etc/apache2/mods"
$apache2_sites = "/etc/apache2/sites"
@thsutton
thsutton / ip_in_block.php
Created March 17, 2011 04:23
Function to check membership of an IPv4 address in an IPv4 CIDR block.
<?php
/**
* Check whether a IPv4 CIDR notation block contains an IP address.
*
* @param $cidr string
* An IPv4 CIDR block like "192.168.56.0/24".
* @param $ip string
* An IPv4 address like "192.168.56.101".
* @return bool

Welcome to Drift!

Drift is an always-already versioned, cloud-backed text editor. You can use it to take notes, and save them in the GitHub cloud.

Your gists are always saved locally, and any changes you make will get pushed to GitHub's servers.

To name a gist, touch its name in the toolbar.

You can use the share button at the top-right to copy a link to one of your gists, or view it on the web in Safari.

@thsutton
thsutton / mimetypecheck.sh
Created November 4, 2011 03:47
Check that MIME type header and file content match
#!/bin/sh
#
# Check that the MIME type sent be a web server and the type of data in the file match.
#
# Usage: mimetypecheck.sh http://example.com/ http://example.org/
CURL="curl --silent"
for URL in $*; do
@thsutton
thsutton / branch.hs
Created December 29, 2011 12:01 — forked from snoyberg/branch.hs
branch in conduits
{-# LANGUAGE NoMonomorphismRestriction #-}
import Data.Conduit
import qualified Data.Conduit.List as CL
branch :: Resource m
=> Sink lIn m lOut
-> Sink rIn m rOut
-> Sink (Either lIn rIn) m (lOut, rOut)
branch (Sink mlsink) (Sink mrsink) = Sink $ do
lsink <- mlsink
@thsutton
thsutton / README.md
Created February 29, 2012 08:46
Basic Feeds support for nodereference CCK fields.

Node Reference support for Feeds

Adding basic support for Node Reference fields to the Feeds module is pretty straightforward (if you don't worry too much about the advanced features of nodereference).

In fact, it's almost a direct copy of the existing support for basic CCK field

@thsutton
thsutton / README
Created June 15, 2012 08:59
Generate an empty Drupal module, with hooks.
mkmodule.sh
===========
This is a short script to create empty Drupal modules. Given a short name and
a list of hooks, it'll create a brand new module with placeholders of the
hooks you want.
sh mkmodule.sh example install uninstall requirements schema menu