Skip to content

Instantly share code, notes, and snippets.

@floz
floz / requestAnimationFrame.js
Last active December 20, 2015 19:29
JS - requestAnimationFrame
(function() {
var lastTime = 0;
var vendors = ['webkit', 'moz'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame =
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
@floz
floz / RequestAnimationFrame.coffee
Created August 8, 2013 11:07
CoffeeScript - RequestAnimationFrame
do ->
w = window
for vendor in ['ms', 'moz', 'webkit', 'o']
break if w.requestAnimationFrame
w.requestAnimationFrame = w["#{vendor}RequestAnimationFrame"]
w.cancelAnimationFrame = (w["#{vendor}CancelAnimationFrame"] or
w["#{vendor}CancelRequestAnimationFrame"])
# deal with the case where rAF is built in but cAF is not.
if w.requestAnimationFrame
@floz
floz / get-sprite.scss
Last active December 21, 2015 22:59
SASS - Mixin spritesheet
// http://compass-style.org/reference/compass/helpers/sprites/
@mixin get-sprite($map, $sprite, $repeat: no-repeat, $height: true, $width: true){
//http://compass-style.org/reference/compass/helpers/sprites/#sprite-file
$sprite-image: sprite-file($map, $sprite);
// http://compass-style.org/reference/compass/helpers/sprites/#sprite-url
$sprite-map: sprite-url($map);
// http://compass-style.org/reference/compass/helpers/sprites/#sprite-position
@floz
floz / gist:6390251
Created August 30, 2013 14:09
Facebook - Share button with custom data
<a href="#" onclick="
window.open(
'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent('http://urlofthepage.com/share/'),
'facebook-share-dialog',
'width=626,height=436');
return false;" target="_blank"> Share </a>
<html>
<head>
<title></title>
@floz
floz / Grid.js
Created October 17, 2013 22:58
JS - Grid.js
Grid = ( function Grid() {
var _itemSize = 156,
_$content = null, _w = 0, _h = 0, _spacing,
_cellWidthPercent = 0.0, _totalWidth = 0, _cellWidth = 0, _spacingPercent = 0.5;
function Grid( $content, w, h, spacing ) {
_$content = $content;
_w = w;
_h = h;
@floz
floz / _mobile_mixins.styl
Created April 29, 2014 15:26
Mobiles mixins for stylus
baseImg = "../img/"
img( url )
background transparent url( baseImg + url ) no-repeat
imgImportant( url )
background transparent url( baseImg + url ) !important
imgRepeat( url )
background transparent url( baseImg + url )
/*
* Natural Sort algorithm for Javascript - Version 0.6 - Released under MIT license
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
* Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
*/
function naturalSort(a, b) {
var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
sre = /(^[ ]*|[ ]*$)/g,
dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
hre = /^0x[0-9a-f]+$/i,
@floz
floz / gist:b573787ec9ab36aa8911
Created October 2, 2014 00:31
Update pixi texture from canvas
# if engine.isWebGL()
# PIXI.updateWebGLTexture @_texture.baseTexture, engine.getRenderer().gl
@floz
floz / gist:53ad2765cc846187cdd3
Created December 18, 2014 18:47
PhotoshopMath.glsl
/*
** Copyright (c) 2012, Romain Dura romain@shazbits.com
**
** Permission to use, copy, modify, and/or distribute this software for any
** purpose with or without fee is hereby granted, provided that the above
** copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
@floz
floz / gist:52fdf6c805dd96f4553a
Last active August 29, 2015 14:20
AlphaMaskFilter2.js
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The AlphaMaskFilter2 class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object.
* You can use this filter to apply all manor of crazy warping effects
* Currently the r property of the texture is used to offset the x and the g property of the texture is used to offset the y.
*
* @class AlphaMaskFilter2