Skip to content

Instantly share code, notes, and snippets.

View astockwell's full-sized avatar

Alex Stockwell astockwell

View GitHub Profile
<?php
/*
* Reference
*
* Term object keys:
* [term_id, name, slug, term_group, term_taxonomy_id, taxonomy, description, parent]
*
*/
@astockwell
astockwell / Readme.md
Last active December 26, 2015 13:59
The following is an extraction of depricated methods from jQuery UI v1.9.2 as a quick-fix monkey-patch for the Wordpress Bannerize plugin to enable compatibility with the new jQuery UI v1.10 included in Wordpress v3.6. USE AT YOUR OWN RISK, BACK UP YOUR FILES & DATABASE. I do not advocate modifying core plugin files unless it is an emergency. NO…

Two files must be modified for this fix to work:

#	modified:   wp-content/plugins/wp-bannerize/js/jquery-ui.min.js
#	modified:   wp-content/plugins/wp-bannerize/js/jquery.timepicker.min.js
  1. Save everything else, ensure you are using source control, and backup your files and database!
  2. Replace the entire contents of wp-content/plugins/wp-bannerize/js/jquery.timepicker.min.js with the contents of the latest version.
  3. Replace the entire contents of wp-content/plugins/wp-bannerize/js/jquery-ui.min.js with the contents of jquery-ui.min.js from this gist.
@astockwell
astockwell / script.js
Created October 24, 2013 20:03
Enquire! "True" on line 46 activates this breakpoint for non-supporting browsers (IE!!!).
// ========================================================================== //
// Media Query JS support
// ========================================================================== //
$(function(){
mq_desktop = 620;
// Initial setup (all breakpoints)
$(document).ready(function() {
// Setup learnmore blocks
$('.learnmore').hide();
@astockwell
astockwell / helpers.php
Last active December 26, 2015 05:59
PHP truncate text at word function
<?php
function truncate($string, $length, $tailing_char = '...') {
if (strlen($string) > $length):
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string . ' ', 0, $length)) . $tailing_char;
endif;
return $string;
}
@astockwell
astockwell / scrape_image_urls.rb
Created September 8, 2013 23:49
Scrape media portal of client site (had to use Watir due to site being built in backbone.js) to download 1000+ high-res images. 1) Scrape image file URLs from all gallery pages. 2) Run non-trivial curl/wget loop to download image files (not shown). 3) Re-organize files from step 2 based on product categories from step 1.
#!/bin/env ruby
require 'watir-webdriver'
@username = ENV["username"]
@password = ENV["password"]
@login_url = ENV["login_url"]
@product_url = "#{@login_url}/photos/"
@astockwell
astockwell / _README.md
Last active December 30, 2023 22:39
PHP Serialization Fix. For use after a find/replace/sed on MySQL dump, to repair String lengths in serialized PHP objects. Optimized and refactored for memory-safe production use in Python (~7s for 250MB dump, ~400K replacements). Written also in Perl (~7s for 250MB), Ruby (~8s for 250MB) and Go (~20s for 250MB) for benchmark comparison. Python …
@astockwell
astockwell / functions.php
Last active December 21, 2015 00:59
Paginate a custom WP_Query on a Wordpress static page. Be sure to REFRESH PERMALINKS!!!
// add new rule to match routes at "/events/page/#"
function add_rewrite_rules($aRules) {
$aNewRules = array('events/page/(\d+)/?$' => 'index.php?pagename=events&paged=$matches[1]');
$aRules = $aNewRules + $aRules;
return $aRules;
}
// hook add_rewrite_rules function into rewrite_rules_array
add_filter('rewrite_rules_array', 'add_rewrite_rules');
@astockwell
astockwell / functions.php
Created August 2, 2013 19:12
Format Date/Time strings in PHP < version 5.3
<?php
/*
* VARIABLE FORMATS:
* $e_date = '02/10/2012' (string)
* $e_time = '7:00 pm' (string)
* $e_end = '11:00 pm' (string)
* $format_short = true (boolean)
*/
@astockwell
astockwell / klas_to_flat.sh
Last active December 20, 2015 11:59
Creates a working project for flat (non-Wordpress) site development from the latest [KLAS framework](https://github.com/kylelarkin/klas). Usage is indicated at the top of the file. Don't use if you don't understand what's going on, as this file is destructive. Remove from your project after use.
#!/bin/bash
#### TO USE ####
# 1. Create a new folder for your project
# 2. Save this script in that folder (as klas_to_flat.sh)
# 3. Run `chmod +x klas_to_flat.sh` to make it executable
# 4. Run `./klas_to_flat.sh`
#### Smile ####
set -eu
<script>
(function(d,s){
var x = d.createElement(s),
o = d.getElementsByTagName(s)[0];
x.src="script.js"; // your script here
x.async=true; // mostly optional
o.parentNode.insertBefore(s,o); // inject
})(document,'script');
</script>