Skip to content

Instantly share code, notes, and snippets.

View ElectricCoffee's full-sized avatar

Niko Lepka ElectricCoffee

View GitHub Profile
@ElectricCoffee
ElectricCoffee / dice.ijs
Last active April 17, 2024 06:49
A simple script to find the percentage chance of rolling a pair on N dice.
NB. Preliminary research
die =. 1 + i. 6
solution_1 =. ,(2 = #@~.)"1 (,"0 1/ ,"0/~)~ die NB. this solution assembles a matrix
solution_2 =. _3 (2 = #@~.)\ ; { 3 $ < die NB. this solution uses the catalogue function to create a table of boxes
solution_3 =. (2 = #@~.)"1 (#: i.@(*/)) 3 $ 6 NB. this solution was provided by elcaro
calc_pct =. 100 * # %~ +/ NB. chained forks are one hell of a drug
NB. Implemented solution
import _ from 'lodash';
import Fn from './functools';
it('ignores all inputs', () => {
const actual = Fn.nop(800, 'hello there', []);
expect(actual).toBeUndefined();
});
it('only returns the constant', () => {
const fn = Fn.constant(8);
@ElectricCoffee
ElectricCoffee / README.md
Last active January 11, 2023 10:25
A fix for icehousegames.org to fix the missing font.

To use this script you must download two things:

  1. A userscript manager
  • Firefox: Install Greasemonkey
  • Chrome: Install Tampermonkey
  1. The Pyramid Love font: https://seagullincident.com/pyramidlove/

First, install the font; then click on the {grease,tamper}monkey icon and click "new user script". Copy the code in the other file and paste it in.

@ElectricCoffee
ElectricCoffee / fiesta-caldera.js
Last active December 20, 2022 12:59
A layout generator for Fiesta Caldera. Simulates dice rolls to see if setting up with dice is viable. (it is).
const MIN_X = 0;
const MAX_X = 4;
const MIN_Y = 0;
const MAX_Y = 4;
const MAX_VAL = 8;
const mat = Array.from(Array(5), () => Array(5).fill(MAX_VAL));
const supply = Array(8).fill(3);
@ElectricCoffee
ElectricCoffee / advent-of-code-day-5.apl
Last active December 7, 2022 20:58
My solution for the Advent of Code day 5 problem in APL
Solution ← {¯1+⍺+⍺⍳⍨≢¨⍺ ∪/⍵}
⍝ Or with ⎕io ← 0:
Solution ← {⍺+⍺⍳⍨≢¨⍺ ∪/⍵}
#!/usr/bin/env perl
use 5.30.0;
use warnings;
use Cwd 'getcwd';
use File::Basename;
my $dir = getcwd;
my ($name) = File::Basename::fileparse($dir);
import { useState } from "react";
/**
* Creates a specialised `useState` which includes mutators in its definition.
* The returned object includes a `get()` method and a `set(x)` method by default.
* @param init The default value
* @param mutators an object containing the mutator functions
* @example
* ```
* const counter = useTilstand(0, {
@ElectricCoffee
ElectricCoffee / carnac.gdl
Created September 29, 2022 12:36
an idea for a 'game description language' for board games inspired by the Plain English programming language
name: Carnac
players: 2
components:
- 28 megaliths
- 3 boards
board sizes: small, medium, and large.
player actions are: proceed and skip.
@ElectricCoffee
ElectricCoffee / loop.rkt
Created September 21, 2022 09:18
A simple loop implementation which makes use of `continue` and `break`, which works as you'd expect. All using the power of continuations!
#lang racket
(define LOOP/CC (box '()))
(define BREAK/CC (box '()))
(define (continue)
(let ((loop/cc (unbox LOOP/CC)))
(loop/cc loop/cc)))
(define (break)
@ElectricCoffee
ElectricCoffee / maybe.ts
Created September 20, 2022 08:04
Maybe monad in TypeScript
export class Maybe<A> {
readonly kind: "Just" | "Nothing";
value?: A;
private constructor(kind: "Just" | "Nothing", value?: A) {
this.kind = kind;
this.value = value;
}
static readonly just = <A>(value: A): Maybe<A> => new Maybe("Just", value);