Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile
@westonruter
westonruter / wordpress-lesscss.php
Created November 9, 2009 19:37
lessphp for WordPress: filter for stylesheet URLs so that if there is a corresponding file with a .less extension and that file is newer than this .css file, then lessphp is invoked to rebuild the stylesheet: the theme comment header is preserved.
<?php
/**
* Filter stylesheet URLs so that if there is a corresponding file with
* a .less extension and that file is newer than this .css file, then lessphp
* <http://leafo.net/lessphp/> is invoked to rebuild the stylesheet: the
* comment header is preserved in the LESS output. Requires that lessphp be
* located in <TEMPLATEPATH/lessphp/lessc.inc.php> This filter may be invoked
* in header.php as follows:
* <link rel="stylesheet"
* href="<?php echo apply_filters('style_loader_src', get_stylesheet_uri(), null); ?>"
@westonruter
westonruter / gist:232314
Created November 11, 2009 21:25
Track runtime performance of WordPress by adding these snippets to header.php and footer.php
<!-- Add to beginning of <head> -->
<?php if(defined('WP_DEBUG') && WP_DEBUG): ?>
<script>var debugClientStartTime = (new Date()).valueOf();</script>
<?php endif; ?>
<!-- Add to end of <body> -->
<?php if(defined('WP_DEBUG') && WP_DEBUG):
ob_start(); ?>
<div id="debugPerformance">
<style scoped="">
@westonruter
westonruter / optimize-scripts.php
Created November 12, 2009 23:01
Concatenates scripts and then minifies and optimizes them using Google's Closure Compiler. For non-concatenable scripts, removes default WordPress 'ver' query param so that Web-wide cacheability isn't broken for scripts on CDNs like ajax.googleapis.com.
Please see: http://svn.wp-plugins.org/optimize-scripts/trunk/
@westonruter
westonruter / canPlayAudioMP3.js
Created December 10, 2009 07:13
HTML5 MP3 Audio detection
/**
* Detect if the browser can play MP3 audio using native HTML5 Audio.
* Invokes the callack function with first parameter is the boolean success
* value; if that value is false, a second error parameter is passed. This error
* is either HTMLMediaError or some other DOMException or Error object.
* Note the callback is likely to be invoked asynchronously!
* @param {function(boolean, Object|undefined)} callback
*/
function canPlayAudioMP3(callback){
try {
@westonruter
westonruter / fixFootersForESVHTML.js
Created December 16, 2009 17:56
ESV API Footnote Fix: The HTML marking up the footnotes returned by the ESV API is undesirable. Each footnote is separated from following footnotes by <br> elements. This function places each footnote inside of a <li> and adds the ID of the link inside.
/**
* The HTML marking up the footnotes returned by the ESV API is undesirable.
* Each footnote is separated from following footnotes by <br> elements:
* <span class="footnote"><a href="#b1" id="f1">[1]</a></span> <span class="footnote-ref">1:6</span> ...<br />
* This function places each footnote inside of a <li> and adds the ID of the
* link inside.
* Created for http://pixelfaith.com/bible/
*/
function fixFootersForESVHTML(){
var footnotes = document.querySelector('.footnotes > p');
@westonruter
westonruter / grayscale-css.pl
Created December 16, 2009 21:52
Grayscale CSS Colors: Replace all CSS colors from STDIN with their grayscale versions in the STDOUT. Supports hex colors, rgb/rgba, and hsl/hsla.
#!/usr/bin/perl -w
# Grayscale CSS:
# Replace all CSS colors from STDIN with their grayscale versions in the STDOUT.
# Supports hex colors, rgb/rgba, and hsl/hsla.
# Usage: perl grayscale-css.pl screen.css > grayscale-screen.css
# by Weston Ruter <http://weston.ruter.net/>
# Copyright 2009, Shepherd Interactive <http://shepherdinteractive.com/>
# License: GPL 3.0 <http://www.gnu.org/licenses/gpl.html>
#
# This program is free software: you can redistribute it and/or modify
<?php
define('MD5_INPUT', "Hello, World!");
?>
<script src="gibberish-aes.js"></script>
<pre><?php echo md5(MD5_INPUT); ?></pre>
<pre><script>
var md5_arr = GibberishAES.Hash.MD5(<?php echo json_encode(MD5_INPUT) ?>);
var md5_hex = '';
for(var i = 0; i <md5_arr.length; i++){
var hex = md5_arr[i].toString(16);
@westonruter
westonruter / gist:300864
Created February 10, 2010 21:28
A patch to fix a “Scale to Fit” issue in the Shopp WordPress plugin
Index: core/model/Image.php
===================================================================
--- core/model/Image.php (revision 99)
+++ core/model/Image.php (revision 100)
@@ -72,16 +72,14 @@
if($this->src->height*$scale > $height){ // Now scale by height if it would end up too tall
$scale *= $height / ($this->src->height*$scale);
}
- $this->Processed->width = $width;
- $this->Processed->height = ceil($this->src->height * $scale);
@westonruter
westonruter / gist:311373
Created February 22, 2010 19:21
jQuery fallback implementation of HTML5 placeholder attribute
if(!jQuery('<input PLACEHOLDER="1" />')[0].placeholder){ //Uppercase attr for IE
jQuery(':input[placeholder]').each(function(){
var $this = $(this);
if(!$this.val()){
$this.val($this.attr('placeholder'));
$this.addClass('input-placeholder');
}
}).live('focus', function(e){
var $this = $(this);
if($this.hasClass('input-placeholder')){
@westonruter
westonruter / gist:311513
Created February 22, 2010 21:20
Detect multiple backgrounds (inspired by Modernizr) using data: URI so no HTTP requests made
var url = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
var div = document.createElement('div');
div.style.background = "url(" + url + "),url(" + url + "), black url(" + url + ")";
if(!div.style.backgroundImage || div.style.backgroundImage.match(/url/g).length != 3){
document.documentElement.className += " no-multiplebgs"
}