Skip to content

Instantly share code, notes, and snippets.

View rampion's full-sized avatar

Noah Luck Easterly rampion

  • Mercury Technologies
View GitHub Profile
@rampion
rampion / ZipWith.hs
Last active July 8, 2021 03:52
Two implementations of a variadic `zipWith` function, based on inferring the type using either the argument or the return type
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
module ZipWith where
import Control.Applicative (ZipList (..))
import Prelude hiding (zipWith)
@rampion
rampion / LazyLength.hs
Last active May 24, 2021 12:34
The Lazy Length monoid allows you to compare two lists by length without calculating the full length of both lists (unless they are of equal length). Though `lazyLength :: [a] -> LazyLength` is O(n), two `LazyLength` values for lists of length n and m may be compared in time O(min(log n, log m)).
{-# LANGUAGE BangPatterns #-}
module LazyLength (
LazyLength(),
fromLazyLength,
toLazyLength,
lazyLength,
-- QuickCheck properties
prop_invariant,
prop_invertible,
prop_addition,
@rampion
rampion / Lib.hs
Last active May 24, 2021 00:55
ShortestLongest
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wall -Wextra -Werror -Wno-name-shadowing -Wno-unused-top-binds #-}
module Lib
( shortestLongest,
)
where
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall -Werror -Wextra #-}
module Hyperfunction where
import Control.Category
import Data.Function (fix)
import Prelude hiding (id, (.))
extern crate structopt;
use clap::ArgGroup;
use structopt::StructOpt;
#[derive(Debug, StructOpt, PartialEq)]
#[structopt(group(ArgGroup::with_name("confs").multiple(true)))]
pub struct Command {
#[structopt(long = "config", group = "confs", parse(from_str = config))]
configs: Vec<Conf>,
// ==UserScript==
// @name NewScientistViewer
// @namespace http://rampion.myopenid.com
// @description (U) Hide "You have now viewed your 3 free articles" popover from New Scientist.
// @include http://www.newscientist.com/article/*
// ==/UserScript==
// inject script, so hide overlay can use the has library, and runs after the popover happens.
const script = document.createElement('script');
script.type = "text/javascript";
@rampion
rampion / SortAsReverse.hs
Created December 5, 2020 16:15
"Implement the reverse function using the sort function" from https://bindthegap.news/issues/BindTheGap-01Nov2020.pdf
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module SortAsReverse where
-- challenge from bindthegap.news issue 1, Nov 2020
--
-- implement reverse using sort
import Data.Coerce (coerce)
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}

WHAT hey

what ho

  1. What's a recipe?
  2. What's a target?
  3. What's a rule?
  4. What's that `.PHONY` thing?
  5. What's that `.DEFAULT_GOAL` thing?