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 Sep 27, 2022 — 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]
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 Mar 16, 2022
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 Mar 16, 2022
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 Mar 9, 2022
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 Jan 14, 2022
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 Mar 16, 2022
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))
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
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';