Skip to content

Instantly share code, notes, and snippets.

View monkeymonk's full-sized avatar
😶
β+∂(ℤ²-i)ℕ×g³=α!

Stéphan Zych monkeymonk

😶
β+∂(ℤ²-i)ℕ×g³=α!
View GitHub Profile
@monkeymonk
monkeymonk / functions.php
Created September 23, 2021 09:20 — forked from tripflex/functions.php
WordPress Recursively get taxonomy hierarchy (courtesy of http://www.daggerhart.com/wordpress-get-taxonomy-hierarchy-including-children/ )
<?php
/**
* Recursively get taxonomy hierarchy
*
* @source http://www.daggerhart.com/wordpress-get-taxonomy-hierarchy-including-children/
* @param string $taxonomy
* @param int $parent - parent term id
*
* @return array
@monkeymonk
monkeymonk / sass-explode.scss
Created November 5, 2020 12:41 — forked from danielpchen/sass-explode.scss
Sass explode()
// @function explode() -- split a string into a list of strings
// {string} $string: the string to be split
// {string} $delimiter: the boundary string
// @return {list} the result list
@function explode($string, $delimiter) {
$result: ();
@if $delimiter == "" {
@for $i from 1 through str-length($string) {
$result: append($result, str-slice($string, $i, $i));
}
@monkeymonk
monkeymonk / capture.html
Created November 13, 2019 11:00 — forked from ajardin/capture.html
Capture a thumbnail from a video with JavaScript.
<!DOCTYPE html>
<head>
<script type='text/javascript'>
window.onload = function () {
var video = document.getElementById('videoId');
var canvas = document.getElementById('canvasId');
var img = document.getElementById('imgId');
video.addEventListener('play', function () {
canvas.style.display = 'none';
@monkeymonk
monkeymonk / freezeRecursive.js
Created October 23, 2019 22:48
freezeRecursive method #javascript #es6
/**
* Freeze given value recursively if needed.
* @param obj
* @return {*}
*/
export default function freezeRecursive(obj) {
Object.freeze(obj);
if (obj === undefined) {
return obj;
@monkeymonk
monkeymonk / distance.js
Last active October 22, 2019 08:33
JavaScript Distance Between Coordinates #javascript #map
/**
* Returns the distance bewteen 2 coordinates.
* @param {Object} from - Object with lat and lng
* @param {Object} to - Object with lat and lng
* @return {float}
*/
function distance(from, to) {
const {atan2, cos, sqrt, sin} = Math;
// @note - radius of the planet earth in meters
const R = 6378137;
@monkeymonk
monkeymonk / definePropertyFreeze.js
Last active July 13, 2019 20:11
Define unwritable property to the given object.
/**
* Define unwritable property to the given object.
* @example
* var test = {};
* test = definePropertyFreeze(test, 'foo', 'bar');
* test = definePropertyFreeze(test, 'baz', {bat: 'bral'});
* test = definePropertyFreeze(test, 'bot', [1, 2]);
* // then
* test.bat = 'ok'; // works
* test.foo = 'nok'; // not working, test.foo return 'bar'
@monkeymonk
monkeymonk / memoize.js
Created July 13, 2019 18:38
Memoization helper
/**
* Memoization helper.
* @param fn
* @param context
* @return Function
*/
export default function memoize(fn, context = null) {
const cache = {};
return (...args) => {
@monkeymonk
monkeymonk / isCallable.js
Last active April 15, 2021 08:11
Return true if the given value is a callable object or function.
/**
* Return true if the given value is a callable object or function.
* @param value
*/
export default function isCallable(value) {
if (value === null || typeof value === 'number' || typeof value === 'undefined' || typeof value.call === 'undefined') {
return false;
}
return true;

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@monkeymonk
monkeymonk / Props
Created October 5, 2018 10:05 — forked from mynameispj/Props
Estimated reading time in PHP, by Brian Cray
Total props to Brian Cray: http://briancray.com/posts/estimated-reading-time-web-design/