Skip to content

Instantly share code, notes, and snippets.

View PhilKershaw's full-sized avatar

Phil Kershaw PhilKershaw

View GitHub Profile
@PhilKershaw
PhilKershaw / gist:1389041
Created November 23, 2011 15:57
Simple code for executing commands on a remote Linux server via SSH in PHP
<?php
/**
* Simple code for executing commands on a remote Linux server via SSH in PHP
*
* @author Phil Kershaw (In collaboration with Philip Mott)
*
* Note: ssh2_connect requires libssh2-php which is a non-standard PHP lib.
* Debian: apt-get install libssh2-php
* Redhat: yum install libssh2-php ???? I've no idea for redhat, sorry.
*/
@PhilKershaw
PhilKershaw / gist:1506328
Created December 21, 2011 15:00
Builds an array of ACL resources for Zend Framework - could be applied to other frameworks.
<?php
/**
* Zimo ACL Resources
* Complies an array of Modules/Controllers/Actions.
*
* @author Phil Kershaw
*/
class Zimo_Acl_Resources
{
/**
@PhilKershaw
PhilKershaw / gist:1647890
Created January 20, 2012 15:30
PHP Mongo extension class for AppFog
<?php
/**
* AppFogMongo Class
* Designed for AppFog Platform as a Service (PaaS). Obtains the connection details and esteblishes a connection to the Db. Extends PHPs Mongo Class.
*
* @author Phil Kershaw
*/
class AppFogMongo extends Mongo
{
/**
@PhilKershaw
PhilKershaw / gist:2171814
Created March 23, 2012 15:31
Simple example of using 2-legged OAuth in Node.js (requires node-oauth)
var express = require('express');
var oauth = require('oauth');
var app = express.createServer();
var key = "[api-key]";
var secret = "[api-secret]";
var request = new oauth.OAuth(null, null, key, secret, '1.0', null, 'HMAC-SHA1');
app.get('/api-request', function(req, res){
request.get(
"http://127.0.0.1:8000/api/1.0/data.json",
@PhilKershaw
PhilKershaw / gist:2351382
Created April 10, 2012 13:29
WordPress Post term list via AJAX
<?php
/*
* A demo function to compile a list of locations (WordPress Terms) based on a 'type' (also WordPress Terms: 'commercial', 'residential', 'land'). Requested and returned via AJAX.
*
* @author Phil Kershaw
*/
add_action('wp_ajax_get_locations', 'get_locations');
add_action('wp_ajax_nopriv_get_locations', 'get_locations');
function get_locations()
@PhilKershaw
PhilKershaw / Default (Windows).sublime-mousemap
Last active December 22, 2015 19:39
CTRL + [Double] Click function in Sublime Text 2/3. Maps the F12 (Windows) functionality to CTRL+[Double] Click. Create a file containing this JSON in the User preferences directory for Sublime Text: Windows: Default (Windows).sublime-mousemap Linux: Default (Linux).sublime-mousemap OS X: Default (OSX).sublime-mousemap
[
{
"button": "button1",
"count": 1,
"modifiers": ["super", "ctrl"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
@PhilKershaw
PhilKershaw / xhr.js
Created September 24, 2013 14:33
Sample xhr request
var formData = new FormData();
var str_url = '/ajax';
formData.append('id', int_id);
var xhr = new XMLHttpRequest();
xhr.open('POST', str_url, true);
xhr.onload = function(e) {
if (this.status == 200) {
if (/success/i.test(this.responseText)) {
alert('Category Box deleted successfully.');
} else {
@PhilKershaw
PhilKershaw / xhr-POST-with-file.js
Created October 8, 2013 11:35
Rought example of an xhr POST request with a file
var str_title = document.querySelector('#category_box_title').value;
var str_url = document.querySelector('#category_box_url').value;
var arr_image = document.querySelector('#category_box_image').files[0];
var int_id = document.querySelector('#category_box_id').value;
var formData = new FormData();
formData.append('title', str_title);
formData.append('url', str_url);
formData.append('image', arr_image);
formData.append('web_page_content_widget_id', int_selected_content_widget_id);
@PhilKershaw
PhilKershaw / _applyEntities.php
Last active December 29, 2015 00:19
Wrap URLs in tweets in a tags.
<?php
private static function _applyEntities(&$feed)
{
if (null !== $feed) {
foreach($feed as &$item) {
if (null !== $item['entities']['urls']) {
$urls = array_reverse($item['entities']['urls']);
$content = &$item['text'];
foreach ($urls as $url) {
$content = substr_replace($content, '</a>', $url['indices'][1], 0);
@PhilKershaw
PhilKershaw / available_times.php
Last active December 30, 2015 05:58
Showing call-back times for the whole week: Mon - Fri: 9am - 6pm Sat: 9am -5:30pm Sun: 11am - 5pm ...and breathe!
<?php
$available_times = array(
"09:00:00" => '<option value="%s 09:00:00">%s 9.00am - 10.00am</option>',
"10:00:00" => '<option value="%s 10:00:00">%s 10.00am - 11.00am</option>',
"11:00:00" => '<option value="%s 11:00:00">%s 11.00am - 12.00pm</option>',
"12:00:00" => '<option value="%s 12:00:00">%s 12.00pm - 1.00pm</option>',
"13:00:00" => '<option value="%s 13:00:00">%s 1.00pm - 2.00pm</option>',
"14:00:00" => '<option value="%s 14:00:00">%s 2.00pm - 3.00pm</option>',
"15:00:00" => '<option value="%s 15:00:00">%s 3.00pm - 4.00pm</option>',
"16:00:00" => '<option value="%s 16:00:00">%s 4.00pm - 5.00pm</option>',