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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / optional.js
Last active March 16, 2022 13:46
JavaScript optional function helper
/**
* Copy properties from source to target.
* @param target
* @param source
*/
function copyProps(target, source) {
const properties = Object.getOwnPropertyNames(source);
properties
.concat(Object.getOwnPropertySymbols(source))
@monkeymonk
monkeymonk / snippets.md
Created January 14, 2022 17:50
WP-CLI Usefull commands
  • wp rewrite flush - Flush rewrite rules
  • wp media image-size - List registered image sizes
  • wp media regenerate --yes - Regenerate all media
  • wp search-replace https://old.domain.tld https://new.domain.tld - Replace an old domain in database
  • wp db export --add-drop-table - Backup database
  • wp db import backup.sql - Import backup in database
  • wp maintenance-mode activate - Maintenance mode (use wp maintenance-mode deactivate to return to normal)
  • wp rewrite list - Show rootes list
  • wp search-replace "old_post_type" "new_post_type" wp_posts --include-columns="guid,post_type" - Rename post_type (use --dry-run to check what it will do)
@monkeymonk
monkeymonk / tailwind.config.js
Created March 9, 2022 17:34
Tailwind config extended by WordPress theme.json
const fs = require('fs');
const colors = require('tailwindcss/colors');
const themeJson = JSON.parse(fs.readFileSync('./theme.json'));
module.exports = {
theme: {
extend: {
colors: useThemeJSONWith({
// brand
primary: colors.purple,