Skip to content

Instantly share code, notes, and snippets.

View adamrobbie's full-sized avatar

Adam Robbie adamrobbie

View GitHub Profile
function PrefixInteger(num, length) {
return (Array(length).join('0') + num).slice(-length);
}
@adamrobbie
adamrobbie / guid.js
Created June 24, 2012 23:24
generate static guid via javascript
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
var myID = "static" + guid();
@adamrobbie
adamrobbie / reset.css
Created June 26, 2012 16:25
The CSS Reset
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@adamrobbie
adamrobbie / getClass.js
Created June 27, 2012 14:32
Utility method to get class of any JS object
function getClass(obj) {
if (typeof obj === "undefined")
return "undefined";
if (obj === null)
return "null";
return Object.prototype.toString.call(obj)
.match(/^\[object\s(.*)\]$/)[1];
}
getClass("") === "String";
@adamrobbie
adamrobbie / cookie.js
Created June 27, 2012 14:53
JS Cookie utility functions [get, set, delete]
@adamrobbie
adamrobbie / loadAsynchronousJS.js
Created June 28, 2012 17:24
js to load js without blocking .onload() via Stoyan
(function(url){ var iframe = document.createElement('iframe'); (iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0"; var where = document.getElementsByTagName('script'); where = where[where.length - 1]; where.parentNode.insertBefore(iframe, where); var doc = iframe.contentWindow.document; doc.open().write('<body onload="'+ 'var js = document.createElement(\'script\');'+ 'js.src = \''+ url +'\';'+ 'document.body.appendChild(js);">'); doc.close(); })('http://www.jspatterns.com/files/meebo/asyncjs1.php');
@adamrobbie
adamrobbie / getParametersByName.js
Created June 28, 2012 16:04
javascript, get URL paramters
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
@adamrobbie
adamrobbie / htmlentity.txt
Created June 29, 2012 17:15
html entity reference
Name Character Entity
Copyright © &copy;
Registered ® &reg;
Trademark ™ &trade;
Curly Open Double Quote “ &ldquo;
Curly Closed Double Quote ” &rdquo;
Curly Open Single Quote ‘ &lsquo;
Curly Closed Single Quote ’ &rsquo;
Big Bullet/Dot • &bull;
Small Bullet/Dot · &middot;
@adamrobbie
adamrobbie / readmeTutorial.txt
Created July 11, 2012 16:23
How to write a good README
Here's what I think it should include:
name of the projects and all sub-modules and libraries (sometimes they are named different and very confusing to new users)
descriptions of all the project, and all sub-modules and libraries
5-line code snippet on how its used (if it's a library)
copyright and licensing information (or "Read LICENSE")
instruction to grab the documentation
instructions to install, configure, and to run the programs
instruction to grab the latest code and detailed instructions to build it (or quick overview and "Read INSTALL")
list of authors or "Read AUTHORS"
@adamrobbie
adamrobbie / remove_non_alphas.rb
Created July 26, 2012 15:40
Reg ex expression to parse text removing all non-alphabet characters
message = message.gsub(/[^0-9a-z]/i, '')