Skip to content

Instantly share code, notes, and snippets.

View chrisvanpatten's full-sized avatar

Chris Van Patten chrisvanpatten

View GitHub Profile
@dlh01
dlh01 / distribute_user.sh
Last active June 27, 2023 20:25
WP-CLI: Add a user to all sites in a network
#!/bin/bash
# Usage: ./distribute_user.sh [username] [role]
ARGS="$@"
echo "Adding user $1 as $2 to all sites"
SITES=$(wp site list --field=url --format=csv)
for site in $SITES
do
@kingkool68
kingkool68 / pew-infinite-scroll.js
Last active January 4, 2018 21:27
Plugin for handling the URLs to make infinite scrolling work properly on pages like this http://www.pewresearch.org/category/publications/
jQuery(document).ready(function() {
//Set-up some constants.
var scrollTimeout;
var scrollUsePushStateInstead = false; //Set to true to make the history stack of the browser include every point when posts were loaded. It's kind of annoying.
var scrollDelay = 200; //Milliseconds
var scrollLoading = false;
var triggerOffset = $(document).height() - $('#pagination').siblings().eq(-4).offset().top; //The point of this is to do one calculation up front instead of multiple calculations every time the infinite scroll is triggered.
// Simple feature detection for History Management (borrowed from Modernizr)
function supportsHistory() {
@VladaHejda
VladaHejda / Phpunit-Mockery_mock_ArrayAccess_Iterator_Countable-TestCase.php
Last active January 18, 2020 18:23
PHP mock ArrayAccess / Iterator / Countable. Using Phpunit with Mockery. TestCase for simple mocking classes that implements ArrayAccess, Iterator or Countable. Just create mock and call in your test: $this->mockArrayIterator($mock, $array);Notice that if you mock an interface that extends Iterator, Mockery will fail due to bug at https://github…
<?php
abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected function tearDown()
{
parent::tearDown();
\Mockery::close();
}
@Integralist
Integralist / Description.md
Last active April 25, 2020 16:20
This is how BBC News currently implements it's Image Enhancer for responsive images. Note: this is a completely rebuilt version of the code so the BBC's original source code doesn't actually look anything like the below example.

The BBC has a server-side image service which provides developers with multiple sized versions of any image they request. It works in a similar fashion to http://placehold.it/ but it also handles the image ratios returned (where as placehold.it doesn't).

The original BBC News process (and my re-working of the script) follows roughly these steps...

  • Create new instance of ImageEnhancer
  • Change any divs within the page (which have a class of delayed-image-load) into a transparent GIF using a Base64 encoded string.
    • We set the width & height HTML attributes of the image to the required size
    • We know what size the image needs to be because each div has custom data-attr set server-side to the size of the image
    • We then set a class of image-replace onto each newly created transparent image
  • We use a 250ms setTimeout to unblock the UI thread and which calls a function resizeImages which enhances the image-replace images so their source is now set to a URL whe
@strangerstudios
strangerstudios / heartbeat-api-demo.php
Last active April 30, 2024 17:08
Minimal example demonstrating the WordPress Heartbeat API being added in WP version 3.6.
<?php
/*
Plugin Name: Heartbeat API Demo
Plugin URI: http://www.strangerstudios.com/wp/heartbeat-api-demo
Description: Minimal example demonstrating the WordPress Heartbeat API being added in WP version 3.6.
Version: .1
Author: strangerstudios
If logged in as a user and viewing the frontend of your website,
every 15 seconds you should see the following in your Javascript console:
@madalinignisca
madalinignisca / wordpress-default.css
Created May 13, 2013 13:07
Default WordPress classes for using with CSS
/**
* Default Body Class Styles
*/
.rtl {}
.home {}
.blog {}
.archive {}
.date {}
.search {}
@pwc3
pwc3 / Exchange Sync.applescript
Last active February 1, 2024 12:34
AppleScript to copy all of the events from an Exchange calendar to an iCloud calendar.
tell application "Calendar"
-- delete everything from the destination calendar
-- TODO: Change "Destination Calendar" to be the name of your destination calendar
repeat with anEvent in (get events of calendar "Destination Calendar")
delete anEvent
end repeat
-- copy all events from the source calendar to the destination
-- TODO: Change "Source Calendar" to be the name of your source calendar
-- TODO: Change "Destination Calendar" to be the name of your destination calendar
/*
Only change the from email/name on PMPro emails.
This code is useful if Paid Memberships Pro is updating the from name and email on non-PMPro emails and you don't want it to.
Add this code to your active theme's functions.php or a custom plugin.
*/
function my_pmpro_email_headers_init()
{
//first remove the default actions
@chrisvanpatten
chrisvanpatten / _fonts.scss
Last active December 10, 2015 17:39
Fonts
/*
* Using Sass's @each loop to automatically generate code for web fonts
*/
$fonts: (vpm, font-awesome);
@each $font in $fonts {
@include font-face( $font,
font-files(
'#{$font}/#{$font}.woff',
@mudge
mudge / gist:4111082
Created November 19, 2012 14:53
Capistrano task to use relative symlinks instead of absolute.
require "pathname"
namespace :deploy do
task :create_symlink, :except => { :no_release => true } do
deploy_to_pathname = Pathname.new(deploy_to)
on_rollback do
if previous_release
previous_release_pathname = Pathname.new(previous_release)
relative_previous_release = previous_release_pathname.relative_path_from(deploy_to_pathname)