Skip to content

Instantly share code, notes, and snippets.

module Main (main) where
-- http://tools.ietf.org/html/rfc5952
import Data.Word (Word64)
import Data.Bits ((.|.), (.&.), shiftL, shiftR)
import Data.Maybe (listToMaybe)
import Numeric (showHex)
import Data.List (intercalate, isInfixOf)
import Data.List.Split (splitOn)
Index: awk.1
===================================================================
--- awk.1 (revision 270781)
+++ awk.1 (working copy)
@@ -208,7 +208,7 @@
if no argument.
.TP
.B rand
-random number on (0,1)
+random number on [0,1)
import Control.Applicative (Applicative(..))
import Control.Monad (ap)
data MyIO a = Return a
| Get (String -> MyIO a)
| Put String (MyIO a)
instance Functor MyIO where
fmap f (Return a) = Return (f a)
fmap f (Get g) = Get (fmap f . g)
@horus
horus / gist:7119051
Created October 23, 2013 13:45
OSX Mavericks & Xcode 5: clang wrapper script for GHC 7.6.3
#!/usr/bin/perl
use strict;
use warnings;
my $argv = join ' ', @ARGV;
if (index($argv, '-E')+1 && index($argv, '-undef')+1 && index($argv, '-traditional')+1) {
$argv =~ s/-x c/-x assembler-with-cpp/g;
@ARGV = split ' ', $argv;
@horus
horus / gist:6730285
Last active December 24, 2015 02:19
A simple Google PageRank™ checker
{-# LANGUAGE BangPatterns #-}
import Data.Bits
import Data.Char (ord)
import Data.Maybe (fromMaybe, listToMaybe)
import Numeric (showHex)
import Network.Browser
import Network.HTTP
import System.Environment (getArgs)
import System.Exit (exitFailure)
@horus
horus / gist:6304749
Created August 22, 2013 08:54
Generate JSON config file from the contents of the Sensu plugins directory
#!/bin/sh
echo "{"
echo " \"checks\": {"
for i in `ls /etc/sensu/plugins/*metrics.rb`; do
[ -z $trc ] || echo $trc
name=`basename $i | sed 's/\..*//'`
echo " \"$name\": {"
echo " \"type\": \"metric\","
@horus
horus / gist:6200687
Last active December 20, 2015 21:49
Church encoding
-- numbers
zero _ = id
one f = f
two f = f . f
-- numeric operators
succ n f = f . (n f)
plus m n f = (n f) . (m f)
From 635c5e90c99f631da2c7a2a3b885970114b429c4 Mon Sep 17 00:00:00 2001
From: horus <horus.li@gmail.com>
Date: Fri, 26 Jul 2013 15:39:20 +0800
Subject: [PATCH] pass client address to mysql_get_resultset()
---
contrib/dlz/drivers/dlz_mysql_driver.c | 41 +++++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/contrib/dlz/drivers/dlz_mysql_driver.c b/contrib/dlz/drivers/dlz_mysql_driver.c
import Data.Typeable
import Data.Dynamic
f :: Typeable a => Maybe a -> String
f x
| typeOf' x == "Maybe [Char]" = "string"
| typeOf' x == "Maybe Int" = "int"
| otherwise = "anything else"
where typeOf' = flip (showsTypeRep . typeOf) ""
@horus
horus / gist:5821516
Created June 20, 2013 09:40
Build fontforge (20120731-b) on Mac OS X 10.8
XCODE_ROOT=`xcode-select -print-path`
SDK_ROOT=${XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
FRAMEWORK_ROOT=${SDK_ROOT}/System/Library/Frameworks
sed -i.bak -e 's|/Developer/Headers/FlatCarbon/Files.h|CarbonCore/Files.h|' fontforge/macbinary.c fontforge/startui.c gutils/giomime.c
sed -i.bak -e 's|/Developer/Headers/FlatCarbon/CarbonEvents.h|HIToolbox/CarbonEvents.h|' fontforge/startui.c
env CFLAGS="-isysroot ${SDK_ROOT} -F${FRAMEWORK_ROOT}/CoreServices.framework/Frameworks -F${FRAMEWORK_ROOT}/Carbon.framework/Frameworks" \
./configure --prefix=$HOME/local --with-freetype-src=$HOME/local/src/freetype-2.5.0.1 \
--enable-double --without-freetype-bytecode --without-python --with-static-imagelibs