Skip to content

Instantly share code, notes, and snippets.

Vue.directive('dom', {
isLiteral: true,
bind: function () {
this.vm.$.dom = this.vm.$.dom || {};
this.vm.$.dom[this.expression] = this.el;
},
unbind: function () {
delete this.vm.$.dom[this.expression];
}
});
@mattdesl
mattdesl / README.md
Last active September 3, 2015 11:44
tiny modules

tiny modules

A common question: why would anyone publish a single-function module?

It might seem odd to have a module with just a single function (examples: clamp, is-dom, is-url, object-assign, point-in-polygon). Sometimes your tests and documentation are longer than the function itself. Let's examine some of the benefits to this approach...

  • a terse and frozen API does not end up with the scope creep or code rot that larger frameworks and "standard libraries" tend to carry.
  • it encourages diversity rather than "this is the one true way" (e.g. robust-point-in-polygon handles edge cases at so
@gregtatum
gregtatum / round.js
Last active July 21, 2016 03:32
Round a corner
const {
dot,
length,
add,
scale,
normalize,
divide,
subtract,
cross,
distance,
@toddmotto
toddmotto / listeners.js
Last active September 14, 2016 04:59
Automatic unbinding on $scope.$destroy for $rootScope listeners
/*!
* $rootScope listeners, remember to unbind on $destroy
*/
var $rootListeners = {
'transmitProgress': $rootScope.$on('transmit:progress', transmitProgress),
'transmitSuccess': $rootScope.$on('transmit:success', transmitSuccess),
'transmitError': $rootScope.$on('transmit:error', transmitError)
};
// iterate the Object and pass the methods to be called on $destroy
@spoike
spoike / framerateThrottle.js
Last active August 13, 2017 21:35
Throttling using windows.requestAnimationFrame with fallback to lodash throttle. See more here: http://spoike.ghost.io/user-input-framerate-throttling-in-the-browser/
(function() {
var defaultFrameRate = 20, // fps lock for old browsers
// This is the default fallback throttle function
framerateThrottle = function(callback) {
return _.throttle(callback, 1 / (defaultFrameRate * 1000));
};
// Feature detection - should have requestAnimationFrame
if (window.requestAnimationFrame) {
framerateThrottle = function(callback) {
@roboshoes
roboshoes / tween.js
Last active January 25, 2018 18:19
Small tweening function for the quick tween.
export function tween( time, update ) {
const start = Date.now();
var isCanceled = false;
var isComplete = false;
var chain = [];
function loop() {
if ( isCanceled ) return;
@sketchpunk
sketchpunk / quaternion.glsl
Created September 3, 2018 14:31
Quaternion Vector Rotation in GLSL
vec3 vecQuatRotation(vec4 q, vec3 v){
return v + cross(2.0 * q.xyz, cross(q.xyz, v) + q.w * v);
}
@mattdesl
mattdesl / frag.vert
Created May 17, 2016 21:25
shadow on transparent plane ThreeJS r76
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float opacity;
varying vec3 vLightFront;
#ifdef DOUBLE_SIDED
varying vec3 vLightBack;
@mattdesl
mattdesl / stripe.glsl
Created November 8, 2016 15:14
stripe effect with noise
uniform vec4 offsetRepeat; // from ThreeJS Texture
uniform float time;
#pragma glslify: noise = require('glsl-noise/simplex/2d');
float pattern(float v, float repeats, float threshold) {
float result = mod(v * repeats, 1.0);
return step(threshold, result);
}
void main () {
var cushion = .5;
var length = 50;
var dx = point.x - mouse.x;
var dy = point.y - mouse.y;
var da = Math.sqrt(dx * dx + dy * dy);
// Tend à ramener la distance entre les segments à length
var ox = dx / da * length - dx;
var oy = dy / da * length - dy;