Skip to content

Instantly share code, notes, and snippets.

-- Given:
append a [] = a : [] -- 1.1
append a (x:xs) = x : append a xs -- 1.2
last [] = Nothing -- 2.1
last (x : []) = Just x -- 2.2
last (x : xs) = last xs -- 2.3
-- Prove:
@d-akara
d-akara / JavaScriptSafeNavigation.md
Last active April 11, 2024 16:18
JavaScript Safe Navigation

Experimental Safe JavaScript Navigation

Implemented using ES6 Proxies and Symbols

The purpose of this function is to provide a way to avoid deep nested conditionals when traversing a hierarchy of objects. Some languages use an operator such as '?.' to perform this capability. This is sometimes called safe navigation or null conditional operators.

You can somewhat think of this as how a xpath select works. If any nodes along the path are not found, your result is simply not found without throwing an exception and without needing to check each individual node to see if it exists.

Suggestions for improvements welcome!

@mathiasbynens
mathiasbynens / web-platform-status-links.md
Last active July 4, 2024 22:36
Web platform status links
@Avaq
Avaq / combinators.js
Last active July 15, 2024 14:46
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))
@cletusw
cletusw / .eslintrc
Last active February 29, 2024 20:24
ESLint Reset - A starter .eslintrc file that resets all rules to off and includes a description of what each rule does. From here, enable the rules that you care about by changing the 0 to a 1 or 2. 1 means warning (will not affect exit code) and 2 means error (will affect exit code).
{
// http://eslint.org/docs/rules/
"ecmaFeatures": {
"binaryLiterals": false, // enable binary literals
"blockBindings": false, // enable let and const (aka block bindings)
"defaultParams": false, // enable default function parameters
"forOf": false, // enable for-of loops
"generators": false, // enable generators
"objectLiteralComputedProperties": false, // enable computed object literal property names
@rjchatfield
rjchatfield / functors.js
Created February 1, 2015 13:52
Maybe, Either & Try Functors in ES6
//--
//-- FUNCTORS in ES6
//--
//-- BOILER PLATE
let fmap = (f) => (functor) => functor.map(f);
let c2 = (f2, f1) => (x) => f2(f1(x));
let c3 = (f3, f2, f1) => (x) => f3(f2(f1(x)));
// Restify Server CheatSheet.
// More about the API: http://mcavage.me/node-restify/#server-api
// Install restify with npm install restify
// 1.1. Creating a Server.
// http://mcavage.me/node-restify/#Creating-a-Server
var restify = require('restify');
@jashkenas
jashkenas / semantic-pedantic.md
Last active July 13, 2024 04:25
Why Semantic Versioning Isn't

Spurred by recent events (https://news.ycombinator.com/item?id=8244700), this is a quick set of jotted-down thoughts about the state of "Semantic" Versioning, and why we should be fighting the good fight against it.

For a long time in the history of software, version numbers indicated the relative progress and change in a given piece of software. A major release (1.x.x) was major, a minor release (x.1.x) was minor, and a patch release was just a small patch. You could evaluate a given piece of software by name + version, and get a feeling for how far away version 2.0.1 was from version 2.8.0.

But Semantic Versioning (henceforth, SemVer), as specified at http://semver.org/, changes this to prioritize a mechanistic understanding of a codebase over a human one. Any "breaking" change to the software must be accompanied with a new major version number. It's alright for robots, but bad for us.

SemVer tries to compress a huge amount of information — the nature of the change, the percentage of users that wil

@getify
getify / gist:bba5ec0de9d6047b720e
Last active August 29, 2015 14:02
asynquence "reactive sequences" for handling http request/response streams
// Inspired by/adapted from: https://gist.github.com/totherik/4fb1784f008815ac82e1
var http = require("http");
var ASQ = require("asynquence-contrib"); // bring in ASQ + optional contrib plugins
var server, source;
server = http.createServer();
server.setTimeout(30000);
@fabioyamate
fabioyamate / maybe.html
Created May 21, 2014 21:29
Playground for a monad maybe implementation in Javascript
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Snippet</title>
</head>
<body>
<div id="container"></div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore-contrib/0.1.4/underscore-contrib.min.js"></script>