Skip to content

Instantly share code, notes, and snippets.

@pospi
pospi / wordpress-hostchange.sql
Created January 30, 2014 23:04
Some SQL for quickly moving WordPress sites between servers.
SET @FROMDOMAIN = 'myolddomain.com';
SET @TODOMAIN = 'mynewdomain.com';
SET @FROMSCHEME = 'http';
SET @TOSCHEME = 'http';
#-------------- STANDARD TABLES -------------#
UPDATE wp_options
@pospi
pospi / git-post-receive-deployment.sh
Last active August 29, 2015 13:55
A generic git post-receive hook for auto-deploying applications when pushed to.
#!/bin/bash
#------------------------------------------------------------------------------#
# CONFIGURATION
# You will need the following variables set in the git repository to deploy from:
# git config --bool receive.denyCurrentBranch false
# git config --bool core.bare false
# git config --path core.worktree [DEPLOYMENT_DIR]
@pospi
pospi / ie-compatible-rotation.less
Created August 18, 2014 07:01
IE6+ compatible rotation mixin using matrices
.rotate-ie(@degrees) {
-webkit-transform: rotate(@degrees);
-o-transform: rotate(@degrees);
transform: rotate(@degrees);
@cos: cos(@degrees);
@sin: sin(@degrees);
@nl: `"\n"`; // Newline
@pospi
pospi / parse-latlng.js
Last active August 29, 2015 14:11
Parse common lat/lng formats
var parseLatLng = (function()
{
var matchLocDecimal = /^\s*(-?\d+)(\.\d+)?\s*°?\s*(N|S)?(,|\s)+(-?\d+)(\.\d+)?\s*°?\s*(E|W)?\s*$/;
var matchLocDegrees = /^\s*(-?\d+)°?\s*((\d+)(\.\d+)?'?)?\s*(N|S)?(,|\s)+(-?\d+)°?\s*((\d+)(\.\d+)?'?)?\s*(E|W)?\s*$/;
var matchLocCompass = /^\s*(-?\d+)°?\s*((\d+)('|\s)+)?\s*((\d+)(\.\d+)?(''|")?)?\s*(N|S)?(,|\s)+(-?\d+)°?\s*((\d+)('|\s)+)?\s*((\d+)(\.\d+)?(''|")?)?\s*(E|W)?\s*$/;
return function(val)
{
var matches,
lat, lng,
@pospi
pospi / slideToggle.js
Created January 13, 2015 01:09
TweenLite slideToggle behaviour using scrollHeight attribute for height calculation
/**
* Prerequisites:
* element must be block-level & visible
* element must have height: 0
* element must have overflow: hidden
*
* Returns true if the element was shown, false if it was hidden
*/
function slideToggle(ul)
{
@pospi
pospi / dev_server.sh
Created March 21, 2015 01:23
A basket init script for a LEMP server
#!/bin/env bash
echo Setting up dev server
# Change these as you need:
declare HOSTNAME=my_host
declare DB_ROOT_PW=my_password
declare DB_NAME=my_dbname
declare NGINX_CONFIG=my_site
declare OPTIONAL_PACKAGES="sudo vim git"
@pospi
pospi / debug-fired-events.js
Last active November 22, 2015 02:17
Watch all DOM and jQuery events active on a page and log when they fire
window.watchEvents = function() {
var eventIds = [
'click', 'mousedown', 'mouseup',
'touch', 'touchstart', 'touchend',
'focus', 'focusin', 'focusout', 'blur',
'mouseover', 'mouseout', 'mousemove', 'mouseenter', 'mouseleave', 'mousewheel',
'keypress', 'keydown', 'keyup',
'change',
'scroll', 'resize',
'submit', 'reset',
@pospi
pospi / hierarchy-sort.php
Last active December 22, 2015 10:19
Wordpress helper method for efficiently organising a hierarchical taxonomy into a hierarchical data structure. Similar code could be used to organise any hierarchical dataset.
<?php
/**
* Recursively sort an array of taxonomy terms hierarchically. Child categories will be
* placed under a 'children' member of their parent term.
*
* @param Array $cats taxonomy term objects to sort
* @param Array $into result array to put them in
* @param integer $parentId the current parent ID to put them in
*/
function sortHierarchicalTaxonomy(Array $cats, Array &$into, $parentId = 0)
@pospi
pospi / reset-admin-ui.js
Created September 13, 2013 06:56
Reset the Wordpress admin UI to its default state after failing some clientside validation upon saving.
$('#publishing-action')
.find('.spinner').hide().end()
.find('#publish').removeClass('button-primary-disabled');
$('#save-action')
.find('.spinner').hide().end()
.find('#save-post').removeClass('button-disabled');
@pospi
pospi / jquery.clickoutside.js
Created September 24, 2013 00:54
Very simple jQuery event for handling unfocusing of elements when clicking outside of them.
(function($) {
var WATCH_FOCUS_ON = $();
$.event.special['clickoutside'] = {
setup: function()
{
WATCH_FOCUS_ON = WATCH_FOCUS_ON.add( this );
// bind document handler if this is the first guy being bound