Skip to content

Instantly share code, notes, and snippets.

Avatar
😶
β+∂(ℤ²-i)ℕ×g³=α!

Stéphan Zych monkeymonk

😶
β+∂(ℤ²-i)ℕ×g³=α!
View GitHub Profile
View sass-explode.scss
// @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 Nov 13, 2019 — forked from ajardin/capture.html
Capture a thumbnail from a video with JavaScript.
View capture.html
<!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 Oct 23, 2019
freezeRecursive method #javascript #es6
View freezeRecursive.js
/**
* 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 Oct 22, 2019
JavaScript Distance Between Coordinates #javascript #map
View distance.js
/**
* 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 Jul 13, 2019
Define unwritable property to the given object.
View definePropertyFreeze.js
/**
* 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 Jul 13, 2019
Memoization helper
View memoize.js
/**
* Memoization helper.
* @param fn
* @param context
* @return Function
*/
export default function memoize(fn, context = null) {
const cache = {};
return (...args) => {
@monkeymonk
monkeymonk / isCallable.js
Created Jul 13, 2019
Return true if the given value is a callable object or function.
View isCallable.js
/**
* Return true if the given value is a callable object or function.
* @param value
*/
export default function isCallable(value) {
if (fn === null || typeof fn === 'number' || typeof fn === 'undefined' || typeof fn.call === 'undefined') {
return false;
}
return true;
View semantic-commit-messages.md

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 Oct 5, 2018 — forked from mynameispj/Props
Estimated reading time in PHP, by Brian Cray
View Props
Total props to Brian Cray: http://briancray.com/posts/estimated-reading-time-web-design/
@monkeymonk
monkeymonk / easing.js
Created Sep 6, 2018 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
View easing.js
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
easeInQuad: function (t) { return t*t },
// decelerating to zero velocity
You can’t perform that action at this time.