Code Mine

Simple as code

Get the list of keys of any object
JS

        

You can use Object.keys() method which is used return an array of a given object’s own property names, in the same order as we get with a normal loop. For example, you can get the keys of a user object,

const user = {  name: 'John',  gender: 'male',  age: 40};console.log(Object.keys(user)); //['name', 'gender', 'age']
let obj = { firstName : "John" } 
obj.firstName
Different ways to access object properties
programming

        
let obj = { firstName : "John" } 
obj.firstName

There are 3 possible ways for accessing the property of an object.

  1. Dot notation: It uses dot for accessing the properties
    objectName.property
    
  2. Square brackets notation: It uses square brackets for property access
      objectName["property"]
    
  3. Expression notation: It uses expression in the square brackets
      objectName[expression]
    
var counterObj = {counter : 0};
Object.defineProperty(obj, "increment", {
    get : () => {this.counter++;}
});

Yes, You can use Object.defineProperty() method to add Getters and Setters. For example, the below counter object uses increment, decrement, add and substract properties,

var counterObj = {counter : 0};
Object.defineProperty(obj, "increment", {
    get : () => {this.counter++;}
});

Object.defineProperty(obj, "decrement", {
    get : () => {this.counter--;}
});

// Define setters
Object.defineProperty(obj, "add", {
    set : (value) => {this.counter += value;}
});

Object.defineProperty(obj, "subtract", {
    set : (value) => {this.counter -= value;}
});

obj.add = 10;
obj.subtract = 5;
console.log(obj.increment); //6
console.log(obj.decrement); //5

javascript:location.reload(true)

Mobile browser hard reload
JS

        

javascript:location.reload(true)

function shuffle(ordered){ let shuffled = []; for(var i = ordered.length; i>0; i–){ let r = random(0, i); shuffled.push(ordered.splice(r, 1)[0]) } return shuffled; }

.card { box-shadow: 0 4px 8px -8px #444; border: 0px; }

Generate random number
CSS

        

.card { box-shadow: 0 4px 8px -8px #444; border: 0px; }

convert +append image1.jpg image2.jpg result.jpg

Join images using imagemagic
Bash

        

convert +append image1.jpg image2.jpg result.jpg

git log –online

Git logs summary
Git

        

git log –online

function random(min, max){ return Math.floor(Math.random() * (max-min) + min); }

Generate random number
JS

        

function random(min, max){ return Math.floor(Math.random() * (max-min) + min); }