Solve – cors problem


app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

app.get('/', function(req, res, next) {
  // ....
});

app.post('/', function(req, res, next) {
 // ....
});



Ubuntu dbVis – No suitable Java Virtual Machine could be found on your system

Error:

No suitable Java Virtual Machine could be found on your system.
The version of the JVM must be at least 1.8 and at most 9.
Please define INSTALL4J_JAVA_HOME to point to a suitable JVM.

Solution:

sudo apt update && sudo apt autoremove -y && sudo apt clean && sudo apt dist-upgrade -y && sudo add-apt-repository ppa:webupd8team/java -y && sudo apt update && sudo apt install oracle-java8-installer

React createElement – Warning: Unknown prop `childItems` on

The following command creates an element in React.


    const el = React.createElement(
                 < an html tag or react component >, 
                 < attributes or props or {} >, 
                 < children elements or text >
    )

When you pass a non html standard attributes in the second parameter to create html tag like div or p tag then a warning is raised of unknown prop. Simply remove the non standard attribute from the second parameter or pass empty object {}.

Ubuntu 17.10 expo and genymotion errors and solutions

Error:

Switched to a LAN URL because the tunnel appears to be down. Only devices in the same network can access the app. You can restart the project to try reconnecting.

Solution:

Due to some bug you must start xde (expo development environment) before genymotion. Also i needed to run xde from root user login. (not su or sudo ).
UPDATE: The following problem of adb version fixed this problem too.

===================================================================

Error:

Couldn’t start project on Android: could not install *smartsocket* listener: Address already in use
ADB server didn’t ACK
* failed to start daemon *
error: cannot connect to daemon

Solution:

the adb version on your system is different from the adb version on the android sdk platform-tools

1. check sys adb version

# adb version
Android Debug Bridge version 1.0.39

2. check sdk adb version

# cd /root/Android/Sdk/platform-tools
# ./adb version
Android Debug Bridge version 1.0.32

3. copy
# rm /usr/bin/adb
# sudo cp /root/Android/Sdk/platform-tools/adb /usr/bin/adb

=============================================================

Error:
Error: EACCES: permission denied, open ‘/tmp/haste-map-react-native-packager-1-8963e41d25a58e25717f5939e5144fc2

Solution: sudo rm /tmp/haste-map-react-native-packager-1-8963e41d25a58e25717f5939e5144fc2

========================================================
Error:
The development server returned response error code: 500

Solution:
For me this error was resolved running yarn in the project folder. The cause may have been due to the fact that I’d switched branches and some of the packages were not installed.

Reset windows 8 password from Ubuntu – Metadata kept in Windows cache, refused to mount

It was an interesting task to reset windows 8 password on a machine running Ubuntu . When I tried to (re)mount the disk I got the following problem and after googling for a while I found that there was no viable solution but to reinstall windows. However I successfully reset the password by using the following techniques.

I removed hard disk from the windows computer and attached it to my laptop running Ubuntu 17.10. By default Ubuntu mounts new hard disk as read only (or if any error) and therefore I have to remount the disk as read-write but I got the following error during mounting.

Metadata kept in Windows cache, refused to mount. ..

Windows machine had errors or hibernated files and therefore did not allow to mount as read-write. I used the following commands (alternatively, please unmount all partitions if mounted auto by Linux) a couple of times to fix this.

   sudo mount -t ntfs-3g -o remove_hiberfile /dev/sda5  ~/win8/
   sudo ntfsfix /dev/sda5

After this I installed the command line tool by:

  sudo apt install chntpw

Now first list the Windows users and then make password blank by:

   cd ~/win8/Windows/System32/config/
   sudo chntpw -l SAM
   sudo chntpw -u Administratör SAM

The funny part starts now. The administrator user was written with Swedish character ‘ö’ i.e Administratör and it was’nt recognized as in the last command above.

A work around is to use RID which is displayed when listing Windows users ( command : sudo chntpw -l SAM ).

   sudo chntpw -u 0x01f5 SAM

From the menu shown after the above command choose the one with blanking password, press q and (yes) for saving changes.

virtualbox ubuntu boot menu delay and reset password

To increase boot menu delay, first get a list of vms by typing the following in a terminal.

 VBoxManage list vms

You can change the delay by typing:

VBoxManage modifyvm "You virtual machine name from above command" --bioslogodisplaytime 10000

Now start/restart the Ubuntu machine and hold down the left SHIFT key from keyboard unless you get the boot menu. Select ‘root …’ from menu.
We need need to remount the disk in read-write mode:

mount -rw -o remount /

Change the password of the required user, lets say user1:

passwd user1
...

The state object

The state object contains the main data object of the application. Anything that changes in the state object will re-render the component.

The related method to set a specific key in the state is setState. The set state could be called after componentDidMount is called.

 

    constructor(props) {
      super(props);
      this.state = { products: [...] };
    }

    componentDidMount() {
      ....
      this.setState({products});
      .....
    }

Chain pattern


require "vendor/autoload.php";

use Chain\HomeStatus;
use Chain\Lock;
use Chain\Lights;
use Chain\Alarm;


$lock = new Lock();
$lights = new Lights();
$alarm = new Alarm();

$lock->setSuccessor($lights);
$lights->setSuccessor($alarm);

$homeStatus = new HomeStatus();
$lock->check($homeStatus);
echo PHP_EOL;