Reference for How to Write an Open Source JavaScript Library
The purpose of this document is to serve as a reference for:
How to Write an Open Source JavaScript Library course by Kent C. Dodds
Watch the series at egghead.io, if you haven't.
#!/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. |
The purpose of this document is to serve as a reference for:
How to Write an Open Source JavaScript Library course by Kent C. Dodds
Watch the series at egghead.io, if you haven't.
/** | |
* 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() ); |
// 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, |
<?php | |
/** | |
* WDS Visual Composer Custom Element | |
* | |
* @since NEXT | |
* @package WDS Visual Composer | |
*/ | |
/** | |
* WDS Visual Composer Custom Element |
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.
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 ) { |
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);
#!/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" |
// 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); |