Skip to content

Instantly share code, notes, and snippets.

View leggetter's full-sized avatar

Phil Leggetter leggetter

View GitHub Profile
@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:769688
Created January 7, 2011 16:23
How to get the body of a HTTP Request using C#
private string GetDocumentContents(System.Web.HttpRequestBase Request)
{
string documentContents;
using (Stream receiveStream = Request.InputStream)
{
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
documentContents = readStream.ReadToEnd();
}
}
@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">
@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'];
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();
source 'http://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'pusher'
@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;
}
?>
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' );