Skip to content

Instantly share code, notes, and snippets.

View acowley's full-sized avatar

Anthony Cowley acowley

  • Philadelphia, PA, USA
View GitHub Profile
@acowley
acowley / EmacsHaskellDemo.md
Last active May 18, 2023 17:31
Emacs Haskell Demo Show Notes

Org Editing in haskell-mode

The video opens with a regular Haskell source file in haskell-mode. We start off by adding headings that break the file into meaningful chunks. A section heading is indicated by an asterisk following Haskell single-line comment characters, i.e. -- *. These are top-level headings, sub-headings are indicated by adding more asterisks.

These section markers are given meaning by

@acowley
acowley / flake.nix
Created December 11, 2021 18:05
Nix flake for building Frames-streamly
{
description = "Frames-streamly";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
hls.url = "github:haskell/haskell-language-server";
};
outputs = { self, nixpkgs, flake-utils, hls }:
flake-utils.lib.eachDefaultSystem (system:
{-# LANGUAGE MagicHash, UnboxedTuples #-}
import GHC.Prim
import GHC.Types
main :: IO ()
main = do
xb@(I# x) <- fmap read getLine
case addWordC# 5## (int2Word# x) of
(# res, carryFlag #) ->
putStrLn ("5 + " ++ show xb ++ " = " ++ show (W# res))
@acowley
acowley / PipelineMutation.hs
Created May 20, 2011 05:06
Fused in-place updates of mutable values
{-# OPTIONS -O #-}
-- Perform in-place updates on mutable data.
import Control.Applicative
import Control.Monad
import Data.IORef
import Data.Monoid
import Debug.Trace
import System.IO.Unsafe
-- Presumably we can duplicate the values we want to mutate. Here, we
@acowley
acowley / Main.hs
Created May 22, 2015 00:37
Basic array processing
import Criterion.Main
import qualified Data.Vector.Unboxed as V
go :: V.Vector Int -> Int
go = V.sum . V.filter (< 10) . V.map (+ 5)
main :: IO ()
main = do defaultMain [ bench "mapFilterSum" $ whnf go v ]
putStrLn $ "The answer was " ++ show (go v) ++ ", btw"
where v = V.generate n id
@acowley
acowley / Compiler.hs
Created December 22, 2015 18:17
Use the GHC API to time the type checker
import Control.Arrow ((***))
import Control.Monad (replicateM_)
import Control.Monad.IO.Class
import Data.List (isPrefixOf)
import Data.Time.Clock
import DynFlags (defaultFatalMessager, defaultFlushOut, PkgConfRef(PkgConfFile))
import GHC
import GHC.Paths (libdir)
import System.FilePath (takeBaseName, splitExtension, addExtension)
import Text.Printf
@acowley
acowley / VectorByteString.hs
Created June 7, 2013 16:21
Data.Vector.Storable and Data.ByteString
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Monad ((>=>))
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Unsafe as B
import Data.Vector.Storable (Vector)
import qualified Data.Vector.Storable as V
import Foreign.C.String (CStringLen)
import Foreign.Ptr (castPtr)
import Foreign.Storable (Storable(sizeOf))

Keybase proof

I hereby claim:

  • I am acowley on github.
  • I am acowley (https://keybase.io/acowley) on keybase.
  • I have a public key whose fingerprint is 42A1 A9F7 9A8F 7310 4DE7 6BED A23C 1208 D50A 574B

To claim this, I am signing this object:

@acowley
acowley / CMakeLists.txt
Created October 13, 2017 14:44
Nix packaging of the PCL visualizer demo
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(pcl_visualizer_viewports)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
@acowley
acowley / gd.nix
Created July 15, 2016 03:36
A bump of libgd to 2.2.2 and a cherry-picked patch to fix on Darwin
{ stdenv, fetchurl, fetchpatch, autoreconfHook, perl
, pkgconfig
, zlib
, libpng
, libjpeg ? null
, libwebp ? null
, libtiff ? null
, libXpm ? null
, fontconfig
, freetype