Skip to content

Instantly share code, notes, and snippets.

View tbassetto's full-sized avatar

Thomas Bassetto tbassetto

View GitHub Profile
@mauricesvay
mauricesvay / gist:736880
Created December 10, 2010 21:53
Abusing localStorage to build an aggressive cache
var assets = [
'http://localhost/offline-assets/fancybox/jquery.fancybox-1.3.4.js',
'http://localhost/offline-assets/fancybox/jquery.fancybox-1.3.4.css'
];
for (var i=0,l=assets.length; i<l; i++) {
loadAsset(assets[i]);
}
function loadAsset(url){
@andrew8088
andrew8088 / oop.js
Created December 12, 2010 02:15
OOP in JS
var tooltip_button = {
show : function () {
this.panel.show();
},
hide : function () {
this.panel.hide();
},
bind_events : function () {
var that = this;
this.button.bind("mouseover.Tooltip_Button", function () { that.show.call(that); });
@sstephenson
sstephenson / back_forward.js
Created December 13, 2010 21:55
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@creationix
creationix / inspect.js
Created December 23, 2010 06:51
a custom object inspector to help me understand JavaScript
function escapeString(string) {
string = string.replace(/\\/g, "\\\\").
replace(/\n/g, "\\n").
replace(/\r/g, "\\r").
replace(/\t/g, "\\t");
if (string.indexOf("'") < 0) {
return "'" + string + "'";
}
string = string.replace(/"/g, "\\\"");
return '"' + string + '"';
@creationix
creationix / find.js
Created December 24, 2010 23:49
Find all references to an object.
function find(root, obj) {
var seen = [];
function search(root, name, depth) {
if (root === obj) {
console.log(name);
return;
}
if (!depth) { return; }
if (seen.indexOf(root) >= 0) { return; }
if (typeof root !== "object") { return; }
@joemccann
joemccann / phonegap_sencha_tutorial.md
Created January 31, 2011 20:19
Quick setup of Phonegap and Sencha tutorial.

Note: You need to be on a Mac.

Note: This is purposely verbose. Yes, I know a lot of this can be simplified. Fork it and show me.

  1. Install git
  2. Open your terminal.
  3. mkdir ~/Documents/phonegap_sencha
  4. cd ~/Documents/phonegap_sencha
  5. git clone https://github.com/phonegap/phonegap-iphone.git && cd phonegap-iphone
  6. git reset --hard HEAD
@rwaldron
rwaldron / h264.html
Created February 3, 2011 00:06
H264 Support Revision
<!DOCTYPE html>
<html>
<head>
<title>H264</title>
<script src="h264.js"></script>
</head>
<body>
@mklabs
mklabs / simple-cache-system.js
Created February 12, 2011 14:23
A module that acts as a service to request localy stored markdown file, this version includes a simple cache wrapper
var markdownService =(function(){
var cache = function(fn){
var c = {};
return function(file, cb) {
var item = c[file],
_cb = cb,
cb = function(r) {
var cFile = c[file];
@tmahesh
tmahesh / measurePageloadTimes.js
Created February 18, 2011 00:56
How fast is my site? integrate boomerang and google analytics
<script type="text/javascript">
BOOMR.init({
beacon_url: "/boomerang.gif",
BW: {
enabled: false
}
});
BOOMR.subscribe('before_beacon', trackInAnalytics);
var pageType = "homepage"; // customize this
@louisremi
louisremi / which form.js
Created February 23, 2011 07:39
Why is IE9 Another Thorn in our Side?
/*
* margin-top or marginTop?
* When to use lower-case and camel-case property names in JavaScript.
*/
// Setting style: camel-case
elem.style.marginTop = '10px';
// Getting style: camel-case
var value = elem.style.marginTop;