Skip to content

Instantly share code, notes, and snippets.

View amosr's full-sized avatar

Amos Robinson amosr

View GitHub Profile
@amosr
amosr / split.sh
Last active December 1, 2015 00:52
## $FILES is names of all files to be split
## splits files into two
# find largest file
largest=`ls $FILES -l | sort -k5 -nr | head -n1 | awk '{ print $9 }'`
# count how many lines in it
lines=`wc -l $largest`
@amosr
amosr / merge.c
Last active December 2, 2015 03:44
merging EAVTs
#include <fcntl.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/stat.h>
@amosr
amosr / int.c
Last active December 8, 2015 10:45
SSE int parsing
#include <x86intrin.h>
#include <stdint.h>
#include <stdio.h>
static const uint32_t powers_of_ten_multipliers[]
= { 10000000, 1000000, 100000, 10000
, 1000 , 100 , 10 , 1
, 0 , 0 , 0 , 0
, 0 , 0 , 0 , 0
@amosr
amosr / repl.swift
Created January 28, 2016 07:24
cast :: UnsafeMutablePointer<T> -> UnsafeMutablePointer<U> in Swift?
13> let y : UnsafeMutablePointer<UInt8> = unsafeDowncast(malloc(50))
repl.swift:13:39: error: generic parameter 'T' could not be inferred
let y : UnsafeMutablePointer<UInt8> = unsafeDowncast(malloc(50))
^
Swift.unsafeDowncast:12:13: note: in call to function 'unsafeDowncast'
public func unsafeDowncast<T : AnyObject>(x: AnyObject) -> T
^
13> let y : UnsafeMutablePointer<UInt8> = unsafeDowncast<UnsafeMutablePointer<UInt8>>(malloc(50))
repl.swift:13:39: error: cannot explicitly specialize a generic function
@amosr
amosr / run.sh
Created January 30, 2016 02:30
UInt can't hold (2^63)+1
amos@localhost option-test $ swiftc uint.swift && ./main
2^62 = 4611686018427387904
2^63 - 1 = 9223372036854775807
Illegal instruction
# Running with -Ounchecked gives wrong result.. (last two numbers are same)
amos@localhost option-test $ swiftc tx1-uint.swift -Ounchecked && ./main
2^62 = 4611686018427387904
2^63 - 1 = 9223372036854775807
2^63 = 9223372036854775807
@amosr
amosr / fusion.md
Last active March 13, 2016 04:34
Icicle lambda jam abstract(s)

Icicle: write once, run once

When dealing large data sets that do not fit in memory, it is crucial to limit the number of accesses and iterations over the data set. However, in a high level language it may not be immediately obvious how many iterations a particular program will require. The number of iterations becomes even less obvious in the presence of heuristic and statistics-based optimisations, as used by traditional databases: a small tweak to the query or even modifying the number of rows in a table can cause drastic changes to the query plan.

@amosr
amosr / bonkers.hs
Created April 1, 2016 01:01
Type families error that I don't understand
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeFamilies #-}
class Bonkers b where
type Bonkers1 b :: *
type Bonkers2 b :: *
bonkersFrom :: Bonkers1 b -> Bonkers2 b
bonkers' :: Bonkers b => Bonkers1 b -> Bonkers2 b
@amosr
amosr / sums.c
Last active May 3, 2016 23:13
No global value numbering / duplicate removal
#include <stdio.h>
void b01_sums(int size, int* A)
{
int sum0 = 0;
int sum1 = 0;
for (int i = 0; i != size; ++i)
{
sum0 = sum0 + A[i];
sum1 = sum1 + A[i];
@amosr
amosr / lucy.sh
Last active May 24, 2016 08:17
Installing and running Lucid Synchrone (Lucy)
#!/bin/sh -eu
# The version of Lucid Synchrone / Lucy on the website was built a long time ago, and only has bytecode available.
# It seems that between ocaml 4.00.1 and 4.00.2, the bytecode format changed,
# so you need to use that version.
# This should:
# install the right version of the compiler (assuming you have opam);
# download lucy;
# change the shebang of the binaries to point to the right version;
# and put lucyc in /usr/local/bin.
@amosr
amosr / THStuff.hs
Created September 2, 2016 00:31
Template Haskell reify does not return declaration
-- Template haskell parts need to be in separate module, because of staging restriction.
-- Use GHC 8, since the VarI constructor changed between 7 and 8.
{-# LANGUAGE TemplateHaskell #-}
module THStuff where
import Language.Haskell.TH
-- Try to convert a name into its definition.
-- This would be really useful for forcing definitions to be inlined into a particular callsite.
get :: Name -> Q Exp
get nm = do