Skip to content

Instantly share code, notes, and snippets.

@refi64
refi64 / haskell.hs
Created May 14, 2015 21:35
Haskell version of "Four MLs (and a Python)"
import Control.Applicative
import System.Environment
import Data.List.Split
import Data.List
-- the ":: [Float]" prevents the type inferencer from going haywire
addTo [] v = v :: [Float]
addTo t v
| length t == length v = zipWith (+) t v
| otherwise = error "Inconsistent-length rows"
@refi64
refi64 / felix.flx
Last active August 29, 2015 14:21
Felix entry for "Four MLs (and a Python)"
fun add_to(totals: list[float])(values: list[float]) =>
if values.len != 1.size then let n = totals.len in match n with
| 0uz => values
| $(values.len) => (add of (float^2)).map $ totals.zip2 values
// this ugliness is because of a bug in Felix that generates invalid C++ code
// see https://github.com/felix-lang/felix/issues/71
| _ => #(fun () = { raise "Inconsistent-length rows"; return #list[float]; })
endmatch else totals;
fun add_line_to(totals: list[float])(line: string) =>
@refi64
refi64 / ln
Last active August 29, 2015 14:20
Hy line number solver
#!/bin/sh
if [ -z "$1" ] || [ -z "$2" ]; then
echo "usage: $0 <file> <line>"
exit 1
fi
line=`expr $2 - \( $2 / 256 \* 256 \) + \( $(wc -l < $1) / 256 \* 256 \)`
echo "$line: `sed ${line}q\;d $1 | sed 's/^[ \t]*//;s/[ \t]*$//'`"
@refi64
refi64 / c++-string-bench.cpp
Created March 6, 2015 22:22
C++ string implode benchmark
/*
This is a simple benchmark of the C++ string implode algorithms as stated at
http://stackoverflow.com/questions/5689003/
how-to-implode-a-vector-of-strings-into-a-string-the-elegant-way.
This uses Celero.
Results on my machine, compiling with Clang SVN and -O3:
[==========]
[ CELERO ]
@refi64
refi64 / Jamroot
Created February 12, 2015 20:49
AsmJit build system with Boost.Build
import option ;
import package ;
import regex ;
local embed = [ option.get embed : 0 ] ;
local xprops = ;
if embed in 1 true yes {
xprops = "<link>static" ;