Skip to content

Instantly share code, notes, and snippets.

View tsbits's full-sized avatar
👾

Olivier Destenay tsbits

👾
View GitHub Profile
@tsbits
tsbits / Mobile OS detection
Last active August 29, 2015 14:10
Mobile OS detection
//From http://stackoverflow.com/questions/12606245/detect-if-browser-is-running-on-an-android-or-ios-device
var isMobile = {
Android: function() {
return /Android/i.test(navigator.userAgent);
},
BlackBerry: function() {
return /BlackBerry/i.test(navigator.userAgent);
},
iOS: function() {
@tsbits
tsbits / Quick server from anywhere on Mac OSX
Created November 28, 2014 17:02
Quick server from anywhere on Mac OSX
python -m SimpleHTTPServer
@tsbits
tsbits / Twitter card with picture
Created November 19, 2014 16:37
Twitter card with picture
/* https://dev.twitter.com/cards/types */
<meta name="twitter:card" content="photo" />
<meta name="twitter:title" content="Découvrez le nouveau calendrier de l'avent #Milka" />
<meta name="twitter:description" content="Comptez les nuit jusqu'à Noël grâce au nouveau calendrier de l'avent #Milka et découvrez des surprises sur avent.milka.fr" />
<meta name="twitter:image" content="https://avent.milka.fr/img/tcard.jpg" />
<meta name="twitter:url" content="https://avent.milka.fr" />
@tsbits
tsbits / Colored console.log
Last active August 29, 2015 14:08
Colored console.log
// Pour les retours à la ligne mettre \n
// %c applique du css. A chaque %c, ca applique le css suivant,
// donc de 'Made by Creaktif' a '\n' ca applique 'background: #cdcdcd; color: #fff'
// et après celui ci 'background: #8a8a8a; color: #fff', car il y a de nouveau un %c après le \n
console.log('%c MADE BY CREAKTIF \n%c www.creaktif.com ', 'background: #cdcdcd; color: #fff', 'background: #8a8a8a; color: #fff');
@tsbits
tsbits / Find a random point on a line
Last active August 29, 2015 14:07
Find a random point on a line
var r = Math.random();
var randomPoint = {
'x': (1-r)*this.v1.x + r*this.v2.x,
'y' : (1-r)*this.v1.y + r*this.v2.y
}
//Where v1 & v2 are the two points defining the line.
@tsbits
tsbits / Canvas to image
Created October 17, 2014 22:00
Canvas to image
var img = new Image();
img.src = canvas.toDataURL();
document.body.appendChild(img);
export PATH=/mongo/bin:$PATH
export PATH=/phantomjs/bin:$PATH
function tabname {
printf "\e]1;$1\a"
}
function winname {
printf "\e]2;$1\a"
}
@tsbits
tsbits / Check if a string contains only letters
Last active August 29, 2015 14:02
Check if a string contains only letters
function checkAlpha(word) {
var newStr = word.replace(/(^\s+|\s+$)/g,'');
if (newStr.length > 0) {
if (/[^A-Za-zàáâãäåæçèéêëæìíîïñòóôõöøßùúûüÿÀÁÂÃÄÅÆÇÈÉÊËÆÌÍÎÏÑÒÓÔÕÖØßÙÚÛÜŸ \-']/.test(newStr)) return false;
else return true;
} else return false;
}
@tsbits
tsbits / gist:45a336cdf7eee0107e75
Created June 5, 2014 09:27
Check if a string contains only numbers
function checkNumber(testedString) {
var newStr = testedString.replace(/(^\s+|\s+$)/g,'');
if (newStr.length > 0) {
if (/[^0-9]/.test(newStr)) return false;
else return true;
} else return false;
}
@tsbits
tsbits / gist:1a391f1fc35a5a1210a8
Created May 17, 2014 23:38
Degree to radian and vice-versa
//From http://cwestblog.com/2012/11/12/javascript-degree-and-radian-conversion/
// Converts from degrees to radians.
Math.radians = function(degrees) {
return degrees * Math.PI / 180;
};
// Converts from radians to degrees.
Math.degrees = function(radians) {
return radians * 180 / Math.PI;