Skip to content

Instantly share code, notes, and snippets.

View leggetter's full-sized avatar

Phil Leggetter leggetter

View GitHub Profile
@leggetter
leggetter / move.sh
Created April 30, 2013 20:37
Renames a bunch of files from one file extension to another.
for f in *.html.md; do
ff="${f%.html.md}.md"
test -e "$f" || continue # possible when not using nullglob
test "$f" != "$ff" || continue # possible when using nocaseglob
if test -e "$ff" &&
! test "$f" -ef "$ff"; then # possible on a case sensitive filesystem
echo "skipping <$f>: destination <$ff> exists and is distinct" 1>&2
continue
fi
package WWW::Pusher;
use warnings;
use strict;
use 5.008;
use JSON;
use URI;
use LWP::UserAgent;
@leggetter
leggetter / gist:5165792
Last active December 14, 2015 23:29
I'm trying to create a nice API that .NET developer would be happy using and would also instil confidence in the library by demonstrating good practice.
/*
Which one of the two `Get` method signatures should I go for? Or is there a better alternative?
The purpose of the `Get` method is to make a generic GET call to a REST API and hide away the authentication complexity. That's kind-of irrelevant here.
The 1st param in the call will always identify the resource
* Option 1: using `param KeyValuePair[]` so that multiple key value pairs can be passed to be convereted to name/value paris in a query string.
* Option 2: just uses an object created inline and can therefore have any keys/values it wants. But is it too magical?
var request = require('request');
var fs = require( 'fs' );
var path = require('path');
var WS_URL = 'http://api.ocrapiservice.com/1.0/rest/ocr';
SO2();
function SO2() {
var base64Str = fs.readFileSync( 'example.png' ).toString( 'base64' );
@leggetter
leggetter / http_file_get_contents.php
Last active December 10, 2015 01:35
cURL is the defacto standard for making HTTP requests using PHP. But there are alternatives. Here are a few.
<?php
function http_file_get_contents( $url ) {
$response = file_get_contents( $url );
return $response;
}
?>
source 'http://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'pusher'
com.pusher.define("com.pusher.test.framework", function(exports) {
/**
* Stub Pusher object.
*/
var Pusher = function(appKey, options) {
Pusher.instances.push(this);
this.connection = new Connection();
@leggetter
leggetter / auth.php
Created August 30, 2011 10:31
Pusher PHP Auth example
<?php
// https://github.com/squeeks/Pusher-PHP
require('squeeks-Pusher-PHP-0defb40/lib/Pusher.php');
$key = 'APP_KEY';
$secret = 'APP_SECRET';
$app_id = 'APP_ID';
$pusher = new Pusher($key, $secret, $app_id);
$channel_name = $_POST['channel_name'];
@leggetter
leggetter / jQuery-tablesort-example.html
Created February 5, 2011 13:46
Dynamically sorting a table with jQuery tablesorter plugin
<html>
<head>
<title>
jQuery v1.4.2 and jQuery tablesorter plugin sorting problem
</title>
</head>
<body>
<button id="add">Add Row</button>
<table class="tablesorter">
@leggetter
leggetter / gist:775811
Created January 12, 2011 07:27
Generic JavaScript and CSS file loader
var fileLoader= {
require:function(s) {
try{
// inserting via DOM fails in Safari 2.0, so brute force approach
if(s.type == "text/javascript") {
document.write('<script type="text/javascript" src="'+s.url+'"><\/script>');
} else {
document.write('<link rel="stylesheet" href="'+ s.url +'" />');
}
} catch(e) {