Skip to content

Instantly share code, notes, and snippets.

@keesiemeijer
keesiemeijer / setup-phpunit.sh
Last active September 5, 2024 01:56
Setup PHPUnit for use in the Local by Flywheel app
#!/usr/bin/env bash
# ===============================================================================
# Script to install PHPUnit in the Local by Flywheel Mac app
# These packages are installed
#
# PHPUnit, curl wget, rsync, git, subversion and composer.
#
# WordPress is installed in the `/tmp/wordpress` directory for use by PHPUnit.
# The WordPress test suite is installed in the `/tmp/wordpress-tests-lib` directory.
@oncode
oncode / write-an-open-source-js-lib.md
Created March 6, 2017 08:28 — forked from deadcoder0904/write-an-open-source-js-lib.md
How to Write an Open Source JavaScript Library
/**
* Build social sharing icons.
*
* @return string
*/
function wds_eight_display_social_share() {
// Build the sharing URLs.
$twitter_url = 'https://twitter.com/share?text=' . rawurlencode( html_entity_decode( get_the_title() ) ) . '&url=' . rawurlencode( get_the_permalink() );
$facebook_url = 'https://www.facebook.com/sharer/sharer.php?u=' . rawurlencode( get_the_permalink() );
@yajra
yajra / axios-401-response-interceptor.js
Last active October 8, 2024 21:22
Axios 401 response interceptor.
// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,
@colorful-tones
colorful-tones / class-custom-vc-element.php
Last active January 12, 2017 21:23
Example of using the `vc_shortcodes_css_class` to streamline VC's class name output on parent elements. See line #53 `add_filter()` and the `filter_vc_row_class()` function on line 73.
<?php
/**
* WDS Visual Composer Custom Element
*
* @since NEXT
* @package WDS Visual Composer
*/
/**
* WDS Visual Composer Custom Element
@ljharb
ljharb / array_iteration_thoughts.md
Last active April 15, 2025 03:33
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

<?php
/**
* Searches the database for transients stored there that match a specific prefix.
*
* @author Brad Parbs, Kellen Mace
* @param string $prefix prefix to search for.
* @return array nested array response for wpdb->get_results.
*/
function wds_campbell_search_database_for_transients_by_prefix( $prefix ) {
@priscillamc
priscillamc / wp-add-inline-scripts.md
Last active October 4, 2019 14:53
Adding inline javascript in WordPress 4.5+ using wp_add_inline_script()

Adding Inline Scripts in WordPress

Since WordPress 4.5, you can add the inline JavaScript using the wp_add_inline_script() function. This can be used instead of echoing inline scripts using wp_footer. The first argument is the handle of a registered script, in this case 'pretty-photo'.

function add_styles_scripts(){
	// Add script in the footer
	wp_enqueue_script('pretty-photo', get_stylesheet_directory_uri() . '/.../jquery.prettyPhoto.js', 
		array('jquery'), NULL, true);
	
@unfulvio
unfulvio / vagrant_setdate.sh
Last active October 22, 2024 17:38
How to change server time on a Vagrant box on Virtualbox
#!/bin/bash
# Log in into the box
vagrant ssh
# VirtualBox syncs host time with guest, so we need to shut off VBox Guest Additions first
sudo service vboxadd-service stop
# Now you can set any date and time
sudo date -s "2020-10-01 10:25:00"
@EtienneR
EtienneR / user.js
Created January 7, 2016 23:39
XMLHttpRequest RESTful (GET, POST, PUT, DELETE)
// Get all users
var url = "http://localhost:8080/api/v1/users";
var xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.onload = function () {
var users = JSON.parse(xhr.responseText);
if (xhr.readyState == 4 && xhr.status == "200") {
console.table(users);
} else {
console.error(users);