Skip to content

Instantly share code, notes, and snippets.

@nicuveo
nicuveo / Main.hs
Last active November 3, 2022 09:23
Minimalistic JSON parser, using a Parsec-like approach
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Applicative (liftA2)
import Data.Char
import Data.Foldable (for_)
import Data.Functor
import qualified Data.HashMap.Strict as M
import Data.List (intercalate)
import Prelude hiding (any)
@karol-majewski
karol-majewski / flatMap.ts
Last active February 2, 2023 13:48
The simplest flatMap implementation in TypeScript
export function flatMap<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => U[]): U[] {
return Array.prototype.concat(...array.map(callbackfn));
}
@jorgebucaran
jorgebucaran / index.html
Last active July 14, 2020 06:37
Getting started with Hyperapp
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module">
import { h, text, app } from "https://unpkg.com/hyperapp"
app({
init: () => 0,
view: state =>
h("main", {}, [
@gcanti
gcanti / fp-ts-technical-overview.md
Last active March 11, 2024 02:40
fp-ts technical overview

Technical overview

A basic Option type

// Option.ts

// definition
export class None {
  readonly tag: 'None' = 'None'
@vivekhaldar
vivekhaldar / church.js
Created March 4, 2016 21:11
Church numerals in ES6.
//#!/usr/bin/env node --harmony
/*jshint esversion: 6 */
'use strict';
// Church numerals in ES6.
// c.f. https://en.wikipedia.org/wiki/Church_encoding
// Zero is the identity function.
let zero = (f => x => x);
@Avaq
Avaq / combinators.js
Last active March 18, 2024 20:49
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@Integralist
Integralist / 1. TCO description.md
Last active January 20, 2020 13:32
JS Tail Call Optimisation

The problem

If a function calls itself recursively then the JavaScript engine has to create a new 'stack' (i.e. allocate a chunk of memory) to keep track of the function's arguments.

Let's look at an example of this happening:

function sum(x, y) {
    if (y > 0) {
      return sum(x + 1, y - 1);
@t-nissie
t-nissie / HowToGist.md
Last active December 9, 2023 09:44
Gistの使い方のメモ

Gistの使い方のメモ

Gistを使い始めて気がついた点をメモした。 Gistはこのようなメモや短いコードをバージョン管理しながら公開するのに便利。

特にこのメモでは、画像を同一ディレクトリに置いて、 それGFMファイル内に挿入する方法を解説。

このメモにはgitコマンドの使い方の解説はない。 このメモは随時更新される予定。