Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / partition.ts
Last active May 25, 2023 13:47
Typescript functions to share
/**
* Separate a list into two lists (left and right) using a predicate to detect
* items that should be in the left list. The rest go into the right list.
*
* @param isLeft - predicate to detect items that should be in the left list
*
* @returns a function that accepts an array and returns a pair of arrays
*
* @todo - return type [ L[], R[] ] instead of ambiguous type.
*/
@unscriptable
unscriptable / .gitignore
Last active April 21, 2023 18:53
Most + redis + docker
node_modules
.DS_Store
@unscriptable
unscriptable / Makefile
Last active February 12, 2019 15:19
Makefile to compile Elm in a container
# NOTE will not work with make -v 3.81 or lower
SHELL = /bin/bash
.RECIPEPREFIX = >
# run docker as current user so we don't get elm-stuff permissions problems
UID ?= $(shell id -u):$(shell id -g)
GIT_REPO_ROOT ?= $(PWD)
PROJECT_ROOT := $(GIT_REPO_ROOT)
@unscriptable
unscriptable / README.md
Last active February 12, 2024 00:32
Datalist polyfill

Polyfill for the datalist element and list attribute for Safari on macOS

@unscriptable
unscriptable / .gitignore
Last active July 31, 2017 18:37
Creates a most.js UMD module with creed's ultra-fast Promise implementation packaged in as the Promise shim.
node_modules/
@unscriptable
unscriptable / papply.js
Created January 30, 2017 20:31
Function to partially apply function args even if the function might be "manually curried".
export const papply =
(f, ...x) => {
const arity = f.length
const args = x.length
// shortcut no-ops for perf
if (args === arity) return f(...x)
if (args === 0) return f
if (args < arity) {
// Classic array unfold that works with functions that produce
// reasonably-sized output arrays.
export const unfoldWith =
f => x =>
_unfold(f, [], x)
// Recursive unfold function. Will overflow stack for very, very large unfolds.
// f should return null, if done, or return [ curr, next ] values, if not.
const _unfold =
(f, acc, value) => {
@unscriptable
unscriptable / template.js
Last active February 12, 2024 00:33
Mostly for fun, I created a simple template function using functional JavaScript patterns and ES6 syntax. Kinda like mustache, but much simpler.
// Take a text string containing tokens (of type `${name}`) and return
// a function that will replace the tokens with the properties of a given
// object. If we need to get much more sophisticated, we should
// probably use mustache or similar.
// TODO: allow dev to specify a format for each token?
export default
template => createRenderAll(partition(String(template)))
// ------------------------------------------------------------
@unscriptable
unscriptable / sendSms-ioc.js
Created October 21, 2016 15:28
Code snippet used in an IoC blog post
import _ from "lodash"
export const smsMessage = (template, isValidPhone) => {
const createMessage = _.template(template)
const validate = throwIfInvalidPhone(isValidPhone)
return _.compose(validate, createMessage)
}
const throwIfInvalidPhone = isValidPhone => user => {
@unscriptable
unscriptable / sendSms-traditional.js
Created October 21, 2016 15:27
Code snippet used in an IoC blog post
import _ from "lodash"
import { isValidPhone } from "../validation/phone"
import template from "./template"
import { DbConn } from "../Db"
import SmsService from "../SmsService"
const createMessage = _.template(template)
export const sendSms = userId => {
const service = new SmsService()
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy