Skip to content

Instantly share code, notes, and snippets.

View vinaydotblog's full-sized avatar
🏠
Working from home

Vinay Aggarwal vinaydotblog

🏠
Working from home
View GitHub Profile
// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
}
};
@vinaydotblog
vinaydotblog / gist:2427646
Created April 20, 2012 10:25
CSS Clearfix
/* Easy Clearfix from HTML5 boilerplate : h5bp.com/css */
/* Contain floats: h5bp.com/q */
.clearfix:before, .clearfix:after { content: ""; display: table; }
.clearfix:after { clear: both; }
.clearfix { *zoom: 1; }
@vinaydotblog
vinaydotblog / Menified localStorage Utility
Created May 2, 2012 09:12
Handy function for using localStorage and added support for storing Objects and arrays.
var local=function(a,u){return function(b,c){if(a===u)return;if(!c){try{return JSON.parse(a.getItem(b))}catch(d){}return a.getItem(b)}try{return a.setItem(b,JSON.stringify(c))}catch(d){}return a.setItem(b,c)}}(window.localStorage)
@vinaydotblog
vinaydotblog / gist:2626136
Created May 7, 2012 05:45
Key up delay function
// Delay function to call up on every keyup.
// Solution to this: http://stackoverflow.com/questions/1909441/jquery-keyup-delay
// jQuery 1.7.1 or up required *
jQuery.fn.keyupDelay = function( cb, delay ){
if(delay == null){
delay = 400;
}
var timer = 0;
return $(this).on('keyup',function(){
@vinaydotblog
vinaydotblog / gist:2643824
Created May 9, 2012 11:17
CSS3 #loading overlay
<style type="text/css">
#loading{
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
background:#e6e6e6;
opacity:.8;
@vinaydotblog
vinaydotblog / gist:2693179
Created May 14, 2012 10:32
Generate random hex color
// Simplest and fastest way to generate random hex color
// Taken from http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript
var randomHexColor = function(){
var color = '#', i = 5;
do{ color += "0123456789abcdef".substr(Math.random() * 16,1); }while(i--);
return color;
}
@vinaydotblog
vinaydotblog / gist:2700636
Created May 15, 2012 10:23 — forked from paulirish/gist:373253
jquery invert
// jquery invert plugin
// by paul irish
// some (bad) code from this css color inverter
// http://plugins.jquery.com/project/invert-color
// some better code via Opera to inverse images via canvas
// http://dev.opera.com/articles/view/html-5-canvas-the-basics/#insertingimages
// and some imagesLoaded stuff from me
// http://gist.github.com/268257
@vinaydotblog
vinaydotblog / gist:2887204
Created June 7, 2012 07:39
HTML Lil Template
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
html,body{ height:100%; background-color:#F6f6f6; margin:0; padding:0; overflow-y:scroll; }
div.wrapper{width: 960px; min-height:100%; margin:0 auto; position:relative; }
header{ height:73px; border-bottom:2px solid #222; }
header h1{ margin:0; font-family:cambria; line-height: 73px; }
@vinaydotblog
vinaydotblog / gist:2899329
Created June 9, 2012 03:57
Console Log Wrapper
/*
log function for easy logging with multi parameter support
and printf like string substitution: check usage at bottom
Useful for iphone / ipad simulator where multi params not natively supported
Now also supports logging of DOM objects in iOS
*/
window.log = (function(){
var dom_log = function(obj){
var name = obj.nodeName.toLowerCase(),
@vinaydotblog
vinaydotblog / gist:3082912
Created July 10, 2012 12:04
Function to sort array of objects by property name of each object
// Uses Prototype Inheritance
Array.prototype.sortByProp = function(p){
return this.sort(function(a,b){
return a[p] > b[p] ? 1 : a[p] < b[p] ? -1 : 0;
});
}
/* Usage - Example */