Skip to content

Instantly share code, notes, and snippets.

View bgamari's full-sized avatar

Ben Gamari bgamari

View GitHub Profile
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
@bgamari
bgamari / fletcher.cpp
Last active December 10, 2021 08:44
C++11 Fletcher checksum
#include <stdio.h>
#include <stdint.h>
#include <cstring>
#include <type_traits>
constexpr const uint16_t csum(const char* s, size_t n, size_t i, uint16_t sum1, uint16_t sum2) {
return (i <= n) ? csum(s, n, i+1, (sum1 + s[i]) % 255, (sum2 + sum1) % 255) : ((sum2 << 8) | sum1);
}
constexpr const uint16_t operator "" _csum(const char* s, size_t n) {
@bgamari
bgamari / packet-iscsi.nix
Last active September 7, 2020 09:06
A NixOS module for using Packet's iSCSI-based block storage infrastructure.
{ pkgs, config, lib, ... }:
let
packet-block-storage =
pkgs.stdenv.mkDerivation {
name = "packet-block-storage";
src = pkgs.fetchFromGitHub {
owner = "packethost";
repo = "packet-block-storage";
rev = "4be27cbca7a924b4de7af059d5ac30c2aa5c9e6f";
ulimit -n 32000
_build/stage1/bin/ghc -O -threaded -rtsopts EchoServer.hs -debug
./EchoServer +RTS -N4 -s -DS -RTS &
echo 'GET http://localhost:3000/' | nix run nixpkgs.vegeta -c vegeta attack -rate 4000 -body Vagrantfile >out
kill %1
nix run nixpkgs.vegeta -c vegeta report < out
@bgamari
bgamari / default.nix
Last active May 27, 2020 15:04
haskell-nix configuration for cross-compiling Hadolint
let
haskellNixSrc = builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/a823ba4b7126d11ca272ef70b842b0ea5523fcfd.tar.gz;
haskellNix = import haskellNixSrc {};
nixpkgsSrc = haskellNix.sources.nixpkgs-2003;
nixpkgsArgs = haskellNix.nixpkgsArgs;
in
{ pkgs ? (import nixpkgsSrc nixpkgsArgs).pkgsCross.aarch64-multiplatform-musl
}:
let
hspkgs = pkgs.haskell-nix.stackProject {
diff --git a/runstdtest/runstdtest.prl b/runstdtest/runstdtest.prl
index 4ac632f..fb12099 100644
--- a/runstdtest/runstdtest.prl
+++ b/runstdtest/runstdtest.prl
@@ -209,7 +209,7 @@ if ($PostScript ne '') {
# OK, so we're gonna do the normal thing...
if ($Cachegrind eq 'yes') {
- $CachegrindPrefix = "valgrind --tool=cachegrind --log-fd=9 9>$CachegrindStats";
+ $CachegrindPrefix = "valgrind --tool=cachegrind --dsymutil=no --log-fd=9 9>$CachegrindStats";
#include <stdint.h>
#include <fenv.h>
float hs_word2float32_old(uint64_t x) {
return (float)x;
}
float hs_word2float32_new(uint64_t x) {
int r = fegetround();
fesetround(FE_TOWARDZERO);
@bgamari
bgamari / test-ftdi.sh
Created July 18, 2014 15:43
A small script to test the pins of an FTDI JTAG adapter with OpenOCD
#!/bin/bash
cat >ftdi-test.cfg <<EOF
source [find interface/ftdi/dp_busblaster.cfg]
ftdi_layout_signal TCK -data 0x01
ftdi_layout_signal TDI -data 0x02
ftdi_layout_signal TDO -data 0x04
ftdi_layout_signal TMS -data 0x08
transport select jtag
@bgamari
bgamari / demangle-ghc.c
Last active December 28, 2019 02:41
Demangler for GHC's Z encoding
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
/*
* See https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/symbol-names
*/
/*
* Returns number of characters decoded including NULL-terminator or zero if