Skip to content

Instantly share code, notes, and snippets.

View simonpioli's full-sized avatar

Simon Pioli simonpioli

  • LawPlus Solicitors
  • Manchester, UK
View GitHub Profile
%sprites {
display: inline-block;
background-repeat: no-repeat;
background-image: sprite-url($sprites);
}
@mixin sprite($name, $dimensions: true, $pad: 0) {
@if ($dimensions == true) {
@include sprite-dimensions($sprites, $name);
}
module Jekyll
class CategoryAwareNextGenerator < Generator
safe true
priority :high
def generate(site)
site.categories.each_pair do |category_name, posts|
posts.sort! { |a, b| b <=> a }
@simonpioli
simonpioli / wp-config.php
Created March 9, 2013 13:33
Improved Wordpress wp-config for >1 Environment
<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
*
* This file is used by the wp-config.php creation script during the
@simonpioli
simonpioli / wp-migration.sql
Created March 13, 2013 10:06
Wordpress DB Migration
SET @from_host = 'old-host.com';
SET @to_host = 'new-host.com';
UPDATE `wp_options` SET `option_value` = REPLACE(`option_value`, @from_host, @to_host);
UPDATE `wp_posts` SET `guid` = REPLACE(`guid`, @from_host, @to_host);
UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`, @from_host, @to_host);
@simonpioli
simonpioli / jquery-ui-datepicker-between.js
Created March 16, 2013 20:16
Date-pickers to show between 2 dates using jQuery UI Datepicker
$(function() {
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
numberOfMonths: 1,
beforeShow: function( ) {
var other = this.id == "from" ? "#to" : "#from";
var option = this.id == "from" ? "maxDate" : "minDate";
var selectedDate = $(other).datepicker('getDate');
$(this).datepicker( "option", option, selectedDate );
@simonpioli
simonpioli / anchor-animate.js
Last active December 15, 2015 04:39
Animate the scroll for links to areas of the same page. Requires jQuery.
/** This version only requires jQuery **/
$("a[href*='#']").click(function(event) {
event.preventDefault();
var full_url = this.href;
if(full_url !== '#') {
var parts = full_url.split("#");
var trgt = parts[1];
var target_offset = $("#" + trgt).offset();
var target_top = target_offset.top;
@simonpioli
simonpioli / domain-check.sh
Last active December 16, 2015 00:18
Retrieves the IP of the supplied hostname hourly and pops up a Growl Notification if/when the IP changes. I use it when switching a website to a new server. Note: This does require Growl and the GrowlNotify plug-in. I may rewrite it in the future support the Notification Centre in Mountain Lion and provide more options.
#!/bin/bash
echo "Enter the hostname you want to monitor (eg citypress.co.uk) and hit [ENTER]: "
read hostname
while true; do
newip=$(dig +short $hostname)
if [ "$newip" != "$previp" ]; then
if [ -z "$previp" ]; then
@simonpioli
simonpioli / thedate.php
Last active December 16, 2015 16:49
mySQL Date Format in PHP. Because I'm fed up of Googling it all the time!
<?php
//To mySQL Format
date("Y-m-d H:i:s", $datetime);
//Back to legible
date("d/m/Y", strtotime($datetime));
@simonpioli
simonpioli / database-backup.php
Created June 21, 2013 09:45
Retrieves Content from mySQL database and saves as a .sql file. c/o @darkwing
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
backup_tables('localhost','username','password','database');
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
@simonpioli
simonpioli / wp-excerpts.php
Last active December 18, 2015 19:29
Allows you to specify the excerpt length per page rather than through a global setting in your functions.php.
<?php
/** In functions.php **/
/**
* Customise Excerpt Length
* @param int $new_length Length of excerpt
* @param mixed $new_more String to output at the end of the excerpt, if false reverts to default
* @return type
*/