Skip to content

Instantly share code, notes, and snippets.

@timhwang21
timhwang21 / curry-record.md
Last active January 9, 2023 21:34
Curry unary functions that take a record as an argument

curryRecord

This is an example of a function whose logic lives in the type definition rather than in the function body.

/**
 * @name `curryRecord`
 *
 * Takes a unary function that takes a record as an argument, and makes the
 * record partially applicable. Returns a new function that takes a partial of
@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))
@mmacedo
mmacedo / source.fish
Last active August 9, 2017 04:49
Source bash/zsh/ksh files
function _exec_with
set -l shell $argv[1]
set -l file $argv[2]
set -l code $argv[3]
set -l source
switch "$shell"
case bash zsh ksh
set source .
case '*'
@tcr
tcr / gist:4416956
Last active November 29, 2017 03:38
Make a callable() object in all browsers and Node.js
if (!Object.__proto__) {
var sandbox = function () {
// create an <iframe>
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.documentElement.appendChild(iframe);
return frames[frames.length - 1];
}
var iframe = sandbox();
@kaleb
kaleb / XDG.vim
Last active January 17, 2022 23:16
VIM XDG Configuration
" XDG Environment For VIM
" =======================
"
" References
" ----------
"
" - http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
" - http://tlvince.com/vim-respect-xdg
"
if empty($XDG_CACHE_HOME)
@jamescasbon
jamescasbon / template.py
Created December 11, 2011 16:37
Pure python templates using with statement
"""
A really stupid python template language inspired by coffeekup, markaby.
Do not use this code, it will ruin your day. A byproduct of insomnia.
TL;DR
-----
This module defines a template language that allows us to do:
d = Doc()
anonymous
anonymous / Prelude.cs
Created July 16, 2011 21:36
Oh, you poor, poor imperative developers...
/* Prelude.cs : What happens when a haskell programmer learns C#.
Copyright (c) 2011 Clark Gaebel
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
@fcalderan
fcalderan / inception-javascript.js
Created November 2, 2010 09:42
inception explained as a 4 nested javascript closures
/*
* Fabrizio Calderan, twitter @fcalderan, 2010.11.02
* I had an idea: could Inception movie be explained by a few javascript closures
* and variable resolution scope (just for fun)?
*
* Activate javascript console =)
*/
<script>
console.group("inception movie");