Skip to content

Instantly share code, notes, and snippets.

@getify
getify / 1.js
Last active March 3, 2023 09:23
is Maybe a "monad?
// is Just(..) a monad? Well, it's a monad constructor.
// Its instances are certainly monads.
function Just(v) {
return { map, chain, ap };
function map(fn) {
return Just(fn(v));
}
function chain(fn) {
return fn(v);
}
@imliam
imliam / example.php
Created August 23, 2018 20:17
Define a set of constants to be used as flags for bitmasked options.
<?php
set_bitmask_flags([
'FLAG_1',
'FLAG_2',
'FLAG_3',
'FLAG_4',
'FLAG_5',
]);
@bwinant
bwinant / lifecycle-plugin.js
Created May 7, 2018 09:04
Serverless Plugin Lifecycle Events
'use strict';
// This plugin will bind to all available lifecycle events and print them out as they are invoked
class LifecyclePrinter {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.provider = this.serverless.getProvider('aws');
@schoenkaft
schoenkaft / sphp.sh
Last active April 4, 2018 06:55 — forked from w00fz/sphp.sh
PHP switcher for homebrew/core
#!/bin/bash
# Check if command was ran as root.
if [[ $(id -u) -eq 0 ]]; then
echo "The command \"sphp\" should not be executed as root or via sudo directly."
echo "When a service requires root access, you will be prompted for a password as needed."
exit 1
fi
# Usage
// now an npm package qith 100% code coverage:
// https://github.com/WebReflection/endow#endow---
// (c) Andrea Giammarchi, @WebReflection (ISC)
const mix = Super => ({
with: (...mixins) =>
mixins.reduce(
(Class, Mixin) => {
Class = Mixin(Class);
if (!Mixin.hasOwnProperty(Symbol.hasInstance)) {
@midnightcodr
midnightcodr / main.js
Created December 9, 2017 18:06
node-fetch with retry
const fetch = require('node-fetch')
const delay = (ms) => {
return new Promise(resolve => {
setTimeout(() => {
resolve()
}, ms)
})
}
const retryFetch = (url, fetchOptions={}, retries=3, retryDelay=1000) => {
@schoenkaft
schoenkaft / .profile
Last active April 20, 2017 11:37 — forked from sindresorhus/.profile
Automatic Git signing with gpg/GnuPG 2.1.x on OSX/MacOS
# Set GPG_TTY environment variable
export GPG_TTY=$(tty)
@benlinton
benlinton / multiple_mysql_versions_for_development.md
Last active September 23, 2023 09:38
Multiple MySQL Versions with Homebrew

Multiple MySQL Versions for Development

Options included below:

  • Using Docker docker-compose
  • Using Homebrew brew

Using Docker (recommended)

This gist was originally created for Homebrew before the rise of Docker, yet it may be best to avoid installing mysql via brew any longer. Instead consider adding a barebones docker-compose.yml for each project and run docker-compose up to start each project's mysql service.

@paulirish
paulirish / what-forces-layout.md
Last active May 6, 2024 07:54
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@nolanlawson
nolanlawson / protips.js
Last active February 4, 2024 18:06
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");