Skip to content

Instantly share code, notes, and snippets.

View wiledal's full-sized avatar
🥃

Hugo Wiledal wiledal

🥃
View GitHub Profile
@wiledal
wiledal / PhotoshopSpriteStripMaker.js
Last active December 16, 2015 08:08
Photoshop script for making a sprite sheet out of a folder of images.
/* FUNCS */
function move(l,x,y) {
var Position = l.bounds;
Position[0] = x - Position[0];
Position[1] = y - Position[1];
l.translate(-Position[0],-Position[1]);
}
@wiledal
wiledal / dfor.js
Last active December 19, 2015 07:19
Delayed for-loop for async operations Usage: dfor(tasks.length, function(i, next) { // Do task with i next(); }, function() { // All completed }
dfor = function(num, func, callback) {
var i = -1;
function next() {
i++;
if (i == num) {
end();
}else{
func(i, next);
}
}
@wiledal
wiledal / automountvboxsf.sh
Created September 24, 2013 08:21
Set up auto mount for folders shared in VirtualBox with one command line. Replace <SHARED FOLDER> with the folder which is shared.
sudo touch /etc/init.d/mountdisks.sh; sudo sh -c 'echo "mount -t vboxsf <SHARED FOLDER> /var/www" > /etc/init.d/mountdisks.sh'; sudo chmod +x /etc/init.d/mountdisks.sh; sudo ln -s /etc/init.d/mountdisks.sh /etc/rc5.d/S20mountdisks.sh; sudo ln -s /etc/init.d/mountdisks.sh /etc/rc2.d/S20mountdisks.sh;
@wiledal
wiledal / nicedatefromtimestamp.js
Created November 8, 2013 10:07
Gives you a nice date sentence from a timestamp
function getNiceDateFromTimestamp(timestamp) {
var splits = {
"second": [60 * 1000, 1000],
"minute": [60 * 60 * 1000, 60 * 1000],
"hour": [24 * 60 * 60 * 1000, 60 * 60 * 1000],
"day": [7 * 24 * 60 * 60 * 1000, 24 * 60 * 60 * 1000],
"week": [4 * 7 * 24 * 60 * 60 * 1000, 7 * 24 * 60 * 60 * 1000],
"month": [12 * 4 * 7 * 24 * 60 * 60 * 1000, 4 * 7 * 24 * 60 * 60 * 1000],
"year": [-1, 12 * 4 * 7 * 24 * 60 * 60 * 1000]
}
@wiledal
wiledal / normalizeScroll.js
Created March 6, 2014 15:57
Normalize scroll
// Provide "originalEvent" of DOMMouseScroll and mousewheel
var o = event;
var d = o.detail;
var w = o.wheelDelta || o.deltaY;
var n = 225;
var n1 = n - 1;
var d = (d ? (w && (f = w / d) ? d / f : -d / 1.35) : w / 120);
var d = (d < 1 ? (d < -1 ? (-Math.pow(d, 2) - n1) / n : d) : (Math.pow(d, 2) + n1) / n);
@wiledal
wiledal / RandomColor
Last active August 29, 2015 14:04
Random Color
return "#" + ("000000" + (Math.random()*(1<<24)|0).toString(16)).slice(-6)
@wiledal
wiledal / blend.js
Created July 29, 2014 17:03
Blend two hexes
function blendHex(hex1, hex2, steps) {
var rgb1 = {
r: parseInt(hex1.slice(1,3), 16),
b: parseInt(hex1.slice(3,5), 16),
g: parseInt(hex1.slice(5,7), 16)
}
var rgb2 = {
r: parseInt(hex2.slice(1,3), 16),
b: parseInt(hex2.slice(3,5), 16),
g: parseInt(hex2.slice(5,7), 16)
@wiledal
wiledal / TransitionController.js
Last active August 29, 2015 14:05
Amazing Transition Controller
(function() {
window.AnimationController = {
enter: function(element, parent, callback) {
parent.append(element);
AnimationController.transition(element, "t-enter", "t-enter-active", function() {
if (callback) callback()
});
},
leave: function(element, callback) {
AnimationController.transition(element, "t-leave", "t-leave-active", function() {
@wiledal
wiledal / webcam-motion.coffee
Last active August 29, 2015 14:05
Webcam Motion Detection
class MotionDetection
@getDataPositionFromCoordinates = (width, x, y) ->
return x * 4 + y * (width * 4)
getCoordinatesFromPosition: (position) ->
return {
x: (position % @camCanvas.width) / @camCanvas.width
y: (Math.floor(position / @camCanvas.width)) / @camCanvas.height
}
@wiledal
wiledal / shake.js
Created March 14, 2015 21:56
Simple shake animation for TweenMax (gsap.js). For modern form error feedback.
function shakeAnimation(element){
TweenMax.to(element, .1, {
x: -7,
ease: Quad.easeInOut
});
TweenMax.to(element, .1, {
repeat: 4,
x: 7,
yoyo: true,
delay: .1,