Skip to content

Instantly share code, notes, and snippets.

View avishwakarma's full-sized avatar
🫠
Meltdown

Ashok Vishwakarma ✪ avishwakarma

🫠
Meltdown
View GitHub Profile
# Install node v10
FROM node:10
# Set the workdir /var/www/myapp
WORKDIR /var/www/myapp
# Copy the package.json to workdir
COPY package.json ./
# Run npm install - install the npm dependencies
version: '3'
services:
myapp:
container_name: myapp
restart: always
build: .
ports:
- '4300:4300'
- '4301:4301'
links:
@avishwakarma
avishwakarma / array_flat.js
Last active May 2, 2017 06:44
JavaScript Array Flat / Merge
/**
* flat / merge all sub array into one array
* @uses [['1', '2'], ['3', '4], '5', '6'].flat(); // ['1', '2', '3', '4', '5', '6']
*/
Array.prototype.flat = function(){
return [].concat.apply([], this);
}
@avishwakarma
avishwakarma / size.js
Created June 28, 2016 06:39
JavaScript object size
/**
* size - Object size in javascript
* @uses {a:1, b:2}.size() // 2
*/
Object.prototype.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
@avishwakarma
avishwakarma / unique.js
Last active June 28, 2016 06:36
JavaScript Array function for unique elements
/**
* unique - Array function for unique elements
* @use [2, 2, 3, 4, 3, 2].unqiue() // [2, 3, 4]
*/
Array.prototype.unique = function() {
var unique = [];
for (var i = 0; i < this.length; i++) {
if (unique.indexOf(this[i]) == -1) {
unique.push(this[i]);
@avishwakarma
avishwakarma / removeSpaces.js
Created June 28, 2016 06:08
remove all spaces (" ") from string
/**
* remove all spaces (" ") from string
* @uses removeSpaces("sample string with s p a c e s") // samplestringwithspaces
*/
function removeSpaces(str){
return (str + "").replace(/ /g,'');
}
@avishwakarma
avishwakarma / palindrome.js
Created June 28, 2016 06:05
Check if a number or string is palindrome
/**
* isPalindrome - function to check if a number or string is palindrome
* @uses isPalindrome(141) // true
*/
function isPalindrome(str){
return (str + "").split("").reverse().join("") == (str + "");
}
@avishwakarma
avishwakarma / serializeObject.js
Created June 28, 2016 05:59
jQuery plugin to serialize form elements as an object
/**
* serializeObject - jQuery plugin to serialize form elements as an object
* @uses $("#form").serializeObject(); // return {input:"value", input2:"value" .. }
*/
$.fn.serializeObject = function(){
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
@avishwakarma
avishwakarma / replaceAll.js
Created June 28, 2016 05:57
JavaScript replace multiple items in a string at once worked as str_replace PHP function
/**
* replaceAll - JavaScript string function
* @uses replace all matching substring to its corresponding replace string
* Worked similarly as str_replace in PHP
*/
String.prototype.replaceAll = function(find, replace) {
var replaceString = this;
var regex;
for (var i = 0; i < find.length; i++) {
@avishwakarma
avishwakarma / swap.js
Created June 28, 2016 05:52
jQuery plugin to swap two elements to each other using $.replaceWith function
/**
* $.swap - jQuery plugin to swap two elements
* Swap the current element with other element
* @uses $("#eample").swap($("#element"))
*/
$.fn.swap = function(to) {
return this.each(function(){
var ct = $(to).clone(true);
var cf = $(this).clone(true);