Thursday, January 30, 2020

UNABLE TO RESTORE TO A PREVIOUS RESTORE POINT USING WINDOWS


>PROBLEM

After some operation, the Windows system becomes no more accessible.
Then how to restore to a previous "restore point" if Windows is not running.


>SOLUTION

Just to remember that a restore point is also accessible using the Repair/Rescue disk created by the same version of the system that requires repair.

Reboot using de Repair/Rescue disk and choose the respective option.




CREATE IMAGE BACKUP WINDOWS 10 CREATION FAILS DUE TO CORRUPTED VOLUME


>PROBLEM

Attempt to create a Windows system image using Windows native tool returns an error message like this:

Failed to create image due to corrupted volume \\{9834834138743...}


>SOLUTION

Restart the machine using the Windows Repair/Rescue disk of the same version of the system that requires repair. Do not use different a version even though it seems to work fine.

Select the option "Windows Memory Diagnostic Tool"

I know, it seems awkward because the first thing that triggers our minds is something about the RAM memories itself.







Windows Cannot Find a System Image on This Computer


>PROBLEM


Windows 10 Fails to Find System Image Backup

Attempt to restore a system image fails because the Repair/Rescue disk is not able to present the backup list, unlike the image below, the fields always return blank, without result.

An attempt to select a system image (radio option above to the buttons) returns an empty list.


NOTE - POST EXTENDED
Other issues and additional solutions are available here (an extension of this post), including the download of the Windows Rescue/Repair iso image to create a bootable CD or pen drive.


>SOLUTION


Supposing the source HDs where the images were saved are NOT corrupted, try another Repair/Rescue disk created by the same version of Windows that created the system images.

This issue may happen when an image is created with a different version of Windows than the Windows version that created the Repair/Rescue disk.

If you do not have another machine, try to find somebody who has a Windows system similar to your system, then create the rescue disk.





Wednesday, January 22, 2020

node.js: TypeError: Router.use() requires a middleware function but got a Object


>PROBLEM

Running node.js/express application, returns error:

TypeError: Router.use() requires a middleware function but got a Object


>SOLUTION

Go to the router files and check if module.export sttm is present.
Example:

module.exports = router;

>ENV

node.js v12.4.0
Express
Windows 10


Monday, January 20, 2020

node.js: req.body.PARAM_NAME fails returning undefined


Many times a failure comes from subtle things.

Both app.post/app.get  and  router.post/router.get accepts req.body.PARAM_NAME.

Example:

app.get('/', function(req,res){
 var email = req.body.email;
 var password = req.body.passwd;
 console.log('email: ' + email);
 console.log('pass: ' + password);
 res.render("index");
});

router.get('/alo/', function(req, res, next) {
 var email = req.body.email;
 var password = req.body.passwd;
 console.log('email: ' + email);
 console.log('pass: ' + password);
 res.render('alo', { title: 'Alo Express!' });
});

When using router and req.body returns undefined values, check if the code is well implemented, if not missing module.exports clause.

Follow by the example.

app.js file:
..
const indexRouter = require('./routes/indexRouter');
app.use('/', indexRouter);
..
module.exports = app;
 
indexRouter.js file:
..
const router = express.Router();
..
router.get('/alo/', function(req, res, next) {
  res.render('alo', { title: 'Alo Express!' });
});
..
module.exports = router;
Naturally the dependencies and app's configuration must be implemented, for example:
const express = require('express');
const bodyParser = require('body-parser');
const cookeParser = require('cookie-parser');
const app = express();
const passport = require('passport');
const { check, validationResult } = require('express-validator');
const session = require('express-session')
const hbs = require('express-hbs');
const flash = require('flash');
const router = express.Router();
const view_path = __dirname + '/views/';
const public_path = __dirname + '/public/';
app.use(express.static(view_path))
app.use(express.static(public_path));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(cookeParser());
app.use(passport.initialize());
app.use(passport.session());
app.set('view engine', 'html');
app.engine('html', require('hbs').__express);
 
@SEE:
Usando middlewares

 

Friday, January 17, 2020

Maven compilation asm issue: nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class




>PROBLEM


A deployable file is created using:

  mvn clean install


Attempt to run fails:

  java -jar myfile.war

generating the following message (snippets):

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL 
[jar:file:/L:/work/dev/java/projects/tpzapp/parent/sisgit2/sisgit2-2.0.war!/WEB-INF/classes!/br/net/telespazio/sisgit2/app/Sisgit2App.class]; 
nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
 at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:311) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
 at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:272) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
 at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:135) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
...
Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
 at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_112]
 at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0_112]
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_112]



>SOLUTION


Switched maven's compilation plugins configuration as follows:


>>BEFORE


<packaging>war</packaging>
<plugin>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-maven-plugin</artifactid>
</plugin>
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-surefire-plugin</artifactid>
</plugin>

         

>>AFTER


<packaging>jar</packaging>
<plugin>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-maven-plugin</artifactid>
</plugin>


>ENV

Windows 10
Java 8
Maven 3.x

Saturday, January 11, 2020

Vim editor – Commands’ Summary (Cheat Sheet)


MINI TUTORIAL - MINIMAL KNOWLEDGE


This post intends to give you the very initial steps to begin using Vim, supplying a Cheat Sheet collected from many sources across the years.

To begin, let's create a hello text file.
Using the console (prompt), type the following:

vim hello.txt
Type I (i) to get into "insert mode".
Type: hello world!
Type ESC to exit.
Type colon (:) then x to save:
:x
Use enter to exit.

That's it. You are "initiated" - simple like that.




Vim editor has "modes" - commands' contexts.

When you open the editor you may issue a set of commands.
See basic navigation below.

To enter into edit mode, use insert key or the I(i) key.
To exit from insert mode, use ESC.

On ESC mode, if you type colon (:), you get a command line at the bottom that enables another set of commands. For instance, if you desire to add line numbers, you do: 

Type ESC.
Type colon (:).
Type "set nu"
Type ESC to exit from the command line.

Now the lines have sequential numbers.

Vim is a super editor, having everything you wonder or you even never supposed to.

It worths to get acquainted to it because it is the default editor on most *nix systems, like AIX, Unix and flavors of Linux.

When using console (SSH connection), Vim is the ubiquitous solution - everywhere has a "vim" command available for you.

Although the documentation turns into something scaring it is not a big deal if you dive into its resources by section of interests.
For instance, what do you want to do?
Find a string, replace text, mark a point on the text to get there fast, split windows, compare files, etc.


I know, I know - it is very strange to alternate between insert mode and command mode. Do not complain - it is just a matter of habit. You'll see!  :-)

Advantage of that: you have extra power while having to modes.

Vim, my old friend...


BASIC NAVIGATION (NOT ON INSERT MODE)

NOTE:  the behavior depends upon the keyboard type.
If not working, try the Fn key plus the shortcut.
Example: Fn + k

  • k – navigate upwards
  • j – navigate downwards
  • l – navigate right side
  • h – navigate left side
  • 0 – go to the starting of the current line.
  • ^ – go to the first non blank character of the line.
  • $ – go to the end of the current line.
  • g_ – go to the last non blank character of the line.
  • H – Go to the first line of current screen.
  • M – Go to the middle line of current screen.
  • L – Go to the last line of current screen.
  • ctrl+f – Jump forward one full screen.
  • ctrl+b – Jump backwards one full screen
  • ctrl+d – Jump forward (down) a half screen
  • ctrl+u – Jump back (up) one half screen
  • e – go to the end of the current word.
  • E – go to the end of the current WORD.
  • b – go to the previous (before) word.
  • B – go to the previous (before) WORD.
  • w – go to the next word.
  • W – go to the next WORD.
  • { – Go to the beginning of the current paragraph. By pressing { again and again move to the previous paragraph beginnings.
  • } – Go to the end of the current paragraph. By pressing } again and again move to the next paragraph end, and again.
  • N% – Go to the Nth percentage line of the file.
  • NG – Go to the Nth line of the file.
  • G – Go to the end of the file.
  • `” – Go to the position where you were in NORMAL MODE while last closing the file.
  • `^ – Go to the position where you were in INSERT MODE while last closing the file.
  • g – Go to the beginning of the file.
  • % – Go to the matching braces, or parenthesis inside code.
  • Use ‘.’ to repeat the last command.
    The command will be repeated considering the current caret position.

MORE DETAILED INFORMATION, SEE:

Wednesday, January 8, 2020

Docker: Hardware assisted virtualization and data execution protection must be enable in the BIOS


>PROBLEM

Docker fails to start, returning the following message:

Hardware assisted virtualization and data execution protection must be enabled in the BIOS
See https://docs.docker.com/docker-for-windows/troubleshoot/#virtualization-must-be-enabled







>SOLUTION

Turn on hyper-v.
As Administrator, issue the command:

   bcdedit /set hypervisorlaunchtype auto start

Restart the machine.

*** IMPORTANT NOTE:

Vagrant with VirtualBox require to turn off hyper-v:

  bcdedit /set hypervisorlaunchtype off

That way, if you have both installed, once their configurations are conflicting, it is not possible to have both working at the same time.





>ENV

Windows 10
Vagrant v2.2.6
VirtualBox 6.0

>SEE

Vagrant: The box you're attempting to add doesn't support the provider you requested

Vagrant: There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox


Vagrant: There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox


>PROBLEM

Starting vagrant:

    vagrant up

Causes the follwing issue:

There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox. 
The command and stderr is shown below.

Command: ["startvm", "01748371-61a5-4c0e-a279-9077bab91aaf", "--type", "headless"]
Stderr: VBoxManage.exe: error: Call to WHvSetupPartition failed: ERROR_SUCCESS (Last=0xc000000d/87) (VERR_NEM_VM_CREATE_FAILED)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole


>SOLUTION

Turn off  hyper-v.
As administrator, issue the comand:

    bcdedit /set hypervisorlaunchtype off

Restart machine.


*** IMPORTANT NOTE:

Docker requires hyper-v on:

   bcdedit /set hypervisorlaunchtype auto start

So, after the environment is restarted, docker will stop working.
Docker and Vagrant/VirtualBox requires conflicting environment configuration.




Vagrant: The box you're attempting to add doesn't support the provider you requested


>PROBLEM

Starting Vagrant using VirtualBox as follows:

   vagrant up

Fails to start returning this message:

The box you're attempting to add doesn't support the provider you requested. 
Please find an alternate box or use an alternate provider. 
Double-check your requested provider to verify you didn't simply misspell it.

If you're adding a box from HashiCorp's Vagrant Cloud, make sure the box is
released.

Name: ubuntu/trusty64
Address: https://vagrantcloud.com/ubuntu/trusty64
Requested provider: [:hyperv]


If you force, using:

  vagrant up --provider virtualbox

vagrant then returns the following:

Vagrant has detected that you have a version of VirtualBox installed
that is not supported by this version of Vagrant. Please install one of
the supported versions listed below to use Vagrant:
4.0, 4.1, 4.2, 4.3, 5.0, 5.1, 5.2, 6.0

The provider 'virtualbox' that was requested to back the machine
'mongod-m103' is reporting that it isn't usable on this system. The
reason is shown below:

Vagrant has detected that you have a version of VirtualBox installed
that is not supported by this version of Vagrant. Please install one of
the supported versions listed below to use Vagrant:

4.0, 4.1, 4.2, 4.3, 5.0, 5.1, 5.2, 6.0

          A Vagrant update may also be available that adds support for the version
        you specified. Please check www.vagrantup.com/downloads.html to download
        the latest version.


>SOLUTION

Download a version of VirtualBox compatible with Vagrant's version.
For instance, if vagrant v2.2.6, use vitualbox 6.0.

Download here (change the url's version suffix for the one desired):

https://www.virtualbox.org/wiki/Download_Old_Builds_6_0


>ENV

Windows 10
Vagrant v2.2.6
VirtualBox 6.0

Sunday, January 5, 2020

git Changes not staged for commit remove message



>PROBLEM

git status command returns the following message:

  git Changes not staged for commit remove message


>SOLUTION

This kind of problem may be originated when a folder is added to .gitignore without adding and committing the repository before .gitignore inclusion and committing after.
A straightway is to move the folder that contains the inconsistency to a temporary folder. Then add and commit again.

Example, supposing the following project structure:

+-- myProjectRoot
+--folder1
+--folder2
+--folderWithIssue

To fix, do:

cd /home/myProjectRoot
- windows:
cd C:\myProjectRoot

git add *
git commit -am "my message here"

mv /home/myProjectRoot/folderWithIssue /home/temp
- windows:
move folderWithIssue C:\temp

git add *
git commit -am "my message here"
git push

mv /home/temp/folderWithIssue .
- windows:
move C:\temp\folderWithIssue .

git add *
git commit -am "my message here"
git push


node.js: morgan deprecated default format: use combined format



>PROBLEM

The server throws the following server's message:
  morgan deprecated default format: use combined format

>SOLUTIONS

>>POSSIBILITY #1 ----------------------------------

BEFORE:
app.use(logger);


AFTER:
app.use(logger('combined'));


@FROM:
stackoverflow.com/questions/36397812/morgan-deprecated-expressjs/36398066


>>POSSIBILITY #2 ----------------------------------

BEFORE:
app.use(logger(process.env.AMBIENTE));
...
require('dotenv').config();


AFTER:
require('dotenv').config();
..
app.use(logger(process.env.AMBIENTE));

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...