Skip to content

Instantly share code, notes, and snippets.

@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" ;
@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 / 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 / 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 / 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"
def fuzzyfinder(p, l):
return map(lambda t: t[0], sorted(filter(lambda t: all(map(lambda x: x != -1, t[1])), map(lambda s: (s,map(s.find, p)), l)), key=lambda t: t[1]))
@refi64
refi64 / word.k
Created March 8, 2016 21:44
Surrounds the input words with quotes and puts them (comma-seperated) into 84-column lines
w:0:"/dev/stdin"
`0:(" ",)'{y:"'",y,"', ";:[80<(#y)+#*|x;x,,y;:[#x;(-1_ x),,(*|x),y;,y]]}/(,()),{:[(*|x)~(#*|x)#y;(-1_ x),(,y),(-1#x);x,,y]}/(,()),?w@<w
import re
def myfunc(s):
m = re.match(r'^(.+?)\1+$', s)
return len(s)/len(m.groups()[0])
print(myfunc('abccbaabccba'))
print(myfunc('abcabcabcabc'))
howl.bindings.push
editor:
ctrl_q: (editor) ->
if howl.app.editor.buffer.mode.name == "elm"
howl.command.run 'elm-doc'
else
howl.command.run 'show-doc-at-cursor'
@refi64
refi64 / lcss.css
Created June 7, 2018 22:14
LHTML/LCSS
/*
Major differences from CSS3:
- Only selectors are `.class`, `element`, `*` (as well as multi selectors, e.g. `.a, .b`).
- Only a few properties are supported.
- Styles only define basic looks (so no box model or similar).
- Things like 'initial' and 'inherit' don't exist.
- Styles in <style> tags MUST before the elements with those classes.
*/