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
@jorendorff
jorendorff / gist:9192015
Last active August 29, 2015 13:56 — forked from getify/gist:9105362
function* range(start, stop, step=1) {
for (var i = start; i < stop; i += step)
yield i;
}
for (var n of range(0, 100, 3))
console.log(n);
@nzakas
nzakas / simplemap.js
Created April 3, 2014 17:38
A simple map implementation for JavaScript (not intended to be an ES6 polyfill)
function SimpleMap() {
this._data = {};
}
SimpleMap.prototype = {
get: function(key) {
return this.has(key) ? this._data[key] : null;
},
@smockle
smockle / grips.md
Last active August 29, 2015 14:01
The idea behind Grips is that HTML templating and CSS preprocessing can be pretty much the same. Very neat.

Here are some thoughts I had after reading through the slides and gist:

  1. I don't think I'd often use *prop. I don't keep track of which properties/values need vendor prefixes (or nonstandard code) to work with the browsers I'm targeting. I use Autoprefixer, which uses data from the Can I Use? database.
  2. A command that generates JSON with keys representing the variable names used in a .gcss file would be handy.
  3. I feel like I missed the point of storing style variables in JSON. One benefit is "different site themes"--but most of my projects include a "_variables.scss" file that could be swapped out--oh, but that would require recompiling scss. I see. I think I get it now. Never mind!
function foo(){}
foo.prototype = 2;
Object.defineProperty(foo,"prototype",{writable:false});
Object.getOwnPropertyDescriptor(foo,"prototype"); // Object {value: 2, writable: false, enumerable: false, configurable: false}
foo.prototype; // 2
function bar(){}
Object.defineProperty(bar,"prototype",{value:2,writable:false});
@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,
@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.
// ------
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
@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
@getify
getify / bar.js
Created August 26, 2011 19:27
how to use LABjs to load nested resources serially, with callbacks
// look ma, I have no dependencies, no need for any wrappers!
alert("bar.js is loaded!");