Skip to content

Instantly share code, notes, and snippets.

View leggetter's full-sized avatar

Phil Leggetter leggetter

View GitHub Profile
@leggetter
leggetter / socket-io-namespace.md
Created July 1, 2014 17:58
Should the following result in so many connections being made to the Socket.IO server?

I'm trying to use Socket.IO with namespaces in order to partition the data. See the following code:

<script src="https://cdn.socket.io/socket.io-1.0.6.js"></script>
<script>
var webglStats = io( '/webgl' );
var videoStats = io( '/video' );
var touchStats = io( '/touch' );
</script>
@leggetter
leggetter / stickerify.html
Created October 1, 2014 09:59
Grokking Promises
<!doctype html>
<html>
<head>
<title>Stickerify</title>
</head>
<body>
<ul id="stickers">
</ul>
@leggetter
leggetter / replay-api-messages.js
Created November 3, 2014 21:02
Add "Replay" button to API Messages in Pusher Debug Console
// ==UserScript==
// @name Pusher Debug Console Enhancements
// @namespace http://www.leggetter.co.uk
// @version 0.1
// @description Add a button to the Pusher JavaScript console that lets you replay API Messages
// @author Phil @leggetter
// @match https://app.pusher.com/apps/*/console
// @grant none
// ==/UserScript==
@leggetter
leggetter / pusher-channel-regexp.js
Created November 9, 2014 18:07
Pusher Valid Channel Name Regexp
var pusherChannelRegexp = /[\w_\-\=@,\.;]+/;
var result = pusherChannelRegexp.test( 'foo-bar_1234@=,.;' );
console.log( result );
@leggetter
leggetter / pusher.js
Created January 15, 2015 01:04
pusher-js 2.2.3 but with a returnExportsGlobal UMD header which means it should work in browsers by Pusher being available as a global and with Browserify with CommonJS style require syntax. AMD has not been tested.
/*!
* Pusher JavaScript Library v2.2.3-umd
* http://pusher.com/
*
* Copyright 2014, Pusher
* Released under the MIT licence.
*/
// Uses Node, AMD or browser globals to create a module. This example creates
// a global even when AMD is used. This is useful if you have some scripts
@leggetter
leggetter / client.html
Created June 13, 2015 11:38
How easy it is to integrate Pusher
<script src="//js.pusher.com/2.2/pusher.min.js"></script>
<script>
var pusher = new Pusher('YOUR_APP_KEY');
var channel = pusher.subscribe('test_channel');
channel.bind('my_event', function(data) {
// do something awesome with data
// e.g. showNotification(data.msg)
});
</script>
@leggetter
leggetter / index.html
Created December 7, 2010 16:38
A really simple example of how to use the Kwwika JavaScript API within a webOS application.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>sampleApp</title>
<script src="ares.js" type="text/javascript"></script>
<script src="http://js.kwwika.com/staging/api.js" type="text/javascript"></script>
<script>
@leggetter
leggetter / gist:775792
Created January 12, 2011 06:55
How to dynamically load JavaScript and CSS
var OptaAshes = {
scriptBase: "widget/",
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 +'" />');
}
@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) {
@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">