Skip to content

Instantly share code, notes, and snippets.

View chrisvanpatten's full-sized avatar

Chris Van Patten chrisvanpatten

View GitHub Profile
@CharlieHawker
CharlieHawker / gulp-favicons.js
Last active January 15, 2019 21:13
Generate favicons for common sizes automatically from an SVG file using gulp
var gulp = require('gulp'),
imagemin = require('gulp-imagemin'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
rimraf = require('gulp-rimraf'),
imageResize = require('gulp-image-resize');
gulp.task('clean:favicons', function() {
return gulp.src('dist/favicon*')
@theMikeD
theMikeD / image_meta.php
Created January 20, 2015 17:43
Manipulates the metadata for uploaded images at upload time to make better use of IPTC data that may be present.
<?php
/*
Manipulates the metadata for uploaded images at upload time to make better use
of IPTC data that may be present.
An image is stored as an attachment, which is a special type of post. It is
handled the same way as any other post type.
As far as the meta goes, it's stored like this:
@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
@jbrinley
jbrinley / force-plugin-activation.php
Last active November 5, 2020 15:11
An mu-plugin that forces selected plugins to be active, without the capability to deactivate.
<?php
/*
Plugin Name: Force Plugin Activation/Deactivation (except if WP_DEBUG is on)
Plugin URI: http://tri.be/
Description: Make sure the required plugins are always active.
Version: 1.0
Author: Modern Tribe, Inc.
Author URI: http://tri.be/
*/
@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 {}
/*
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
@janfabry
janfabry / virtual-intermediate-images.php
Created November 13, 2010 16:05
WordPress Virtual intermediate images plugin (first public attempt)
<?php
/*
Plugin Name: Virtual intermediate images
Plugin URI: http://www.monkeyman.be
Description: Prevent creation of actual intermediate image sizes
Version: 0.1
Author: Jan Fabry
This plugin prevents the creation of actual intermediate image sizes. It does, however, fill in all metadata attributes as if the intermediate sizes exist. It is designed to work together with a plugin that can create these images on the fly, like monkeyman-on-demand-resizer.
@janfabry
janfabry / on-demand-resize.php
Created November 13, 2010 16:03
WordPress On-Demand image resizer plugin (first public attempt)
<?php
/*
Plugin Name: On-Demand image resizer
Plugin URI: http://www.monkeyman.be
Description: Create and store images in different sizes on demand
Version: 1.0
Author: Jan Fabry
This plugins monitors 404 requests to the uploads directory and created new images of a requested size. They are saved as new files in the upload directory, not cached somewhere, so future requests are served directly by the server. This allows you to eliminate the creation of intermediate image sizes [see monkeyman-virtual-intermediate-images] or resize images based on the size used in the editor [see monkeyman-resize-image-tags].