Skip to content

Instantly share code, notes, and snippets.

View remy's full-sized avatar
🌮
Hack. Learn. Fix. Teach.

Remy Sharp remy

🌮
Hack. Learn. Fix. Teach.
View GitHub Profile
// whilst in firebug, try:
var console = {}; // or, well - anything actually...
// note the number to the left of the 'e', 7 and 8 respectively
alert( 1.7976931348623157e+308 === 1.7976931348623158e+308 ); // true!
var _width = $.fn.width;
$.fn.width = function () {
debbugger; // triggers a break point
_width.apply(this, arguments); // continue with execution
};
@remy
remy / gist:312540
Created February 23, 2010 18:39
Bookmarklet for injecting entire web pages to JS Bin
javascript:(function(){var b=document.createElement("form");b.action="http://jsbin.com";b.method="post";var a=document.createElement("input");a.type="hidden";a.value="<!DOCTYPE html><html>"+document.documentElement.innerHTML+"</html>";a.name="html";b.appendChild(a);a=document.createElement("input");a.type="hidden";a.value="true";a.name="inject";b.appendChild(a);b.submit()})();
// Google closure compiler 1000 to 1E3 - love it!
1000 === 1E3; // true
(function(window, document, undefined) {
// Enable all HTML5 elements in IE. For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/
/*@cc_on'abbr article aside audio canvas details figcaption figure footer header hgroup mark menu meter nav output progress section summary time video'.replace(/\w+/g,function(n){document.createElement(n)})@*/
if (![].forEach) {
Array.prototype.forEach = function (fn) {
var len = this.length || 0, that = arguments[1];
if (typeof fn == 'function') {
for (var i = 0; i < len; i++) {
@remy
remy / view-source.js
Created March 4, 2010 10:05
Save this a bookmarklet on your iPhone or desktop browser to view the source to the current page
// bookmarklet to introspect the source of current page
javascript:(function(d,h){h=d.documentElement.innerHTML;d.open();d.write('<pre>'+('<!DOCTYPE html><html>'+h+'</html>').replace(/[<>]/g,function(m){return{'<':'&lt;','>':'&gt;'}[m]})+'</pre>')})(document);
@remy
remy / gist:330318
Created March 12, 2010 13:59
autofocus and placeholder support
/**
* Add this script to the end of your document that use <input autofocus type="text" />
* or <input type="text" placeholder="username" /> and it'll plug support for browser
* without these attributes
* Minified version at the bottom
*/
(function () {
function each(list, fn) {
var l = list.length;
@remy
remy / gist:330584
Created March 12, 2010 18:13
Shuffle an array, not the best, but will do
function shuffle(array) {
var newArray = [], i;
while (array.length) {
i = ~~(Math.random() * array.length);
newArray.push(array[i]);
array = array.slice(0, i).concat( array.slice(i+1) );
}
return newArray;
}
@remy
remy / gist:333954
Created March 16, 2010 13:21 — forked from madrobby/gist:333764
Beautiful one line array shuffle
// pure JS
function shuffle(array) {
return array.sort(function(){
return .5 - Math.random();
});
}
// with Prototype.js you can do
function shuffle(array){
return array.sortBy(Math.random);