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 / fix-wordpress-permissions.sh
Created March 6, 2024 16:22 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
@monkeymonk
monkeymonk / git-users
Last active February 6, 2024 08:10
A tiny script to register and switch between Git users.
#!/bin/bash
# Path to the Git user file
GIT_USERS_FILE=~/.gitusers
# Check if Git is installed
if ! command -v git &>/dev/null; then
echo "Git is not installed on this machine"
exit
fi
@monkeymonk
monkeymonk / wpml-update-settings.js
Created August 17, 2023 06:27
WPML Translation setup snippet to check everything
document.querySelectorAll('.wpml-translation-setup-table input[type="radio"][value="3"]').forEach(input => { input.checked = true; });
@monkeymonk
monkeymonk / .htaccess
Created September 27, 2022 12:18 — forked from CurtisL/.htaccess
Better Maintenance Mode .htaccess rules
# 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
/**
* @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
/**
* @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
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
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
  • 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
/**
* Copy properties from source to target.
* @param target
* @param source
*/
function copyProps(target, source) {
const properties = Object.getOwnPropertyNames(source);
properties
.concat(Object.getOwnPropertySymbols(source))