Skip to content

Instantly share code, notes, and snippets.

@glynrob
glynrob / apicheck.py
Created July 28, 2012 20:18
Checks an API and sends the a returning colour dependant on the result
#!/usr/bin/python
import subprocess
import time
import urllib
import usblamp
import signal
import sys
@glynrob
glynrob / Memcache-check
Created September 6, 2012 22:08
Check connection to memcache server
$memcache = new Memcache;
$memcache->connect("localhost",11211);
echo "Server's version: " . $memcache->getVersion() . "<br />\n";
$data = 'This is working';
$memcache->set("key",$data,false,10);
echo "cache expires in 10 seconds<br />\n";
@glynrob
glynrob / Memcache-Comparison
Created September 6, 2012 22:11
Memcache Comparison in Codeigniter
$cachetime = 10; // number of seconds to cache for
$data = array();
$data['cachereset'] = 0;
// cache calls
$startTime = microtime(true);
$this->load->driver('cache');
$cache = $this->cache->memcached->get('alluserscount');
if (!$cache){
$data['cachereset'] = 1;
@glynrob
glynrob / Memcached-config
Created September 22, 2012 16:43
Multiple instances of memcached
$config= array(
'default' => array(
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 80
),
'server_1' => array(
'host' => '127.0.0.2',
'port' => 11211,
'weight' => 50
@glynrob
glynrob / gist:4466906
Created January 6, 2013 12:49
List Webapp manifest html
<!DOCTYPE html>
<html manifest="wsdemo.manifest">
<head>
<meta name="viewport" content="width=device-width">
@glynrob
glynrob / gist:4466921
Created January 6, 2013 12:50
Web storage list example
window.addEventListener("DOMContentLoaded", loadSavedData, false);// load locally saved data when the page opens
// get the locally saved data
function loadSavedData(){
savedData = localStorage.getItem("data"); // get data from local storage
if (savedData && savedData != null) { // if not empty
savedData = JSON.parse(savedData); // get data from returned json string
savedData = savedData['dataToSave']; // set savedData from dataToSave item
showListItems();// Generate the list items and display
@glynrob
glynrob / gist:4466924
Created January 6, 2013 12:51
List Webapp save data with Web storage
// save the new list locally
function saveLocally(dataToSave){
var cleanData = JSON.stringify({dataToSave: dataToSave}); // generate clean data
localStorage.setItem("data", cleanData); // save new data locally
showListItems(); // refresh the list display
showLocalData(); // update localdata display
}
@glynrob
glynrob / gist:4466926
Created January 6, 2013 12:52
List webapp detect if online
// display if they are online or not
if (!navigator.onLine){
$('#status').html('Offline');
} else {
$('#status').html('Online');
}
@glynrob
glynrob / gist:4519988
Created January 12, 2013 19:10
localStorage test function
function runStorageTest(){ // fill up all data in local storage to see how much we can squeeze in
localStorage.clear();
var i = 0;
var testPacket = new Array( 1025 ).join( "a" ); // create 1024 characters so 1KB
while (i<maxMBToTest){ // MB level
$('#currentDisplay').html(i+'Mb');
var t = 0;
while (t<1025){ // KB level
try {
localStorage.setItem(i+"|"+t, testPacket);
@glynrob
glynrob / gist:4520053
Created January 12, 2013 19:19
Get current size of localStorage
function sizeofAllStorage(){ // provide the size in bytes of the data currently stored
var size = 0;
for (i=0; i<=localStorage.length-1; i++)
{
key = localStorage.key(i);
size += lengthInUtf8Bytes(localStorage.getItem(key));
}
return size;
}