Skip to content

Instantly share code, notes, and snippets.

View mandiwise's full-sized avatar

Mandi Wise mandiwise

  • Edmonton, Canada
View GitHub Profile
@mandiwise
mandiwise / permutations.js
Last active June 10, 2020 08:42
Get all unique permutations of character strings in an array.
let someChars = ['A', 'B', 'C', 'D'];
/**
* Handle all permutations for one array item (in relation to all other array items)
*/
function permutateAgainstOneItem(arr) {
let [first, ...tail] = arr;
let head = [first];
let permutations = [];
@mandiwise
mandiwise / functions.php
Last active February 11, 2021 01:14
Create, display and save an URL field in a WP custom metabox
<?php
/**
* Add the metabox.
*/
function my_url_add_metabox() {
add_meta_box(
'my_url_section', // The HTML id attribute for the metabox section
'My URL Metabox Title', // The title of your metabox section
@mandiwise
mandiwise / lexer.py
Created April 5, 2021 19:29
Mostly working JSX lexer for Pygments
# -*- coding: utf-8 -*-
"""
pygments.lexers.jsx
~~~~~~~~~~~~~~~~~~~~
Lexers for JSX formats.
Based on https://github.com/fcurella/jsx-lexer
"""
import re
@mandiwise
mandiwise / db.json
Created April 29, 2021 02:04
Sample book, author, and user data to be use with JSON Server.
{
"authors": [
{
"name": "Chinua Achebe",
"id": 1
},
{
"name": "Douglas Adams",
"id": 2
},
@mandiwise
mandiwise / Limit Gravity Forms Upload Size
Last active January 16, 2022 14:12
Set a maximum upload size for a Gravity Forms image field
function limit_file_upload_size( $validation_result ) {
$form = $validation_result['form'];
foreach( $form['fields'] as &$field ){
// NOTE: Add a custom CSS class to your image upload field and grab onto it here...
if( strpos( $field['cssClass'], 'choose-file' ) === false )
continue;
@mandiwise
mandiwise / init-letsencrypt.sh
Last active February 26, 2022 04:21
Create dummy certificates to start up nginx so it can request real certificate from Let's Encrypt
#!/bin/bash
# Usage:
# $ chmod +x init-letsencrypt.sh
# $ init-letsencrypt.sh mydomain.com bob@email.com 1
#
# Reference:
# https://medium.com/@pentacent/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71
domain=${1}
@mandiwise
mandiwise / seedData.js
Last active April 24, 2022 12:11
Generate seed data for Auth0 and MongoDB.
// Usage (from `server` directory):
// $ node -r dotenv/config -r esm src/scripts/seedData.js <PASSWORD>
import faker from "faker";
import gravatarUrl from "gravatar-url";
import mongoose from "mongoose";
import auth0 from "../config/auth0";
import initMongoose from "../config/mongoose";
import Post from "../models/Post";
@mandiwise
mandiwise / Dynamically Populate Gravity Forms Dropdown with CPT
Last active March 22, 2023 12:40
Using gform_pre_render_[form ID] for Auto-population
function populate_concept_nominees( $form ){
foreach ( $form['fields'] as &$field ){
// Set a custom CSS class for your field and grab onto it here
if ( $field['type'] != 'select' || strpos( $field['cssClass'], 'populate-concept' ) === false )
continue;
// Query parameters for get_posts
@mandiwise
mandiwise / Stop tracking directory in Git repo
Last active April 11, 2023 16:28
A command to stop tracking and entire directory in a Git repo
// Reference: http://stackoverflow.com/questions/936249/stop-tracking-and-ignore-changes-to-a-file-in-git
$ git rm --cached -r <dir>
@mandiwise
mandiwise / Update remote repo
Last active April 17, 2024 07:41
Transfer repo from Bitbucket to Github
// Reference: http://www.blackdogfoundry.com/blog/moving-repository-from-bitbucket-to-github/
// See also: http://www.paulund.co.uk/change-url-of-git-repository
$ cd $HOME/Code/repo-directory
$ git remote rename origin bitbucket
$ git remote add origin https://github.com/mandiwise/awesome-new-repo.git
$ git push origin master
$ git remote rm bitbucket