Skip to content

Instantly share code, notes, and snippets.

View timwhitlock's full-sized avatar

Tim Whitlock timwhitlock

View GitHub Profile
$ git diff install.old install.php
diff --git a/install.old b/install.php
index d23073b..6b2202e 100644
--- a/install.old
+++ b/install.php
@@ -39,7 +39,7 @@ require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
require_once( dirname( __FILE__ ) . '/includes/upgrade.php' );
/** Load wpdb */
retweet.html
rt-loader.js
#!/bin/bash
# dos2unix utility using translate characters command
# requires /usr/bin/tr
for f in "$@"
do
if [ -f "$f" ]; then
echo "dos2unix $f"
cat $f | /usr/bin/tr -d "\015" > "$f.tmp"
mv "$f.tmp" "$f"
@timwhitlock
timwhitlock / require_wp_db_patch.php
Created January 27, 2012 10:48
What require_wp_db function in Wordpress would look like, if it worked
<?php
function require_wp_db() {
global $wpdb;
if ( isset($wpdb) ){
return;
}
// Should check for override db.php file first
// - including both means fatal error on duplicate class
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ){
require_once( WP_CONTENT_DIR . '/db.php' );
@timwhitlock
timwhitlock / no-widows.php
Created February 2, 2012 16:42
Simple wordpress plug to avoid typographical widows
<?php
/*
Plugin Name: No Widows
Plugin URI: http://timwhitlock.info/
Description: Prevents typographical widows in titles and post body content
Author: Tim Whitlock
Version: 1.0
Author URI: http://timwhitlock.info/
*/
@timwhitlock
timwhitlock / dict.js
Last active January 6, 2021 19:01
Searchable JavaScript Dictionary
/**
* Searchable JavaScript dictionary.
*
* Usage:
* var dict = require('path/to/this').create();
* dict.add( 'somedata', 'Text to index' );
* var items = dict.find('text');
*/
exports.create = function(){
return new Dict;
@timwhitlock
timwhitlock / _tw_intercept_comment.php
Created June 19, 2012 12:45
Boot any comment bot that fills in the author website field
<?php
/**
* Boot any comment bot that fills in the author website field.
*/
function _tw_intercept_comment( array $data ){
if( empty($data['comment_author_url']) ){
return $data;
}
get_header();
echo 'See ya';
/**
* swipe inertia demo for browsers supporting the touchstart family of events
* @param HTMLElement
* @param Function touchend callback with speed and direction of swipe
*/
function initSwiper( el, callback ){
var xstart = 0, // <- initial scroll position on first touch
tstarts = [], // <- time each touch started
xoffset = [], // <- initial x position of each touch
yoffset = []; // <- initial y position of each touch
@timwhitlock
timwhitlock / touchmove.js
Created November 14, 2012 11:31
Snippet showing cancelling of touchmove event on vertical swipe
// [...] already calculated xmove and ymove since last movement ... ]
if( ymove && Math.abs(ymove) > Math.abs(xmove) ){
// this was intended as a vertical scroll - probably of the page
// we will allow this event through so the OS/browser can handle it.
return true;
}
if( xmove ){
// else take control of horizonal scroll position and cancel event
element.scrollLeft = Math.max( 0, xstart + xmove );
}
@timwhitlock
timwhitlock / eachTouchEvent.js
Created November 14, 2012 16:24
Abstracting touch and pointer events with an iterator function
function onTouchStart( event ){
eachTouchEvent( event, function( i, ev ){
ev.clientX; // <- do something with this
} );
return true;
}
function eachTouchEvent( event, callback ){