How To: Logging with Javascript using Date class

Hello,

If you are trying to print a neat date format in Javascript using Date() class, then you can use below snippet.

Its a ES6 based function with template literals.


  
  const date = () => {
  const d = new Date();
  return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}_${d.getHours()}-${d.getMinutes()}-${d.getSeconds()}_${d.getMilliseconds()} => `;
};

 
  

If you are looking for ES5 syntax, you can use below one

 
  var getDate = function() {
    var d = new Date();
    return d.getFullYear()+"-"+d.getMonth()+"-"+d.getDate()+"_"+d.getHours()+"-"+d.getMinutes()+"-"+d.getSeconds()+"_"+d.getMilliseconds()+" =>";
  };
  
  

Hope it helps.

Thank you.

How to resolve VERR_NEM_VM_CREATE_FAILED in Windows ?

How to resolve VERR_NEM_VM_CREATE_FAILED in Windows ?

Hello Everyone,
So I tried to install VirtuaBox VM in Windows 10 and I was getting VERR_NEM_VM_CREATE_FAILED error. After trying many solutions and searching a log in internet, Finally issue got resolved with below command.

  1. Open cmd prompt as Administrator.
  2. Shut down all programs. You will have to shut down, unplug, and restart your host.
  3. Ensure that none of these things are running:
  • DeviceGuard
  • CredentialGuard
  • Windows Defender’s Core Isolation
  1. Find the Command Prompt icon, right click it and choose Run As Administrator.
  2. Enter this command:
   bcdedit /set hypervisorlaunchtype off  

Then run below command

DISM /Online /Disable-Feature:Microsoft-Hyper-V
  1. Enter this command to shutdown your system
shutdown -s -t 2  
  1. When the computer turns off, unplug it for 20 seconds. Then plug it in again and boot up Windows 10.

After following these instructions, my issue got resoved and I am able to bootup again.

Credit Goes to : virtualbox.org • View topic - VERR_NEM_VM_CREATE_FAILED: What do I do?

Hope it helps.
Thank you.

How to: Bash PID of last execute command

Hello Everyone

In shell scripting if you want to get PID of last executed command, then you can use BASH `$!` meta variable.

For example lets say if you have below command


# nohup sha256sum 1g.bin &

If you want to find that job PID which is running in the background, use below command


  # echo $!

For Example


[x:/tmp]# nohup sha256sum 1g.bin &
[1] 14866
[x:/tmp]# nohup: ignoring input and appending output to `nohup.out'

[x:/tmp]# echo $!
14866
[x:/tmp]# pgrep sha256sum
14866

Hope it helps.

Thank you.

How to : Docker mount current working directory as volume

Hello Everyone,

If you have a docker container and you would like to mount one of your current folder in the host machine as volume inside your container, then you can use below command


docker run --rm -it -v $(pwd):/usr/src/project gcc:4.9
 

use cases:

- If you local folder have your source code and you like to execute inside your container environment manually. 

How To - Ansiable Playbook Output - JSON Format

How To - Ansiable Playbook Output - JSON Format

Hello Everyone,

In this blog post lets see how to execute ansible-playbook with custom output format like JSON

Lets say you have a playbook like below

---
- hosts: 127.0.0.1
  gather_facts: false

  tasks:
    - name: execute uptime command
      command: uptimer
      register: result

    - debug: var=result.stdout

And if you execute the playbook with below command

ansible-playbook playbook.yaml

You will get normal ansible standard output format like below

▶ ansible-playbook ansible_uptime.yaml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

 _______________________________
< TASK [execute uptime command] >
 -------------------------------
      
changed: [127.0.0.1]

ok: [127.0.0.1] => {
    "result.stdout": "12:34  up  4:03, 2 users, load averages: 3.42 3.62 3.10"
}


127.0.0.1 : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


~/my_learning/ansible

If you want output in JSON format for example, you can use ANSIBLE_STDOUT_CALLBACK env variable. Set the variable value with respect to output format you want. If its JSON

ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ansible_uptime.yaml
▶ ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ansible_uptime.yaml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
{
    "custom_stats": {},
    "global_custom_stats": {},
    "plays": [
        {
            "play": {
                "duration": {
                    "end": "2021-10-26T07:06:58.968665Z",
                    "start": "2021-10-26T07:06:58.419247Z"
                },
                "id": "acde4800-1122-4989-e4cc-000000000005",
                "name": "127.0.0.1"
            },
            "tasks": [
                {
                    "hosts": {
                        "127.0.0.1": {
                            "_ansible_no_log": false,
                            "action": "command",
                            "changed": true,
                            "cmd": [
                                "uptime"
                            ],
                            "delta": "0:00:00.008988",
                            "end": "2021-10-26 12:36:58.904425",
                            "invocation": {
                                "module_args": {
                                    "_raw_params": "uptime",
                                    "_uses_shell": false,
                                    "argv": null,
                                    "chdir": null,
                                    "creates": null,
                                    "executable": null,
                                    "removes": null,
                                    "stdin": null,
                                    "stdin_add_newline": true,
                                    "strip_empty_ends": true,
                                    "warn": false
                                }
                            },
                            "msg": "",
                            "rc": 0,
                            "start": "2021-10-26 12:36:58.895437",
                            "stderr": "",
                            "stderr_lines": [],
                            "stdout": "12:36  up  4:05, 2 users, load averages: 3.78 3.54 3.14",
                            "stdout_lines": [
                                "12:36  up  4:05, 2 users, load averages: 3.78 3.54 3.14"
                            ]
                        }
                    },
                    "task": {
                        "duration": {
                            "end": "2021-10-26T07:06:58.942858Z",
                            "start": "2021-10-26T07:06:58.448326Z"
                        },
                        "id": "acde4800-1122-4989-e4cc-000000000007",
                        "name": "execute uptime command"
                    }
                },
                {
                    "hosts": {
                        "127.0.0.1": {
                            "_ansible_no_log": false,
                            "_ansible_verbose_always": true,
                            "action": "debug",
                            "changed": false,
                            "result.stdout": "12:36  up  4:05, 2 users, load averages: 3.78 3.54 3.14"
                        }
                    },
                    "task": {
                        "duration": {
                            "end": "2021-10-26T07:06:58.968665Z",
                            "start": "2021-10-26T07:06:58.949451Z"
                        },
                        "id": "acde4800-1122-4989-e4cc-000000000008",
                        "name": "debug"
                    }
                }
            ]
        }
    ],
    "stats": {
        "127.0.0.1": {
            "changed": 1,
            "failures": 0,
            "ignored": 0,
            "ok": 2,
            "rescued": 0,
            "skipped": 0,
            "unreachable": 0
        }
    }
}

~/my_learning/ansible

Hope it helps.

Thank you.
Raaz

Motivation for everyone for everyday in real life or work life, Read this everyday before starting your day

When something is fun,like playing cricket, watching a suspense thriller or Sci-Fi movie, you dont need extra motivation, you will do that anyway because you are loving it. When something isn't fun, you dont like it and if you still have to do it, then you can follow below ideas.

  • Dont just go with problem -> solution approach, if you have 10 problems, if you have solved 3 already then you still see them as 7 more PROBLEMS and our brain hate problems, wont it ?, so its no more fun, so it (you) started doing procrastination automatically and soon or later you reach deadlines and you started feeling guilty for wasting that much time and you will hurry up with your work and finally your work from making a spider in 10 minutes to making a spider to 1 minute

 Image credit : https://jim.blacksweb.com

  •  So look at them like with explorer mindset. You remember in explorer games you have to do lot of exploring for gems, points etc. So adopt same satisfying or happy mindset when you started exploring a problem and found a solution. Dont look at them like problems, look at them like something you dont know and need to explore.

 

  •  Dont get overwhelm by things you dont know. Break the problem into steps. Users are unable to login into your billion dollars application, this reason is enough to create panic, heart attacks. But look at the problem, " ok no login, alright, login page loading properly ? on submit event coming to our webservers or not ? if no , ok network issue, call network team. if, yes, ok from here request is sending to respective logic server/ app server or not ? no , check the LB, check the VIP rules, check webserver configuration etc." like this you can formulate so many steps and you can solve the problem or atleast you can identify and understand the problem and then giving a solution can be easy because you know the problem already, "" Some problems are tricky I agree and might needs more brains, so thats why we work in a team right, take their suggestion, because greatest things were never built alone "".

 

  • Expect always that nothing is perfect and when you got a problem, see it like an opportunity to improve your self for next product/ design to avoid same/similar issues like this. See it like a way of improving your current product, to make it more solid. so problems are good, they will help you and your product, to more solid product. And as you have faced the problem, your next product must consider this type of issue, so your next product is already bullet proof for current problem you are facing. You might get new problems, but they are chances to improve yourself or your product always. They are coming to make you strong, not to make you week. 

Hope it help you. Please add your comments, if you like this post and that will gives me a clarity if I need to write more in future.