Skip to content

Instantly share code, notes, and snippets.

View GarrettS's full-sized avatar

Garrett Smith GarrettS

View GitHub Profile
@GarrettS
GarrettS / Variable Speed for YouTube
Last active August 27, 2015 17:56
Bookmarklet Variable Speed for YouTube
javascript:var gSpeedControl = (function(v,i,n,t){ n.insertBefore(i, n.firstChild);i.type="range";i.min=.3;setTimeout(function(){i.max=i.value=1;i.oninput();},1); i.step=.05;t=i.nextSibling;i.oninput=function(){t.data=(100*(v.playbackRate=i.value)|0)+"%"};return i})(document.querySelector("video"), document.createElement("input"), document.getElementById("watch-header"))
@GarrettS
GarrettS / Prototype Inheritance
Created August 23, 2014 04:01
Prototype Inheritance - extends.
function Car(make) {
this.make = make;
}
Car.prototype.drive = function() {
console.log('driving ' + this.make);
};
@GarrettS
GarrettS / gist:1fb0709bb03e8d5bae25
Created September 4, 2014 00:02
Selectors: findAncestor
function matchesSelector(el, selectorText, ctx) {
var all = (ctx||el.ownerDocument).querySelectorAll(selectorText);
return indexOf(all, el) != -1;
}
function findAncestor(el, selectorText, container) {
if(el == null || el === container)
return null;
var parent = el.parentNode;
- return !!(node && method in node && node[method].apply);
1079 + return !!(node && method in node &&
1080 + (typeof node[method] === 'function' ||
1081 + String(node[method]).indexOf('function') === 1)); // IE reports as object, prepends space
It didn't look like it need much time, or to achieve any depth. Just
copy the source text and work down it inserting comments on the things
that stand out. When the first line of code is a 'fix' for pre-ECMA 262
3rd edition browsers (a standard that came out in 1999 and where the
most recent browser that needed the 'fix' is IE 4, in a system that does
not support IE in any version) then you don't need depth to see fault.
@GarrettS
GarrettS / newApply.js
Created March 10, 2011 05:49
newApply
function F(){}
function newApply(ctor, args) {
var i,
fp = F.prototype = ctor.prototype; // Copy prototype.
if(fp) {
fp.constructor = ctor;
}
i = new F;
ctor.apply(i, args); // Apply the original constructor.
return i;
@GarrettS
GarrettS / gist:1189225
Created September 2, 2011 17:26
toHexString = function (r, g, b)
var toHexString = function (r, g, b) {
return (toHexString = _toHexString)(r,g,b);
function _toHexString(r, g, b) {
return "#" + toHexByte(r) + toHexByte(g) + toHexByte(b);
}
function toHexByte(bite) {
var hex = bite.toString(16);
return (hex.length === 2 ? hex : "0" + hex);
}
};
@GarrettS
GarrettS / why-i-dislike-jquery
Created October 30, 2011 02:04
In Response to BadassJS "Why Do You Hate jQuery?"
<div style="white-space: normal">
Twitter anonymous user posted the question to me "Why do you hate jQuery?" The question implies that I have hatred of jQuery. I've been over the problems with jQuery over and over again. So much that I have long ago grown tired of it. I'll just sum them up here, with no code review. For links of jQUery code reviews, see "JavaScript Query Engines" article, on the site dhtmlkitchen.com (site was transferred to a new owner who had agreed to maintain it but instead dumped it).
Why do I dislike jQuery?
The initial design looked like a creative web programming experiment (and experimenting is a great way to learn, for sure).
But jQuery was touted as something of a general purpose solution to web scripting. Web authors having a very superficial and limited understanding of what they do, could now do things that they would have otherwise been incapable of. It was empowering to this class of developer.
However, for web developers who actually understand what they are doing, jQue
@GarrettS
GarrettS / jitsu deploy fatal
Created December 23, 2011 00:57
jitsu deploy FATAL ERROR
Garrett-Smiths-MacBook-Pro:~ garrettsmith$ jitsu apps deploy
info: Welcome to Nodejitsu
info: It worked if it ends with Nodejitsu ok
info: Executing command apps deploy
info: Authenticated as xkit
warn:
warn: Your package.json file is missing required fields:
warn:
warn: subdomain
warn:
@GarrettS
GarrettS / jitsu install http-server
Created December 23, 2011 01:09
Jitsu Install HTTP
Garrett-Smiths-MacBook-Pro:missionmassage garrettsmith$ jitsu install http-server
info: Welcome to Nodejitsu
info: It worked if it ends with Nodejitsu ok
info: Executing command install http-server
info: Installing http-server locally.
warn: Downloading packages from npm, this may take a moment...
info: http-server installed.
help: You can now jitsu deploy this application
prompt: Would you like to start this application locally? (yes): yes
warn: Outputting logs from: http-server