This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rand(min, max, integer) { | |
var r = Math.random() * (max - min) + min; | |
return integer ? r|0 : r; | |
} | |
// Usage | |
console.log(rand(2,5)); // float random between 2 and 5 inclusive | |
console.log(rand(1,100,true)); // integer random between 1 and 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stripTags(htmlstr) { | |
var div = document.createElement('div'); | |
div.innerHTML = htmlstr; | |
return div.textContent; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function once(fn, context) { | |
var result; | |
return function() { | |
if(fn) { | |
result = fn.apply(context || this, arguments); | |
fn = null; | |
} | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
convert -strip -quality 80% original.jpg step1.jpg | |
jpegtran -optimize -progressive -copy none -outfile output.jpg step1.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Meant to find out if a DOM element is scrolled into view | |
// aka if it is visible on the screen. | |
function appear(elem) { | |
var $elem = $(elem); | |
var $window = $(window); | |
var docViewTop = $window.scrollTop(); | |
var docViewBottom = docViewTop + $window.height(); | |
var elemTop = $elem.offset().top; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add this as the only script before your closing body tag | |
// and let it load your external scripts once your DOM has finished loading. | |
function addJSOnload() { | |
var element = document.createElement("script"); | |
element.src = "defer.js"; // replace your script with "defer.js" | |
document.body.appendChild(element); | |
} | |
if (window.addEventListener) | |
window.addEventListener("load", addJSOnload, false); | |
else if (window.attachEvent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A simple Bootstrap clearfix mod */ | |
/* Tablet */ | |
@media (min-width:767px){ | |
/* Column clear fix */ | |
.col-lg-1:nth-child(12n+1), | |
.col-lg-2:nth-child(6n+1), | |
.col-lg-3:nth-child(4n+1), | |
.col-lg-4:nth-child(3n+1), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.4.0.rc.1) | |
// Compass (v1.0.0.alpha.20) | |
// ---- | |
/** | |
* Generate the carousel animation | |
* based on the number of frames | |
* and the pourcentage of a frame spent static | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For the times that I need to know how far an element is from the top of the DOM, | |
//not the top of it’s parent, I use this helper function. | |
//Loops through all parent nodes of an element to get it's distance from the top of the document | |
function getDistanceFromTop(element) { | |
var yPos = 0; | |
while(element) { | |
yPos += (element.offsetTop); | |
element = element.offsetParent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Will print the 3rd line of all script files in the given folder (except 'myscripts') | |
for file in ~/scripts/*[^~"myscripts"] | |
do | |
tail -n+3 $file | head -n1 | |
done |
OlderNewer