Skip to content

Instantly share code, notes, and snippets.

View yckart's full-sized avatar

Yannick Albert yckart

View GitHub Profile
@yckart
yckart / randomAlphaNum.js
Created February 15, 2013 06:21
Random alphanum with javascript. based upon: https://gist.github.com/hasenj/3662865
var randomAlphaNum = function () {
var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
return alpha[Math.round(Math.random() * alpha.length)];
};
@yckart
yckart / B64.js
Last active December 13, 2015 20:19
// http://hashify.me/
var B64 = function(){
encode: function (raw) {
return window.btoa( window.unescape( encodeURIComponent(raw) ) );
},
decode: function (b64) {
return decodeURIComponent( window.escape( window.atob(b64) ) );
}
};
var cookie = {
create: function (name, value, minutes) {
var expires;
if (minutes) {
var date = new Date();
date.setTime(date.getTime() + (minutes * 60 * 1000));
expires = "; expires=" + date.toGMTString();
} else expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
},
@yckart
yckart / Class.js
Last active December 15, 2015 13:29
A class factory.
/**
* Class
* A class factory
*/
function Class(parent, members) {
// prepare single-inheritance
members = members || parent;
@yckart
yckart / snake.js
Last active December 15, 2015 20:41
Simple canvas snake game to port into some game-engines.
/*!
* snake.js 0.0.1 - https://gist.github.com/yckart/5320382/
* A super simple canvas snake game to port into some game-engines.
*
* Copyright (c) 2013 Yannick Albert (http://yckart.com)
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
* 2013/04/05
*/
@yckart
yckart / rAF.js
Created April 30, 2013 02:05
requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel refactored by Yannick Albert
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// refactored by Yannick Albert
// MIT license
(function(window) {
var equestAnimationFrame = 'equestAnimationFrame',
requestAnimationFrame = 'r' + equestAnimationFrame,
@yckart
yckart / performance.now.js
Last active December 16, 2015 20:18
performance.now polyfill
(function (performance) {
performance.now = performance.now ||
performance.webkitNow ||
performance.msNow ||
performance.mozNow ||
Date.now || function () {
return new Date().getTime();
};
}(this.performance = this.performance || {}));
@yckart
yckart / jquery.addrule.js
Last active December 29, 2022 12:16
Add css-rules to an existing stylesheet - http://stackoverflow.com/a/16507264/1250044
/*!
* jquery.addrule.js 0.0.2 - https://gist.github.com/yckart/5563717/
* Add css-rules to an existing stylesheet.
*
* @see http://stackoverflow.com/a/16507264/1250044
*
* Copyright (c) 2013 Yannick Albert (http://yckart.com)
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
* 2013/11/23
**/
/**
* Hide the addressbar on ios & android devices
* https://gist.github.com/yckart/5609969
*
* Based on the work from Nate Smith
* @see https://gist.github.com/nateps/1172490
*
* Copyright (c) 2013 Yannick Albert (http://yckart.com)
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
* 2013/07/10
@yckart
yckart / nthChild.js
Last active December 17, 2015 18:19
var nthChild = function (elem, num, fn) {
var len = elem.length;
var ret = [];
var i = 0;
// :nth-child(num)
if (!isNaN(Number(num))) {
for (i = 0; i < len; i++) {
if (i === num - 1) {
if (fn) fn(elem[i]);