Skip to content

Instantly share code, notes, and snippets.

Avatar

Ian Channing ianchanning

View GitHub Profile
@ianchanning
ianchanning / ping.php
Created Jun 14, 2013
PHP Ping Packets
View ping.php
<?php
/**
* Ping a host using an IMCP packet
*
* N.B. This function must be called by an administrator / root user as socket_create requires this
*
* @param string $host domain
* @param integer $timeout seconds
* @return mixed False | Response time milliseconds
*
@ianchanning
ianchanning / svn_upgrade_wordpress.sh
Last active Dec 24, 2015
For upgrading WordPress when you've got a subversion installation. Backs up the database then upgrades WordPress to the specified version. A bit odd having subversion commands on github... but hey.
View svn_upgrade_wordpress.sh
#!/bin/bash
# usage: svn_upgrade_wordpress.sh X.X.X
# http://codex.wordpress.org/Installing/Updating_WordPress_with_Subversion
# licence MIT
die () {
echo >&2 "$@"
exit 1
}
@ianchanning
ianchanning / row_toggle.js
Last active Feb 14, 2020
Pure JavaScript hierarchical table row toggling (plus older jQuery version too)
View row_toggle.js
/**
* Hierarchical table rows object
*
* Pure JavaScript - but comes with a IE9+ warning
*
* @param {object} options tableSelector e.g. 'table'
* parentClass e.g. 'parent'
* collapsedClass e.g. 'hidden'
* childClassPrefix e.g. 'parentId'
* @type function
View app.js
$(function() {
var form = $("form");
var button = form.find("button[type=submit]");
var input = form.find("input[name=postcode]");
var output = form.find("output[name=location]");
var map = L.mapbox.map("map", "hubbox.map-u557d78b").setView([54, 0], 6);
var failed = function(data) {
button.html("Failed");
@ianchanning
ianchanning / upgrade_translated_wordpress_skeleton.sh
Last active Aug 29, 2015
Upgrade a translated installation of WordPress-Skeleton
View upgrade_translated_wordpress_skeleton.sh
#!/bin/bash
# usage: upgrade_wordpress.sh X.X.X
# This is for upgrading a translated version of WordPress whilst using WordPress-Skeleton
# https://github.com/markjaquith/WordPress-Skeleton
# https://core.trac.wordpress.org/ticket/27752
# licence MIT
die () {
echo >&2 "$@"
exit 1
View RiverReader
<!DOCTYPE html>
<html>
<head>
<title>Minimal River Reader</title>
<script src="http://fargo.io/code/jquery-1.9.1.min.js"></script>
</head>
<body>
<script>
var theRiver;
function onGetRiverStream (updatedFeeds) {
@ianchanning
ianchanning / printf.js
Created Jul 20, 2014
printf JavaScript
View printf.js
if (!String.format) {
/**
* printf function
* @link http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format
* @example var fullName = String.format('{0} {1}', firstName, lastName);
*
* @param {string} format String with replacable parameters
* @returns {string} formatted string
*/
String.format = function(format) {
@ianchanning
ianchanning / db_swap.bat
Created Aug 10, 2014
Rename a local SQL Server instance
View db_swap.bat
@ECHO OFF
REM detach, rename and reattach one database to another
REM @author ICC 11 Sep 09
REM @param sting Server name i.e. <Computer Name>\<SQL Server Name> e.g. .\SQLEXPRESS or COCO\SQLEXPRESS
REM @param string Existing database name e.g. mydb
REM @param string New database name e.g. mydb2
REM @return none renames database, detaches database files, renames them and reattaches
REM usage db_swap.bat .\SQLEXPRESS mydb mydb2
REM *** The following error occurs if you use a forward slash not a back slash
@ianchanning
ianchanning / minecraft-backup-user-saves.bat
Last active Aug 29, 2015
Backup the minecraft saves directory (uses 7-zip)
View minecraft-backup-user-saves.bat
@ECHO OFF
REM Backup the mincraft saves directory (uses 7-zip)
REM @author ICC 10 Aug 2014
REM @licence MIT
REM usage backs up the user saves directory to the current directory
REM gives the filename .minecraft-saves.[User]-[Computer]-YYYY-MM-DD.bak.7z
REM create date in YYYY-MM-DD format
FOR /f "tokens=1-3 delims=/ " %%a IN ('date /t') DO (SET today=%%c-%%b-%%a)
REM Computer name
@ianchanning
ianchanning / startserver.bat
Created Aug 10, 2014
Custom Minecraft server script with banned until date and IP address
View startserver.bat
@echo off
REM Start server script that won't start before a certain date and gives the IP address
REM current date
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set olddate=%%a-%%b-%%c)
REM The server will run on or after this date
set newdate=02-08-2014
set "sdate1=%olddate:~-4%%olddate:~3,2%%olddate:~0,2%"
set "sdate2=%newdate:~-4%%newdate:~3,2%%newdate:~0,2%"