Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile
@westonruter
westonruter / gist:326845
Created March 9, 2010 17:25
Quick and dirty WordPress plugin to ensure content is served over SSL if no mixed content.
<?php
/*
Plugin Name: Force HTTPS
Version: 0.1
Description: Quick and dirty way to ensure content is served over SSL if no mixed content. Removes the "http:" and "https:" from external images embedded in the_content so that SSL can be enabled without the security warning in IE. Redirects to HTTPS if no mixed-content warning will be generated; redirects back to HTTP if it will. Makes use of output buffering. Developed at <a href="http://shepherdinteractive.com/">Shepherd Interactive</a>.
Author: Weston Ruter
Author URI: http://weston.ruter.net/
*/
function wr_force_https_init(){
@westonruter
westonruter / create.php
Created April 20, 2010 21:49
HTTP 201 Created redirect test
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'):
header("Location: http://$_SERVER[HTTP_HOST]/create.php?created", true, 201);
?>
Created <a href='create.php?created'>resource</a>
<?php
exit;
elseif($_SERVER['QUERY_STRING'] == 'created'): ?>
<h1>I am the created resource!</h1>
<?php endif; ?>
@westonruter
westonruter / jquery.bindAndCall.js
Created April 30, 2010 07:00
jQuery.fn.bindAndCall(type, callback): Not only bind a handler to an event, but also call it immediately once.
/*!
* Not only bind a handler to an event, but also call it immediately once.
* @param {string} event One or more event types separated by spaces. Only first listed will be immediately called.
* @param {function(Object)} callback The event handler
* @returns {jQuery}
*/
jQuery.fn.bindAndCall = function(type, callback){
this.bind(type, callback);
var types = type.split(/\s+/); //because only one type makes sense to call
this.each(function(){
/*!
* bindAndTrigger - v0.2 - 04/30/2010
* http://benalman.com/ (original v0.1 at http://gist.github.com/384866 )
* http://weston.ruter.net/ (playing around with improving variable args)
*
* http://jsfiddle.net/cowboy/fJnA2/
*/
(function($,undefined){
@westonruter
westonruter / jquery.prop.js
Created April 30, 2010 16:28
jQuery.fn.prop(name, vaue): Same as jQuery('…').attr(name, value) but for DOM attributes (properties)
/**
* Same as jQuery('…').attr(name, value) but for DOM attributes (properties)
* @param {string} name The property name
* @param {mixed} value The property value
* @todo Allow for passing setter
*/
jQuery.fn.prop = function(name, value){
if(typeof value == 'undefined'){
return this.length ? this[0][name] : null;
}
@westonruter
westonruter / WidgetWithBehaviorScript.widget.php
Created May 6, 2010 22:08
WidgetWithBehaviorScript: Template for a WordPress widget which enqueues an accompanying behavior script; script only output if widget is rendered.
<?php
class WidgetWithBehaviorScript extends WP_Widget {
function __construct() {
parent::__construct(__CLASS__, 'Widget with Accompanying Behavior Script', array(
'classname' => __CLASS__,
'description' => "This WordPress widget serves as a pattern for how to enqueue a script only if the widget is actually rendered."
));
@westonruter
westonruter / jquery.html5.hide-show.js
Created May 12, 2010 22:33
jQuery hide() and show() supporting HTML5 hidden attribute
(function(){
// jQuery hide() and show() supporting HTML5 hidden attribute
// "All HTML elements may have the hidden content attribute set. The hidden
// attribute is a boolean attribute. When specified on an element, it indicates
// that the element is not yet, or is no longer, relevant. User agents should
// not render elements that have the hidden attribute specified."
// http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#the-hidden-attribute
// Pointers from http://www.bennadel.com/blog/1624-Ask-Ben-Overriding-Core-jQuery-Methods.htm
var originalHide = jQuery.fn.hide;
@westonruter
westonruter / webpage-expose.user.js
Created June 15, 2010 17:53
Webpage Exposé User Script: Hit Alt+Spacebar to toggle zooming in & out of a page so that everything can be seen at once. When zoomed out, clicking on an element will unzoom and scroll to it. Uses CSS3 Transforms. Tested in Chrome and Firefox 4 w/ GMonkey
// ==UserScript==
// @name Webpage Exposé
// @description Hit Alt+Spacebar to toggle zooming in & out of a page so that everything can be seen at once. When zoomed out, clicking on an element will unzoom and scroll to it. Uses CSS3 Transforms. Tested in Chrome and Firefox 4 w/ Greasemonkey.
// @namespace http://weston.ruter.net/
// @include *
// @license GPL/MIT
// @version 0.2
// @author Weston Ruter (@westonruter) <http://weston.ruter.net/> of X-Team <http://x-team.com/>
// ==/UserScript==
# coding: utf8 #
from django.db import models
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from core.models import Language, License, Server
// ==UserScript==
// @name Wikipedia TTS-friendly Markup
// @description Include a button in the toolbar on Wikipedia articles to toggle the inclusion of elements not suitable for feeding into a screen-reader.
// @namespace http://weston.ruter.net/
// @include http://en.wikipedia.org/wiki/*
// ==/UserScript==
var noReadEls = [];
Array.forEach(document.querySelectorAll('#bodyContent sup, #toc, .editsection'), function(el){