Skip to content

Instantly share code, notes, and snippets.

View mattboon's full-sized avatar

Matt Berridge mattboon

View GitHub Profile
@mattboon
mattboon / middleware.js
Created June 3, 2015 09:38
middleware.js
'use strict';
var glob = require('glob');
var objectAssign = require('react/lib/Object.assign');
var defaults = {
folder: './app/node_modules/components/',
extension: '.jsx'
};
@mattboon
mattboon / server.js
Created June 3, 2015 09:37
server.js
// Middleware
var middleware = require('./middleware/components.js');
app.use(middleware);
// Require the core Styleguide
var Styleguide = require('../app/node_modules/styleguide/layout');
var styleguideProps = this.props;
// Json for all components
app.get('/components.json', function(req, res) {
@mattboon
mattboon / webfont-localstorage.js
Last active June 26, 2016 02:09
webfont-localstorage.js
function supportsWoff2() {
"use strict";
/*global FontFace*/
// Source: https://github.com/filamentgroup/woff2-feature-test
if (!window.FontFace) {
return false;
} else {
var f = new FontFace('t', 'url("data:application/font-woff2,") format("woff2")', {});
f.load();
return f.status === 'loading';
@mattboon
mattboon / gist:9408252
Created March 7, 2014 09:19
Copy / Micro Copy Class Generator
=font-scale($sizes, $namespace: "copy", $micro_class: true)
@each $scale in $sizes
$current-breakpoint: nth($scale,1)
$current-font-size: nth($scale,2)
$base-size: $current-font-size !default
@if $current-breakpoint > 0
+mq-min($current-breakpoint)
.#{$namespace}
font-size: $current-font-size
@if $micro_class == true
<?php
// Return the page id by slug
// -------------------------------------------------------------
function get_ID_by_slug( $page_slug ) {
$page = get_page_by_path( $page_slug );
if ( $page ) {
return $page->ID;
} else {
return null;
@mattboon
mattboon / Different colour logo in print.css
Created December 12, 2012 15:03
For when you need a different logo for print than screen - either a higher quality, different colour etc. Use this in print.css. Doesn't work in IE7 but IE7/print is a bit of an edge case
/* for <a href="#" class="logo"><img src="..."></a> */
.logo,
.logo:before {
height: 75px;
width: 275px;
display: block; }
.logo {
position: relative; }
@mattboon
mattboon / gist:4202188
Created December 4, 2012 09:34
WordPress - Split content above and below <!--more--> tag
<?php
$morestring = '<!--more-->';
$explode_content = explode( $morestring, $post->post_content );
$content_before = apply_filters( 'the_content', $explode_content[0] );
$content_after = apply_filters( 'the_content', $explode_content[1] );
?>
@mattboon
mattboon / gist:4072631
Created November 14, 2012 15:04
WordPress - Add PDF filter to media library
<?php
// Add PDF filter to media library
add_filter( 'post_mime_types', 'modify_post_mime_types' );
function modify_post_mime_types( $post_mime_types ) {
// select the mime type, here: 'application/pdf'
// then we define an array with the label values
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) );
// then we return the $post_mime_types variable
return $post_mime_types;
@mattboon
mattboon / gist:4072627
Created November 14, 2012 15:03
WordPress - Add custom taxonomy filters to custom post types
<?php
// Add category filters to WP custom post types
add_action( 'restrict_manage_posts', 'my_add_category_filters' );
function my_add_category_filters() {
global $typenow;
if( $typenow == "event" ){
$taxonomy = 'event_type';
}
elseif( $typenow == "guideline" ){
@mattboon
mattboon / gist:4072618
Created November 14, 2012 15:01
WordPress - Add filter to 'event' post type to filter events in the past/future (given by event_date meta field)
<?php
// Add past/future events filter
add_action( 'restrict_manage_posts', 'my_add_past_prev_filter' );
function my_add_past_prev_filter() {
global $typenow;
// get our time period filter (if applied)
$time_period = $_GET['time_period'];
// set our select options