Skip to content

Instantly share code, notes, and snippets.

View Maximilianos's full-sized avatar
:shipit:
Shipping

Max G J Panas Maximilianos

:shipit:
Shipping
View GitHub Profile
@Maximilianos
Maximilianos / async-examples.js
Last active May 6, 2017 09:43
Examples of asynchronous patterns to achieve: 1. Parallel requests 2. Print each resolved value as soon as possible 3. Preserve order when printing
/// base functions
const files = {
file1: "first text",
file2: "middle text",
file3: "last text"
};
function readFile(file, success) {
const delay = parseInt(Math.random() * 2000 + 500, 10);
@Maximilianos
Maximilianos / fitIndex.js
Created May 30, 2016 18:39
fit the given number within the available indexes of an array of a given length and overflow around from the end or beginning where appropriate
/**
* Fit a given index into a given array
* length, while properly handling overflow
*
* so for eg:
* - given length=10 & index=3 -> return 3
* - given length=10 & index=14 -> return 4 (overflow)
* - given length=10 & index=-2 -> return 8 (overflow)
*
* @param index
@Maximilianos
Maximilianos / LooseMap.js
Created May 27, 2016 11:08
Basic Spying and Stubbing for functions in JavaScript
import deepEqual from 'deep-equal';
/**
* A basic Map implementation whose keys hold a deep equality
* relationship but not a referential equality relationship
*
*/
export default class LooseMap {
constructor() {
this.__entries__ = [];
@Maximilianos
Maximilianos / curry-example.js
Last active May 8, 2016 23:15
Curry a function in JavaScript
/**
* Curry the given function
*
* @param func {Function} the function to curry
* @param context {Object} (optional) the execution context to
* apply/bind to the returned curried
* function
* @returns {Function}
*/
function curry(func, context = null) {
@Maximilianos
Maximilianos / class-templater.php
Created February 12, 2016 14:51
Register custom page templates in WordPress programmatically in a plugin or in the theme without even requiring real template files.
<?php
/**
*
*/
/**
* Class MCF_Templater
*
* Based on work by Harri Bell-Thomas <https://github.com/HarriBellThomas>
@Maximilianos
Maximilianos / unused-dependencies.js
Created November 10, 2015 16:24
quick script to log packages that are registered in your package.json but not explicitly called in your code
/* eslint-disable */
/**
* Approximately list packages that are
* registered in your package json but
* not used in your code
*
*/
/**
* Kilometers per hour to
* Beaufort scale
*
* @param kmh
* @returns {number}
*/
function kmh2bf(kmh) {
var bf = 0;
var i = 0;
/**
* Error handling helper with builtin debugMode
* toggle
*
* @author: Max GJ Panas <http://maxpanas.com>
* @license: MIT
*
* Based on ideas from Nicholas Zakas expressed in his article:
* http://www.nczonline.net/blog/2009/04/28/javascript-error-handling-anti-pattern/
*/
@Maximilianos
Maximilianos / SunJooTimer.html
Last active December 18, 2015 07:39
A CodePen by Max G J Panas. Sun Joo Timer - Customizable Raphael.js Timer based on a Dribble Shot (http://dribbble.com/shots/1102815-Timer) by Sun Joo (@plios_sun).
<figure class="wrap">
<div class="clock-wrap">
<div class="clock">
<div id="clock_hours"></div>
</div>
<div class="ticker" id="ticker_hours"></div>
</div>
<div class="clock-wrap">
<div class="clock">
<div id="clock_minutes"></div>