Skip to content

Instantly share code, notes, and snippets.

@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
@thsutton
thsutton / Validate.scala
Created October 14, 2015 04:34
Simple validation thing
sealed abstract class Validation[T] {
def must(p: (T => Boolean), error: String): Validation[T]
}
object Validation {
def apply[T](value: T): Validation[T] = Valid(value)
}
case class Invalid[T](value: T, errors: List[String]) extends Validation[T] {
def must(p: (T => Boolean), error: String): Validation[T] =
@thsutton
thsutton / LICENSE
Last active October 27, 2015 02:45
Count n-length paths through a graph by matrix multiplication
Copyright Thomas Sutton (c) 2015
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
@thsutton
thsutton / Set.hs
Created November 13, 2015 05:32
Compare sets by inclusion
module Set where
import Data.Set (Set)
import qualified Data.Set as S
-- | Compare two 'Set's by inclusion or, failing that, by size.
compareInclusion :: (Ord e) => Set e -> Set e -> Ordering
compareInclusion s1 s2 =
let lt = S.isSubsetOf s1 s2
gt = S.isSubsetOf s2 s1
1228.8G 201206150327
1.3G 201206180153
59.0G 201206290123
68.0G 201207090326
17.0G 201207160118
30.0G 201207200747
14.0G 201207310133
6.6G 201208030035
88.0G 201208100549
55.0G 201208240537