Skip to content

Instantly share code, notes, and snippets.

View martin-sweeny's full-sized avatar
💢

◢◤◢◤ martin-sweeny

💢
View GitHub Profile
/**
* @typedef {TimeUnitTuple[]} TimeUnitTable A table of time units (seconds, minutes, for example), with their corresponding multipliers compared to the last value. The order is important, as each tuple contains a `multiplier`, which is how many times the last value would fit into this one (i.e. there are 60 minutes in an hour, so hour would be [60, 'hours'])
* @typedef {[multiplier: number, label: string]} TimeUnitTuple Intended to be used in an array of the same type, where the `multiplier` represents how many times this unit fits into the last, and `label` is the name of that unit (for example, days)
*/
/**
* Returns the absolute difference between two date objects
* @curried
* @param {(number | Date)} date1
* @returns {(date2?: number | Date) => number} The difference in milliseconds
@martin-sweeny
martin-sweeny / keybase.md
Created October 18, 2020 02:27
keybase.md

Keybase proof

I hereby claim:

  • I am martin-sweeny on github.
  • I am martinsweeny (https://keybase.io/martinsweeny) on keybase.
  • I have a public key ASB7-jdpjRLetRQwrEqEqXM8irnwCBMYQFGus-Z_4GoP3go

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am martin-sweeny on github.
  • I am martinsweeny (https://keybase.io/martinsweeny) on keybase.
  • I have a public key whose fingerprint is 1F70 9F7B 5B18 EE4A 8960 281E FC4D F957 A3C9 CB5C

To claim this, I am signing this object:

@martin-sweeny
martin-sweeny / keybase.md
Created November 19, 2018 21:14
Keybase Proof

Keybase proof

I hereby claim:

  • I am martin-sweeny on github.
  • I am martin_wiseweb (https://keybase.io/martin_wiseweb) on keybase.
  • I have a public key ASCss-qCBeQ1pqXrmirf1YdOGFZ3AlMfB6FX72AnfwxOCwo

To claim this, I am signing this object:

@martin-sweeny
martin-sweeny / async-fun.js
Created January 13, 2018 14:01
Playing with async/await
timed = async i => new Promise(resolve => {
console.log(`starting ${i}`)
setTimeout(() => {
resolve('done!');
console.log('yo', i)
}, Math.random() * 5000)
});
parallel = async count => {
timers = [], msgs = [], indeces = [], start = count;

Keybase proof

I hereby claim:

  • I am martin-wiseweb on github.
  • I am martin_wiseweb (https://keybase.io/martin_wiseweb) on keybase.
  • I have a public key ASCmHrOA_f3VZo03WyK8764No_hNiKv2fRpeFVnShigBTwo

To claim this, I am signing this object:

@martin-sweeny
martin-sweeny / gist:c66cf1acd92e91949b8d3ad65c889ec9
Created February 9, 2017 05:02 — forked from belsrc/gist:672b75d1f89a9a5c192c
Simple Vue.js filters that I usually need
/**
* Changes value to past tense.
* Simple filter does not support irregular verbs such as eat-ate, fly-flew, etc.
* http://jsfiddle.net/bryan_k/0xczme2r/
*
* @param {String} value The value string.
*/
Vue.filter('past-tense', function(value) {
// Slightly follows http://www.oxforddictionaries.com/us/words/verb-tenses-adding-ed-and-ing
var vowels = ['a', 'e', 'i', 'o', 'u'];
/**
* Example Singleton constructor.
* I wish this was extendable but you gotta copy/paste the 2 lines into any object you want to be a Singleton
*
* @returns {*}
* @constructor
*/
function Singleton () {
if ( arguments.callee._singletonInstance ) return arguments.callee._singletonInstance;
arguments.callee._singletonInstance = this;
@martin-sweeny
martin-sweeny / jquery.countup.js
Created May 8, 2016 03:40
A miniscule plugin to allow an element to "count up" to a number
$.fn.countUp = function(timing) {
var max = parseInt(this.text());
if ( !max ) return false;
var i = 0;
var $this = this;
var delay = timing / max ;
var intv = setInterval(function() {
$this.text(i);
if (i === max) return clearInterval(intv);
i++;