1 2 3 4 5 6 7 8 |
FROM node:10 WORKDIR /usr/src/app COPY package*.json ./ RUN npm install pm2 -g RUN npm install COPY . . EXPOSE 8080 CMD ["pm2-runtime", "server.js"] |
Full Stack LAMP, MEAN, DevOps Consultant
1 2 3 4 5 6 7 8 |
FROM node:10 WORKDIR /usr/src/app COPY package*.json ./ RUN npm install pm2 -g RUN npm install COPY . . EXPOSE 8080 CMD ["pm2-runtime", "server.js"] |
Let us see an example of how to calculate the difference between dates using Javascript. First, write an HTML code with Javascript as below:
1 2 3 4 5 |
const d1 = new Date("12/12/2018"); const d2 = new Date("12/12/2020"); const timeDiff = d2.getTime() - d1.getTime(); const DaysDiff = timeDiff / (1000 * 3600 * 24); console.log("Days of difference between:"+ d1 +"<br> and "+d2+" is:" +DaysDiff); |
Array.ForEach is about 95% slower than for() in for each for Arrays in JavaScript. So, don’t use:
1 2 3 4 |
var data = []; arr.forEach(function (item) { data.push(item); }) |
1 2 3 4 |
var data = []; for (var i = 0, len = arr.length; i < len; i++) { data.push(arr[i]); } |
Here is the simple JavaScript code snippet to check if the given number is an odd or even number. Function to check Number Is Odd Or Even
1 2 3 |
function checkEven(val){ return (val%2 == 0); } |
1 2 3 4 5 6 |
val = 9; if(checkEven(val)){ alert("Number is even"); } else { alert("Number is odd"); ] |
jQuery make it easy to preload images in the background so visitors won’t have to wait forever when they would like to display an image. This code is ready to use, just update the image list on line 8.
1 2 3 4 5 6 7 8 9 |
$.preloadImages = function() { for(var i = 0; i<arguments.length; i++) { $("<img />").attr("src", arguments[i]); } } $(document).ready(function() { $.preloadImages("hoverimage1.jpg","hoverimage2.jpg"); }); |
1 2 3 4 5 6 |
$('.btn').hover(function(){ $(this).addClass('hover'); }, function(){ $(this).removeClass('hover'); } ); |
Occasionally we have times when we have broken image links on our website and replacing them one by one isn’t easy, so adding this simple piece of code can save you a lot of headaches.
1 2 3 |
$('img').error(function(){ $(this).attr('src', 'img/broken.png'); }); |
1 2 3 |
var sometext = "here is more HTML"; $("p#text1").append(sometext); // added after $("p#text1").prepend(sometext); // added before |
1 2 3 4 5 6 |
var maxheight = 0; $("div.col").each(function(){ if($(this).height() > maxheight) { maxheight = $(this).height(); } }); $("div.col").height(maxheight); |
1 2 3 4 |
$("a[href='#top']").click(function() { $("html, body").animate({ scrollTop: 0 }, "slow"); return false; }); |