Skip to content

Instantly share code, notes, and snippets.

@gaelbillon
gaelbillon / getLocalStorageSize.js
Created September 25, 2012 10:43
get localstorage size
function getLocalStorageSize () {
function bytesToSize(bytes) { // from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@gaelbillon
gaelbillon / gist:3781339
Created September 25, 2012 11:58
get localstorage size bookmarklet
<a href="javascript:localStorageSize=null;for(var a=0;a<localStorage.length;a++)localStorageSize+=localStorage.getItem(localStorage.key(a)).length;var b=localStorageSize,c=['Bytes','KB','MB','GB','TB'];if(0==b)localStorageSize='n/a';else{var d=parseInt(Math.floor(Math.log(b)/Math.log(1024)),10);localStorageSize=0==d?b+' '+c[d]:(b/Math.pow(1024,d)).toFixed(1)+' '+c[d]}alert('localStorage is : '+localStorageSize);">localStorage Size</a>
@gaelbillon
gaelbillon / gist:3781364
Created September 25, 2012 12:05
log window width & height on resize (paste in console & resize)
window.onresize = function(event) {
console.log("x: " + window.innerWidth+" y: " + window.innerHeight);
}
@gaelbillon
gaelbillon / .htaccess
Created September 29, 2012 13:56
custom htaccess for speed, cache, gzip, ETags, etc
### ENVIRONMENT VARIABLES ###
SetEnv PHP_VER 5
SetEnv REGISTER_GLOBALS 0
### MAIN DEFAULTS ###
Options All -Indexes
DirectoryIndex index.html index.htm index.php
AddDefaultCharset UTF-8
### MIME TYPES ###
@gaelbillon
gaelbillon / gist:3810851
Created October 1, 2012 10:39
get dom size
document.body.parentNode.outerHTML.length
@gaelbillon
gaelbillon / gist:4344325
Created December 20, 2012 10:01
Jquery toggle cheat Key combination to show/hide a div
// Press "right arrow" -> "down arrow" -> "lowercase o" to show hide a div
$('body').bind('keydown', function(e) {
if (typeof(keyPressed) == "undefined") {
keyPressed = [];
}
var code = (e.keyCode ? e.keyCode : e.which);
keyPressed.push(code);
if (keyPressed.length === 3) {
if (keyPressed[0] === 39 && keyPressed[1] === 40 && keyPressed[2] === 79) {
$('#bloc_users').toggle()
@gaelbillon
gaelbillon / gist:4344343
Created December 20, 2012 10:02
MySQL ID -> UUID trigger
CREATE TRIGGER
newid
BEFORE INSERT ON
table_name
FOR EACH ROW
SET NEW.id = UUID()
@gaelbillon
gaelbillon / gist:4344374
Created December 20, 2012 10:06
Android command line : uninstall -> clean -> build -> install -> run
android update project -p . -s -t android-16
cp ../xxx/mobile/final_version assets/www
adb uninstall com.xxxx.xxxx
ant clean
ant debug
adb install bin/xxxxg.apk
adb shell am start -n com.xxxx.xxxx/com.xxxx.xxxx.xxxx (last xxxx is activity name)
@gaelbillon
gaelbillon / gist:5160049
Created March 14, 2013 09:32
device test javascript, css, base64 picture, base64 audio
<html>
<head>
<style media="screen" type="text/css">
h1 {
color: darkgrey;
background-color: lightgrey;
}
h2 {
@gaelbillon
gaelbillon / Angular directive : keep old value if no change
Created May 28, 2013 09:29
could be useful in case of eg: websockets pushing data that can randomly be defined or undefined, if the new value coming in is undefined, this directive keep the old value displayed.
angular.module('myApp.directives', []).
directive('keepoldvalueifnewisempty', function() {
return {
restrict: "E",
link: function(scope, elm, attrs) {
scope.$watch(attrs.val, function (newValue, oldValue) {
newValue = !newValue ? oldValue : newValue;
elm.html(newValue);
});
}