Skip to content

Instantly share code, notes, and snippets.

View Arkham's full-sized avatar
🏠
Working from home

Ju Liu Arkham

🏠
Working from home
View GitHub Profile
@Arkham
Arkham / kata.rb
Last active November 24, 2023 14:33
a functional altermative
# generate 100 random integers and store them in a file
STORE = "numbers.txt"
unless File.exists?(STORE)
File.write(STORE, 100.times.map { Random.rand(10) }.join("\n"))
end
numbers = File.read(STORE).split("\n").map { |n| n.to_i }
@Arkham
Arkham / 12-wasm.rs
Created December 13, 2022 22:00
aoc day 12 wasm fun
pub fn part_one(input: &str) -> Option<(Vec<Coords>, usize)> {
let board = Board::from(input);
run_dijkstra(
&[board.start],
|node| board.successors(node),
|node| node == &board.end,
)
}
@Arkham
Arkham / default.nix
Last active September 20, 2021 18:12
{ }:
let
sources = import nix/sources.nix { };
pkgs = import sources.nixpkgs { };
darwinInputs = with pkgs;
lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
AppKit
CoreFoundation
let
sources = import ./nix/sources.nix { };
nixpkgs = import sources.nixpkgs { };
nixpkgs-ruby267 = import sources.nixpkgs-ruby267 { };
in nixpkgs.mkShell {
buildInputs = [
nixpkgs.go
nixpkgs-ruby267.ruby_2_6
];
}
@Arkham
Arkham / MonadTrans.hs
Created April 19, 2021 13:45
A Monad Transformer tutorial
module MonadTrans where
import Control.Applicative (empty)
import Control.Monad (guard, join)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Identity (IdentityT (..), runIdentityT)
import Control.Monad.Trans.Maybe (MaybeT (..))
import Control.Monad.Trans.Reader (Reader, ReaderT (..), ask)
import Data.List (intercalate)
import qualified Data.Map.Lazy as M
module Robot where
robot (name, attack, hp) = \message -> message (name, attack, hp)
name (n, _, _) = n
attack (_, a, _) = a
hp (_, _, hp) = hp
@Arkham
Arkham / recap.md
Created September 17, 2018 15:25
LambdUp recap

🏰 LambdUp Conf Prague

Philip Wadler - Categories for the Working Hacker

Product

type alias Person =

@Arkham
Arkham / recap.md
Created September 17, 2018 15:25
LambdUp recap

🏰 LambdUp Conf Prague

Philip Wadler - Categories for the Working Hacker

Product

type alias Person =

Lambda Calculus 🔬

A formal system for expressing computation in terms of function abstraction and application using variable binding and substitution

Invented in the 1930s by Alonzo Church. He was pals with Turing. Unsurprisingly, any problem which can be solved with a Turing machine can be solved with lambda calculus. Check out the aptly named Church-Turing thesis!

What is a function

f(1) = A

@Arkham
Arkham / phantom.elm
Created February 26, 2018 20:19
Example of phantom type in Elm
module Main exposing (main)
import Html exposing (Html, text)
type Distance a
= Distance Float
type Kilometer