Skip to content

Instantly share code, notes, and snippets.

@f5io
f5io / emitter.js
Created February 24, 2014 09:58
Publish/Subscribe implementation
var _listeners = {};
function on() {
var args = [].slice.call(arguments);
var ev = args[0],
fn = args[1],
scope = args[2];
_listeners[ev] = _listeners[ev] || [];
_listeners[ev].push({ fn : fn, scope : scope });
@f5io
f5io / widowmaker.js
Created January 3, 2014 11:07
Trollololololololololol
(function(d) {
var tags = 'h1 h2 h3 h4 h5 h6 p div'.split(' ');
var elems = [];
for (var t in tags) {
elems = elems.concat(Array.prototype.slice.call(d.getElementsByTagName(tags[t])));
}
for (var e in elems) {
@f5io
f5io / matrix3d.js
Last active June 2, 2023 11:27
Matrix3D implementation using Typed Arrays
(function(w) {
var Matrix3D = {};
Matrix3D._deg2rad = function(deg) {
return deg * (Math.PI / 180);
};
Matrix3D.create = function() {
var out, args = Array.prototype.slice.call(arguments);
@f5io
f5io / angular-placeholder.js
Created November 1, 2013 12:35
AngularJS placeholder shiv directive.
angular.module('namespace.directives', []).directive('placeholder', ['$timeout', function($timeout) {
var i = document.createElement('input'),
support = ('placeholder' in i);
if (support) return {};
return {
restrict: 'A',
link: function(scope, elm, attrs) {
if (attrs.type === 'password') {
return;
}