Skip to content

Instantly share code, notes, and snippets.

Weston Ruter westonruter

Block or report user

Report or block westonruter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@westonruter
westonruter / wordpress-lesscss.php
Created Nov 9, 2009
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.
View wordpress-lesscss.php
<?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 Nov 11, 2009
Track runtime performance of WordPress by adding these snippets to header.php and footer.php
View gist:232314
<!-- 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 Nov 12, 2009
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.
View optimize-scripts.php
Please see: http://svn.wp-plugins.org/optimize-scripts/trunk/
@westonruter
westonruter / canPlayAudioMP3.js
Created Dec 10, 2009
HTML5 MP3 Audio detection
View canPlayAudioMP3.js
/**
* 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 Dec 16, 2009
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.
View fixFootersForESVHTML.js
/**
* 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 Dec 16, 2009
Grayscale CSS Colors: Replace all CSS colors from STDIN with their grayscale versions in the STDOUT. Supports hex colors, rgb/rgba, and hsl/hsla.
View grayscale-css.pl
#!/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
View gist:300633
<?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 Feb 10, 2010
A patch to fix a “Scale to Fit” issue in the Shopp WordPress plugin
View gist:300864
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 Feb 22, 2010
jQuery fallback implementation of HTML5 placeholder attribute
View gist:311373
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 Feb 22, 2010
Detect multiple backgrounds (inspired by Modernizr) using data: URI so no HTTP requests made
View gist:311513
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"
}
You can’t perform that action at this time.