Skip to content

Instantly share code, notes, and snippets.

View cyberhobo's full-sized avatar

Dylan Kuhn cyberhobo

View GitHub Profile
@cyberhobo
cyberhobo / google-marker-drag.html
Created November 26, 2010 20:20
Add mapstraction marker dragend event to Google markers. Save files in the examples directory of a mapstraction tree to try.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mapstraction Examples - google v2</title>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAY70wuSo0zF3ZtJVp5bDm1BS1Y2ErAqCHV5rDhHSzgjy23KqwdRRaoSBuZk72oDzzAYxVBjtsLqSmTw"></script>
<script src="../source/mxn.js?(google)" type="text/javascript"></script>
<script src="mxn.google.extras.js" type="text/javascript"></script>
<style type="text/css">
#mapdiv {
height: 400px;
}
@cyberhobo
cyberhobo / mkpasswd.sh
Created April 6, 2012 20:50
bash script to generate a random password
#!/bin/bash
LEN=${1-12}
head /dev/urandom | uuencode -m - | sed -n 2p | cut -c1-${1:-$LEN};
@cyberhobo
cyberhobo / functions.php
Created July 25, 2012 16:55
Filter expired The Events Calendar events from a Geo Mashup map
/*
* Exclude expired events from Geo Mashup queries
*/
function calant_filter_geo_mashup_locations_fields( $fields ) {
global $spEvents;
if ( isset( $spEvents ) )
$fields .= ', eventEnd.meta_value as EventEndDate ';
return $fields;
}
add_filter('geo_mashup_locations_fields', 'calant_filter_geo_mashup_locations_fields');
@cyberhobo
cyberhobo / custom-mxn.js
Created September 10, 2012 20:58
Some common custom javascript for customizing geo mashup map markers for Mapstraction map providers (any other than Google v2). The marker images used are 24 x 24 pixels, anchored at the bottom center, with no shadow. #wordpress-geo-mashup #geo-mashup
(function() {
GeoMashup.addAction( 'colorIcon', function( properties, icon, color_name ) {
// For single category icons use the Geo Mashup color icon names,
// but the 24x24 ones in the custom image directory
icon.image = properties.custom_url_path + '/images/mm_20_' + color_name + '.png';
icon.iconShadow = '';
icon.iconSize = [ 24, 24 ];
icon.iconAnchor = [ 12, 24 ];
icon.iconInfoWindowAnchor = [ 12, 1 ];
@cyberhobo
cyberhobo / delete-dup-custom-fields.sql
Created October 4, 2012 19:31
Sometimes post imports in WordPress can create duplicate custom fields for posts that already exist. This will delete custom fields on posts the have the same key and value. A post type restriction is included as an example of further narrowing.
DELETE o
/* SELECT p.post_title, o.*, pmi.* */
FROM wp_postmeta AS o
INNER JOIN wp_posts AS p ON p.ID = o.post_id
INNER JOIN wp_postmeta AS pmi ON pmi.post_id = o.post_id AND pmi.meta_key = o.meta_key AND pmi.meta_value = o.meta_value
WHERE p.post_type = 'post'
AND pmi.meta_id < o.meta_id
@cyberhobo
cyberhobo / wpdump.bash
Created October 8, 2012 16:12
Bash alias for mysqldump using credentials from a wp-config.php file
#!/bin/bash
# one argument: the directory of a wp-config.php file
wpconfig=$1/wp-config.php
if [ ! -f "$wpconfig" ]; then
echo "$wpconfig not found."
exit
fi
@cyberhobo
cyberhobo / custom-googlev3.js
Last active December 12, 2015 00:59
Geo Mashup google v3 custom marker z-index for a marker with an object with category ID 9
(function( $ ) {
GeoMashup.addAction( 'loadedMap', function( properties, mxn_map ) {
$.each( mxn_map.markers, function( i, marker ) {
var objects = GeoMashup.getMarkerObjects( marker );
$.each( objects, function( j, object ) {
$.each( object.categories, function( k, category_id ) {
if ( 9 == category_id ) {
marker.proprietary_marker.setZIndex( 100 );
}
});
@cyberhobo
cyberhobo / custom-mxn.js
Last active December 15, 2015 23:09
Custom Geo Mashup javascript to visit the first post at a marker when clicked. #wordpress-geo-mashup #geo-mashup
GeoMashup.addAction( 'selectedMarker', function( properties, marker, map ) {
var objects = GeoMashup.getMarkerObjects( marker );
if ( objects.length > 0 && GeoMashup.have_parent_access ) {
parent.location.href = properties.home_url + '?p=' + objects[0].object_id;
}
});
@cyberhobo
cyberhobo / import-wpe-archive
Last active December 17, 2015 17:39
Beginnings at least of a shell script to refresh a local development WordPress site with the contents of a WPEngine archive. Uses [wp-cli](http://wp-cli.org).
#!/bin/bash
# exit on error
set -e
archive=$1
# one argument: the archive file
if [ ! -r "$archive" ]; then
echo "Usage: import-wpe-archive <zip-archive>"
@cyberhobo
cyberhobo / backtrace.php
Created December 10, 2013 20:26
PHP (5.3 and up) Notice & Warning Backtrace - just need to quickly see what's causing that message in a non-production environment? Override error handling. In WordPress I do this in my wp-config.php, and remove it again when done.
set_error_handler( function( $no, $str, $file, $line ) {
echo "<pre>$str\n";
var_dump( debug_backtrace() );
echo "</pre>";
} );