Skip to content

Instantly share code, notes, and snippets.

View evanrelf's full-sized avatar

Evan Relf evanrelf

View GitHub Profile
-- Semigroup
(<|^.^|>) :: Semigroup a => a -> a -> a
(<|^.^|>) = (<>)
infixr 6 <|^.^|>
-- Functor
(<|$.$|>) :: Functor f => (a -> b) -> f a -> f b
(<|$.$|>) = (<$>)
let
pkgs = import <nixpkgs> { };
in
pkgs.writeShellScript "doi" ''
cat <<EOF
When in the Course of human events it becomes necessary for one people to
dissolve the political bands which have connected them with another and to
assume among the powers of the earth, the separate and equal station to which
the Laws of Nature and of Nature's God entitle them, a decent respect to the
#!/usr/bin/env nix-shell
#!nix-shell --packages youtube-dl ffmpeg moreutils -i bash
# shellcheck shell=bash
set -euo pipefail
main() {
if [ ! -d ~/.local/share/monty-python ]; then
echo "Creating directory '~/.local/share/monty-python'" >&2
@evanrelf
evanrelf / fundeps.hs
Last active March 11, 2022 02:31
Conflicting instances
-- error:
-- Functional dependencies conflict between instance declarations:
-- instance Exception e => ToError e Error
-- instance Exception e => ToError (Either e a) (Either Error a)
data Error = Error
deriving stock Show
deriving anyclass Exception
class ToError i o | i -> o where
use std::{
any::{Any, TypeId},
collections::HashMap,
};
#[derive(Default)]
pub struct TypeMap {
hash_map: HashMap<TypeId, Box<dyn Any>>,
}
{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -Wcompat #-}
{-# OPTIONS_GHC -Werror=incomplete-record-updates #-}
{-# OPTIONS_GHC -Werror=incomplete-uni-patterns #-}
{-# OPTIONS_GHC -Werror=missing-fields #-}
{-# OPTIONS_GHC -Werror=partial-fields #-}
{-# OPTIONS_GHC -Widentities #-}
{-# OPTIONS_GHC -Wmissing-home-modules #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC -Wall #-}
module Cont where
import Control.Monad.Trans.Cont (Cont, runCont)
data Tree a
@evanrelf
evanrelf / shell.nix
Created August 1, 2022 19:31
Example Nix shell providing Cabal and GHC
let
nixpkgs = builtins.fetchGit {
url = "https://github.com/NixOS/nixpkgs.git";
rev = "6f643a1098b30b060e7f719f84c8a7f9677d1c36";
};
pkgs = import nixpkgs { };
in
pkgs.mkShell {
@evanrelf
evanrelf / README.md
Last active August 16, 2022 02:53
React hello world
  1. Create a directory and cd into it

  2. Copy index.html and main.js into the directory

  3. Run this command to start a web server

    python3 -m http.server 8080
const fib = n => n == 0 ? 0 : n == 1 ? 1 : fib(n - 2) + fib(n - 1);
const fibs = [...Array(10).keys()].map(fib);
console.log(fibs);