Skip to content

Instantly share code, notes, and snippets.

@jrsinclair
jrsinclair / php-full-depth-case-insensitive-file-exists.php
Created July 19, 2013 05:17
PHP Full-depth Case Insensitive file_exists() Function
<?php
/**
* Single level, Case Insensitive File Exists.
*
* Only searches one level deep. Based on
* https://gist.github.com/hubgit/456028
*
* @param string $file The file path to search for.
*
* @return string The path if found, FALSE otherwise.
@jrsinclair
jrsinclair / rsync-examples.sh
Last active February 19, 2016 11:15
Using Rsync over SSH
rsync -rlptuvhz -e ssh username@my-dev-server.dev:/path/to/dir .
# -r Recursive
# -l Copy symlinks as symlinks
# -p Copy permisisons
# -t Copy times
# -u Update. Skip files that are newer on receiving end.
# -v Verbose.
# -h Output numbers in a human-readable format
# -z Use compression when sending data over the network.
@jrsinclair
jrsinclair / fetcher.js
Last active September 15, 2015 23:33
Promise wrapper for using curl with node.
/**
* Fetcher.
*
* This is a simple promise wrapper around a very basic command line curl GET
* request.
*/
"use strict";
/* curl-json-format.txt looks something like the following:
*
import {curry} from 'lodash/fp';
/**
* Chain (flatMap) for Functions.
*
* chainf: (a -> x -> b) -> (x -> a) -> x -> b
*
* @param {Function} g A function that takes two parameters of type a and x.
* @param {Function} h A function that takes one paramter of type x.
* @param {*} x A value of type x.
@jrsinclair
jrsinclair / either.js
Created January 3, 2017 23:25
Lightweight Either Implementation. Mostly ripped off directly from @DrBoolean's Mostly Adequate Guide.
/**
* Lightweight Either Implementation.
* Mostly ripped off directly from @drboolean's Mostly Adequate Guide.
* https://drboolean.gitbooks.io/mostly-adequate-guide/
*/
import {curry} from 'lodash/fp';
export function Left(x) {
this.__value = x;
}
@jrsinclair
jrsinclair / monads.js
Created January 3, 2017 23:51
Lightweight pointfree monad operators. Poor-man's https://github.com/DrBoolean/pointfree-fantasy
/**
* Functions for working with monads.
*
* https://github.com/DrBoolean/pointfree-fantasy is probably a better implementation.
*/
/* eslint prefer-arrow-callback: 0 */
import {curry} from 'lodash/fp';
export const fmap = curry(function fmap(f, m) {
return m.map(f);
import {curry} from 'lodash/fp';
/**
* lift2 (apply) for Functions.
*
* @see http://www.tomharding.me/2017/04/15/functions-as-functors/
*
* Type signature:
* (a -> b -> c) -> (x -> a) -> (x -> b) -> (x -> c)
*
@jrsinclair
jrsinclair / react-example.js
Last active October 29, 2018 02:22
A semi-functional way of thinking about React
import React from 'react';
import compose from 'lodash/fp/compose';
import map from 'lodash/fp/map';
import get from 'lodash/fp/get';
// Curry React.createElement().
const el = elementName => props => children => React.createElement(elementName, props, children);
// Sample HTML element functions
const ul = el('ul');
@jrsinclair
jrsinclair / either-csv-example.csv
Last active December 3, 2018 00:47
Sample CSV Data
timestamp content viewed href
2018-10-27T05:33:34+00:00 @madhatter invited you to tea unread https://example.com/invite/tea/3801
2018-10-26T13:47:12+00:00 @queenofhearts mentioned you in 'Croquet Tournament' discussion viewed https://example.com/discussions/croquet/1168
2018-10-25T03:50:08+00:00 @cheshirecat sent you a grin unread https://example.com/interactions/grin/88
@jrsinclair
jrsinclair / messages.html
Last active December 3, 2018 00:53
Elegant Error Handling Code Samples
<ul class="MessageList">
<li class="Message Message--viewed">
<a href="https://example.com/invite/tea/3801" class="Message-link">@madhatter invited you to tea</a>
<time datetime="2018-10-27T05:33:34+00:00">27 October 2018</time>
<li>
<li class="Message Message--viewed">
<a href="https://example.com/discussions/croquet/1168" class="Message-link">@queenofhearts mentioned you in 'Croquet Tournament' discussion</a>
<time datetime="2018-10-26T13:47:12+00:00">26 October 2018</time>
</li>
<li class="Message Message--viewed">