Skip to content

Instantly share code, notes, and snippets.

@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: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: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 / 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 / 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 / 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 / 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 / colourloop.py
Created July 28, 2012 20:16
Loop through all colours in an array
#!/usr/bin/python
import subprocess
import time
import usblamp
checkTime = 1
arr = ("white", "yellow", "red", "blue", "green")
for i in arr:
@glynrob
glynrob / Example hosts file
Created June 30, 2012 18:20
setup example1.sdev in your hosts file
127.0.0.1 example1.sdev
@glynrob
glynrob / Example vhost
Created June 30, 2012 18:05
Example vhost for WAMP
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/example1.sdev/"
ServerName example1.sdev
<directory "c:/wamp/www/example1.sdev/">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>