Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
@cowboy
cowboy / super-shrinkify.js
Created August 7, 2010 18:51
Super Shrinkify
// This might be useful for certain size-limited JS competitions, or not. #js
function super_shrinkify( str ){
if ( str.length % 2 ) {
str += ' ';
}
var prefix = '"',
suffix = '".replace(/./g,function(a){a=a.charCodeAt();return String.fromCharCode(a>>7,a%128)})',
str_bytes = unescape( encodeURIComponent( str ) ).length,
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);
@getify
getify / ex1:basic_@_usage
Created December 3, 2010 17:10
theoretical native promise/defer via @ operator (in JavaScript or something like it)
//SUMMARY:
// a() @ b() ==> execute a(). if a() flags an async deferral inside it,
// then wait to continue execution of the expression until that promise is
// fulfilled, then continue execution *AT* b().
//
// more generally: X @ Y ==> evaluate X expression. if it was a function call
// call that deferred with a promise, wait until fulfilled then continue at
// Y. otherwise, assume that X had an implicit immediately fulfilled promise,
// and continue evaluating at Y.
// ------
/*
* matchMedia() polyfill - test whether a CSS media type or media query applies
* primary author: Scott Jehl
* Copyright (c) 2010 Filament Group, Inc
* MIT license
* adapted by Paul Irish to use the matchMedia API
* http://dev.w3.org/csswg/cssom-view/#dom-window-matchmedia
* which webkit now supports: http://trac.webkit.org/changeset/72552
*
* Doesn't implement media.type as there's no way for crossbrowser property
function noteval(code, doc){
// add some javascript to a document, like an iframe
//
// var iframe = document.getElementById("theframe");
// noteval('alert("hi")', iframe.contentDocument || iframe.)
var e = doc.createElement("script"),
how = "text" in e ? "text" :
"textContent" in e ? "textContent" :
@dangoor
dangoor / gist:960170
Created May 7, 2011 03:24
JS.next modules - no loader required
// LABjs style
<script src="js/LAB.min.js"></script>
<script>
$LAB
.script("underscore.js")
.script("jquery.js")
.script("mycode.js")
.wait(function() {
//do something
@140bytes
140bytes / LICENSE.txt
Created May 9, 2011 16:13
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@rwaldron
rwaldron / raf.js
Last active March 1, 2018 10:04
requestAnimationFrame, browser prefix detection
var rAF = "equestAnimationFrame";
window["r"+rAF] = window["r"+rAF] ||
window["webkitR"+rAF] ||
window["mozR"+rAF] ||
window["msR"+rAF] ||
window["oR"+rAF];
// A list
@getify
getify / gist:1171666
Created August 25, 2011 19:50
break down (and counts) of user-agents seen so far in golook.at logs
LABEL LABEL2 UNIQUE UA's # OF USES
(empty) - 1 20553
(unrecognized) - 740 10789
(bots) - 354 111898
Clients - 513 1727
Windows (other) 39 166
Windows IE 12301 94162
Windows Chrome 770 23069
Windows Safari 99 541
Windows Opera 553 3645