Skip to content

Instantly share code, notes, and snippets.

View heath's full-sized avatar
❄️
λΠ

heath

❄️
λΠ
View GitHub Profile
@heath
heath / blc.S
Created January 20, 2023 15:38 — forked from jart/blc.S
Binary Lambda Calculus Virtual Machine for x64 Linux in 400 bytes
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2022 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
@heath
heath / running-haskell-scripts.md
Last active May 26, 2020 22:39 — forked from monadplus/running-haskell-scripts.md
Running a haskell script without GHC using nix
#!/usr/bin/env nix-shell
#nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [ mwc-random ])" -i runghc

{-# LANGUAGE ScopedTypeVariables #-}

import System.Random.MWC
import Data.Vector.Unboxed
import Control.Monad.ST
@heath
heath / TestingCFromHaskell.hs
Created February 17, 2020 05:03 — forked from gelisam/TestingCFromHaskell.hs
using Haskell's QuickCheck to property-test C's qsort
-- in response to https://www.reddit.com/r/haskell/comments/duopq8/create_tests_for_other_languages_using_haskell/
-- TLDR: yes, you can test C functions from Haskell; it's a bit painful to
-- call C from Haskell, but once you do, testing is the easy part!
{-# LANGUAGE QuasiQuotes, ScopedTypeVariables, TemplateHaskell #-}
module Main where
import Data.Foldable (for_)
import Data.Traversable (for)
import Foreign.C.Types (CInt, CSize)
@heath
heath / Json.purs
Created February 15, 2020 17:13 — forked from i-am-tom/Json.purs
Parsing, Generating, and Diffing JSON in PureScript
module Main where
-- | JSON is an incredibly simple format. Even its lists are untyped.
-- | As with all languages, functional programming encourages us to
-- | make a domain-specific language (or DSL) to capture the "ideas"
-- | of the language, which we can then use to talk about its content.
-- | In this little snippet, we'll build a JSON DSL, transform it into
-- | a recursive structure, and then use that result to generate some
@heath
heath / Optics Cheatsheet.md
Created January 3, 2020 03:43 — forked from ChrisPenner/Optics Cheatsheet.md
Optics Cheatsheet
fmap :: ... => (a -> b) -> (f a -> f b)
(.) :: (y -> z) -> (x -> y) -> (x -> z)
fmap :: (f2 a -> f2 b) -> (f1 (f2 a) -> f1 (f2 b))
fmap :: (a -> b) -> (f2 a -> f2 b)
(.) :: (y -> z ) -> (x -> y ) -> (x -> z )
(.) :: ((f2 a -> f2 b) -> (f1 (f2 a) -> f1 (f2 b))) -> ((a -> b) -> (f2 a -> f2 b)) -> ((a -> b) -> (f1 (f2 a) -> f1 (f2 a)))
(.) fmap fmap :: (a -> b) -> (f1 (f2 a) -> f1 (f2 b))
^--- (.) fmap fmap = fmap . fmap
@heath
heath / fgrep.md
Last active August 29, 2015 14:16 — forked from dherman/fgrep.md

How Would You Write fgrep?

This is a little style and expressiveness test for various stream libraries. It is certainly not a proof of anything, so much as an ability to showcase how some basic features of streams fit together with different libraries.

Problem statement: given a library of streams, implement an API analogous to fgrep, i.e., a literal string grepper.

Specifically, implement a function fgrep(test, filenames[, limit=10]), which takes a source string, a list of filenames, and an optional concurrency limit, and produces a stream of Match records { filename: string, lineNumber: number, line: string }, representing all lines of all files that contain the string test. For each matching record, filename is the name of the file where the match was found, lineNumber is the one-indexed line number where the match was found, and line is the contents of the line where the match was found.

The limit argument indicates the maximum number of concurrent filehandles that should b

@heath
heath / fun.js
Created May 15, 2014 18:20 — forked from jorendorff/fun.js
// Here is an example of a plain old function that returns a promise.
// Nothing magic about that.
function sleep(sec) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(undefined);
}, sec * 1000);
});
}
angular.module('catalog-diff')
.directive 'scheduleHeatmap', ->
margin =
top: 30
right: 0
bottom: 30
left: 30
# Selenium launcher is a great npm module for booting
# selenium server via a Node.js process.
selenium = require 'selenium-launcher'
soda = require 'soda'
process.env.NODE_ENV = "cucumber"
# This is our app's file.
server = require '../../server'
# We add some empty variables to store the web browser