Skip to content

Instantly share code, notes, and snippets.

@sang4lv
sang4lv / gist:4466191
Created January 6, 2013 09:03
Express Error
Angelas-Mac:~ angelazou$ sudo npm install -g [email protected]
Password:
npm http GET https://registry.npmjs.org/express/2.5.8
npm http 200 https://registry.npmjs.org/express/2.5.8
npm http GET https://registry.npmjs.org/express/-/express-2.5.8.tgz
npm http 200 https://registry.npmjs.org/express/-/express-2.5.8.tgz
npm WARN engine [email protected]: wanted: {"node":">= 0.4.1 < 0.7.0"} (current: {"node":"v0.8.16","npm":"1.1.69"})
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/mime/1.2.4
npm http GET https://registry.npmjs.org/qs
@sang4lv
sang4lv / gist:4461076
Created January 5, 2013 11:16
applicationCache: Overview
var appCache = window.applicationCache;
//Update when ready
appCache.onupdateready = function() {
if(appCache.status == 'UPDATEREADY') {
appCache.swapCache();
if(confirm("New content available. Reload to show?")) {
window.location.reload();
}
}
@sang4lv
sang4lv / gist:4460999
Created January 5, 2013 11:00
Server sent events (SSE): Overview
var serverEvent = new EventSource("http://example.com/eventsource.php"); //CORS is supported
serverEvent.onerror = function(event) {
console.log(event.target.errorCode);
};
serverEvent.onopen = function() {
console.log("Connection has been established");
};
@sang4lv
sang4lv / gist:4460459
Created January 5, 2013 08:06
Manifest File: Overview
CACHE MANIFEST
CACHE: #Explicitly Cached after first download
sample1.png #Use version number to notify update/modification on file
sample2.png
NETWORK: #Items that must be retrieved from the server, regardless of the connection
sample3.png
@sang4lv
sang4lv / gist:4451534
Created January 4, 2013 10:26
Geolocation: Everything
function gotLocation(position) {
console.log("I am at latitude " + position.coords.latitude + ", longitude " + position.coords.longitude + ", and accurate within " + position.coords.accuracy + " meter(s).");
}
function handleLocationError(event) {
switch(event.errorCode) {
case 0:
console.log("We have an unknown error...");
break;
case 1:
@sang4lv
sang4lv / gist:4444696
Created January 3, 2013 16:26
IndexedDB: Add, Delete, and Get from Object Store
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
if(!window.indexedDB) {
console.log("IndexDB is not supported on your browser");
}
function reportError(event) {
console.log("Error with Database. " + event.target.errorCode);
}
@sang4lv
sang4lv / gist:4443484
Created January 3, 2013 13:32
Web Sockets: Introduction
var connection = new WebSocket('ws://html5rocks.websocket.org/echo', ['soap', 'xmpp']);
connection.onerror = function (error) {
console.log('WebSocket Error ' + error);
};
connection.onmessage = function (e) {
console.log('Server: ' + e.data);
};
function sendData(type, content) {
@sang4lv
sang4lv / gist:4442964
Last active December 10, 2015 13:48
Ajax Level 2: Sending large files fast
function upload(blobOrFile) {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/server', true);
xhr.onload = function(e) { console.log("Upload has finished."); };
xhr.send(blobOrFile);
}
document.querySelector('input[type="file"]').addEventListener('change', function(e) {
var blob = this.files[0];
@sang4lv
sang4lv / gist:4442953
Created January 3, 2013 11:52
Ajax Level 2: Send Form Data
function sendForm(form) {
var formContent = new FormData(form); //Get existing form content. Optional argument
formContent.append("hiddenId", "1234");
formContent.append("iceCream", "Vanilla");
formContent.append("currentLocation", "1223084.284|1209843.239");
var progressBar = document.querySelector("progress");
var xhr = new XMLHTTPRequest();
xhr.open("POST", "server.php", true);
xhr.send(formContent);
@sang4lv
sang4lv / gist:4442930
Created January 3, 2013 11:45
Ajax Level 2: Handling BLOB Data
window.URL = window.URL || window.webkitURL; // Take care of vendor prefixes.
var xhr = new XMLHttpRequest();
xhr.open('GET', '/path/to/image.png', true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
var blob = this.response;