Skip to content

Instantly share code, notes, and snippets.

View aslatter's full-sized avatar
🐄

Antoine Latter aslatter

🐄
View GitHub Profile
@aslatter
aslatter / TimeTest.hs
Created November 26, 2012 13:14
getModificationTime shim
{-# LANGUAGE CPP #-}
import Data.Functor ((<$>))
import Data.Time
import System.Directory
#if !(MIN_VERSION_time(1,2,0))
import Data.Time.Clock.POSIX
import System.Time (ClockTime(..))
#endif
@aslatter
aslatter / example.c
Created May 2, 2012 19:53
percent encoding in C
#include "percent_encoding.h"
#include <string.h>
#include <stdio.h>
int main()
{
char* input = "Hello, world!";
int out_len = max_encoded_buffer_size(strlen(input));
char output[out_len+1];
@aslatter
aslatter / uuid_demo.c
Created March 28, 2012 15:47
Working with UUIDs on windows (with Rpc.h)
#define WIN32_LEAN_AND_MEAN
#define NOGDI
#include <windows.h>
#include <Rpc.h>
#include <stdio.h>
int main(int argc, char** argv)
{
@aslatter
aslatter / CerealDemo.hs
Created March 15, 2012 22:47
Generic Serialization w/Cereal
{-# LANGUAGE DeriveGeneric #-}
import Data.Int
import Data.Serialize
import GHC.Generics
data DemoType
= Case1 {this::Int8, that::String}
| Case2
| Case3 {foo::DemoType2}
@aslatter
aslatter / gist:2033416
Created March 14, 2012 02:09
Benchmarks after
warming up
estimating clock resolution...
mean is 2.904412 us (320001 iterations)
found 62512 outliers among 319999 samples (19.5%)
54655 (17.1%) low severe
7857 (2.5%) high severe
estimating cost of a clock call...
mean is 85.60458 ns (23 iterations)
found 4 outliers among 23 samples (17.4%)
1 (4.3%) low mild
@aslatter
aslatter / gist:2033379
Created March 14, 2012 02:06
Benchmark before
warming up
estimating clock resolution...
mean is 2.918909 us (320001 iterations)
found 59871 outliers among 319999 samples (18.7%)
51808 (16.2%) low severe
8063 (2.5%) high severe
estimating cost of a clock call...
mean is 80.35574 ns (23 iterations)
found 3 outliers among 23 samples (13.0%)
1 (4.3%) high mild
@aslatter
aslatter / happstack-wai.hs
Created January 26, 2012 04:33
Convert a happstack app to a wai app
{-# LANGUAGE OverloadedStrings #-}
module Happstack.Server.Wai
( toApplication
, run
, Warp.Port
-- ** Low-level functions
, convertRequest
, convertResponse
) where
@aslatter
aslatter / add_disk.md
Created January 26, 2012 01:02
How to add a disk to a live linux VM

Linux, VMs, disks and LVM

This document outlines how to add disk space to a live Linux VM.

Pre-requisites

I wrote this document against Debian Squeeze (testing), but it should be applicable to Ubuntu and other Linuxes. I'll also try to explain the general principles used.

I was running Linux 3.1, but I don't know of anything here that won't work against

@aslatter
aslatter / benchmark.txt
Created January 16, 2012 18:27
Benchmarking blaze-html
./benchmarks/RunHtmlBenchmarks --resamples 10000 -u results.csv
warming up
estimating clock resolution...
mean is 2.825303 us (320001 iterations)
found 78431 outliers among 319999 samples (24.5%)
75607 (23.6%) low severe
2824 (0.9%) high severe
estimating cost of a clock call...
mean is 80.40991 ns (23 iterations)
found 3 outliers among 23 samples (13.0%)
@aslatter
aslatter / XmlKeys.hs
Created December 29, 2011 19:02
Conversion to xml-conduit
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE OverloadedStrings #-}
{-| Given a set of XML documents,
find all unique element names, attributes
and attribute values.
We neglect namespaces in this catalog.
-}
module Main(main) where