Skip to content

Instantly share code, notes, and snippets.

@hildjj
hildjj / tagged-vector-adder.pegjs
Last active December 3, 2023 20:08 — forked from frostburn/tagged-vector-adder.pegjs
Peggy proposition: Tagged template parser with auto-vectorization of template arguments
import peg from "peggy-tag";
const PLACEHOLDER = "{{{ARG}}}";
const parse = peg`
{{
function add(left, right) {
if (typeof left === 'number') {
if (typeof right === 'number') {
return left + right;
@rntz
rntz / inlining-tagless-final.ml
Last active February 15, 2022 16:23
A simple inlining pass in tagless-final style.
(* Inlining for the λ-calculus, implemented in tagless final style. This seems
* like it _must_ be related to Normalization By Evaluation (see eg [1,2]),
* since they both amount to β-reduction (plus η-expansion in extensional NBE),
* and the techniques have a similar "flavor", but I don't immediately see a
* formal connection.
*
* [1] https://gist.github.com/rntz/f2f15f6cb4b8690c3599119225a57d33
* [2] http://homepages.inf.ed.ac.uk/slindley/nbe/nbe-cambridge2016.pdf
*)
@rxwei
rxwei / ad-manifesto.md
Last active November 9, 2023 09:58
First-Class Automatic Differentiation in Swift: A Manifesto
@font-face {
font-family: SegoeUI;
src:
local("Segoe UI Light"),
url(//c.s-microsoft.com/static/fonts/segoe-ui/west-european/light/latest.woff2) format("woff2"),
url(//c.s-microsoft.com/static/fonts/segoe-ui/west-european/light/latest.woff) format("woff"),
url(//c.s-microsoft.com/static/fonts/segoe-ui/west-european/light/latest.ttf) format("truetype");
font-weight: 100;
}
// Adapted from http://lukajcb.github.io/blog/functional/2018/01/03/optimizing-tagless-final.html
import { Applicative, Applicative1 } from 'fp-ts/lib/Applicative'
import { Apply, Apply1, Apply2C, applySecond, liftA4 } from 'fp-ts/lib/Apply'
import * as array from 'fp-ts/lib/Array'
import * as const_ from 'fp-ts/lib/Const'
import { HKT, Type, Type2, URIS, URIS2 } from 'fp-ts/lib/HKT'
import { IO, io, URI as IOURI } from 'fp-ts/lib/IO'
import { Option, some } from 'fp-ts/lib/Option'
import { getProductSemigroup, Semigroup } from 'fp-ts/lib/Semigroup'
@antirez
antirez / lmdb.tcl
Created April 28, 2017 15:40
LMDB -- First version of Redis written in Tcl
# LVDB - LLOOGG Memory DB
# Copyriht (C) 2009 Salvatore Sanfilippo <antirez@gmail.com>
# All Rights Reserved
# TODO
# - cron with cleanup of timedout clients, automatic dump
# - the dump should use array startsearch to write it line by line
# and may just use gets to read element by element and load the whole state.
# - 'help','stopserver','saveandstopserver','save','load','reset','keys' commands.
# - ttl with milliseconds resolution 'ttl a 1000'. Check ttl in dump!
@JohnEarnest
JohnEarnest / peg.js
Created March 31, 2017 03:05
A compact set of PEG parser combinators in ES6.
// PEG parser combinators
const lookup = x => typeof x == 'string' ? eval(x) : x
const match = (x, y, z) => x ? { c:y, v:z } : { e: true }
const eof = s => match(s.length, 0, '')
const char = s => match(s.length, 1, s[0])
const not = g => s => match(g(s).e, 0, '')
const has = g => s => match(!g(s).e, 0, '')
const oneof = t => s => match(t.indexOf(s[0]) >= 0, 1, s[0])
const lit = t => s => match(!s.indexOf(t), t.length, t)
const option = g => choose(g, lit(''))
@krstffr
krstffr / debounced-redux-thunk-action.js
Created December 16, 2016 12:04
Debouncing redux thunk actions.
// A common redux pattern when dealing with async functions is to use thunk.
// This usually means your action returns a new function instead of an action object,
// and the thunk middleware will make it all work. Example:
const asyncAction = () => dispatch => setTimeout(() => dispatch(someOtherAction()), 10000);
// Now: maybe that async stuff going on is calling some API which you don't want to overload
// with request, and that's what debounce is for.
// This is an example of a debounced function which will only be calleable once every second.
import { debounce } from 'lodash';
const debouncedFn = debounce(() => callApi(), 1000, { leading: true, trailing: false });
@wavezhang
wavezhang / java_download.sh
Last active April 29, 2024 14:42
download java from oracle without login
wget -c --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/12.0.2+10/e482c34c86bd4bf8b56c0b35558996b9/jdk-12.0.2_linux-x64_bin.tar.gz

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x