Skip to content

Instantly share code, notes, and snippets.

View yoannmoinet's full-sized avatar
🐶
DX and Tooling

Yoann Moinet yoannmoinet

🐶
DX and Tooling
View GitHub Profile
@yoannmoinet
yoannmoinet / requestAnimationFrame.js
Created January 10, 2013 21:47
Request Animation Frame polyfill
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
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)
@yoannmoinet
yoannmoinet / scrollEvt.js
Created January 10, 2013 22:34
Cross browser scroll event handler, with a consistant delta.
var mousewheelevt=(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel";
if (document.attachEvent)
document.attachEvent("on"+mousewheelevt, function(e){scroller(e)});
else if (document.addEventListener)
document.addEventListener(mousewheelevt, function(e){scroller(e)},false);
function scroller(evt)
{
//Guess the delta.
@yoannmoinet
yoannmoinet / setCSS.js
Created January 11, 2013 14:33
Set css vendor specific.
function setCSS(prop,value,css){
var ar = ["-webkit-","-o-","-moz-","-ms-","-khtml-",""];
if(css === undefined)
{
css = {};
}
for(var i = 0, max = ar.length; i<max; i+=1)
{
css[ar[i]+prop] = value;
}
@yoannmoinet
yoannmoinet / addFile.js
Created January 11, 2013 14:35
Add a file to the page.
function addScript(type,url,cache,cb){
var script = document.createElement(type),
head=document.getElementsByTagName('head')[0],
done=false,
src = url;
src += (cache === false)?('?dummy=' + (+new Date())):'';
script.onload=script.onreadystatechange = function(){
if ( !done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) {
done=true;
@yoannmoinet
yoannmoinet / CI Session Table Creation
Created February 22, 2013 19:51
Code Igniter Session Table creation.
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);
@yoannmoinet
yoannmoinet / gist:5820391
Last active December 18, 2015 17:39 — forked from renyi/gist:877176
CSS Font-families
/* sans-serif */
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
font-family: Helvetica, "Helvetica Neue", Arial, sans-serif;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-family: Trebuchet, Tahoma, Arial, sans-serif;
font-family: GillSans, Calibri, Trebuchet, sans-serif;
font-family: "DejaVu Sans", "Bitstream Vera Sans", "Segoe UI", "Lucida Grande", Verdana, Tahoma, Arial, sans-serif;
font-family: Geneva, "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif;
font-family: Geneva, Verdana, "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", sans-serif;
font-family: "HelveticaNeue-Roman", "Helvetica 55 Roman", Helvetica, Arial, sans-serif;
@yoannmoinet
yoannmoinet / localSessionStoragePolyfill.js
Last active December 20, 2015 09:09 — forked from remy/gist:350433
Polyfill for localStorage and sessionStorage API.
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
// ==UserScript==
// @name Userscript Name
// @namespace http://example.com/
// @description Userscript Description
// @match http://example.com/* (or @include * to include all pages)
// @version 1.0
// ==/UserScript==
// Emulate Greasemonkey's unsafeWindow in Chrome
window.unsafeWindow = window.unsafeWindow || (function() {
@yoannmoinet
yoannmoinet / CORSHeaders.js
Last active August 29, 2015 14:05
Add all requested headers for a CORS request.
//Cross Domain Headers.
//A bit hacky on the referer.
var getCorsHeaders = function (req, res){
//Can't put wildcards here,
//so here we are, cheating all the way.
var ref = req.headers.referer || req.headers.origin;
ref = ref?ref.slice(0,-1):"*";
res.set('Access-Control-Allow-Origin', ref);
res.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.set('Access-Control-Allow-Headers', 'Authorization, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, origin');
@yoannmoinet
yoannmoinet / mobileDesktopEvents.js
Last active August 29, 2015 14:05
Events for a mobile/desktop Backbone application.
Backbone.MOBILE = navigator.userAgent.match(/mobile/i);
var View = Backbone.View.extend({
events: function () {
return Backbone.MOBILE ? {
"click .new_message": "newMessageClick",
"touchstart #send_new_message": "openMenu",
"touchend #send_new_message": "selectMenu"
} : {
"click .new_message": "newMessageClick",
"mousedown #send_new_message": "openMenu",