Skip to content

Instantly share code, notes, and snippets.

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

Stéphan Zych monkeymonk

😶
β+∂(ℤ²-i)ℕ×g³=α!
View GitHub Profile
@monkeymonk
monkeymonk / .htaccess
Created September 27, 2022 12:18 — forked from CurtisL/.htaccess
Better Maintenance Mode .htaccess rules
View .htaccess
# BEGIN MAINTENANCE MODE
# ADD your IP address to gain access. Local IPS for local testing
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.0
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
@monkeymonk
monkeymonk / retry.js
Created March 23, 2022 12:01
Retry n times
View retry.js
/**
* @example
*.try {
* const result = await retry((attempt) => {
* if ( Math.ceil(Math.random() >= .5) ) {
* return 'ok';
* }
*
*. console.log('-> nope');
* throw new Error('Failed after ' + attempt + ' tries');
@monkeymonk
monkeymonk / watch.js
Last active March 16, 2022 14:20
JavaScript Watch helper
View watch.js
/**
* @example
* const item = watch({}, (value, prop, source) => {
* if (prop === 'foo' && !value) {
* return 'default_value';
* }
*
* if (prop === 'baz') {
* return 'nope';
* }
@monkeymonk
monkeymonk / reactivity.js
Created March 16, 2022 13:50
JavaScript reactivity function helper
View reactivity.js
import debounce from 'lodash.debounce';
/**
* @example
* import { reactive, watch } from './reactivity';
*
* const r1 = reactive({ isReady: false })
* const r2 = reactive({ x: 1 })
*
* setTimeout(() => {
@monkeymonk
monkeymonk / tailwind.config.js
Created March 9, 2022 17:34
Tailwind config extended by WordPress theme.json
View tailwind.config.js
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,
@monkeymonk
monkeymonk / snippets.md
Created January 14, 2022 17:50
WP-CLI Usefull commands
View snippets.md
  • 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 / optional.js
Last active March 16, 2022 13:46
JavaScript optional function helper
View optional.js
/**
* 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 / 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/ )
View functions.php
<?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()
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 November 13, 2019 11:00 — 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';