Friday, April 28, 2017

Magento 2 Reindexing - One or more indexers are invalid. Make sure your Magento cron job is running

To reindex in magento 2, go to the CLI and then the root folder of your magento installation and run the below command :
php bin/magento indexer:reindex
Another way is to set the cron job running every minute suggested by Magento Community and Enterprise version. Detail Here.

If you are using web hosting installation solution. There should be a cron job setting when it was installed at the beginning.  You can change the value to * * * * *.  If you are not familiar with cron format, Please check here at

  • Type: php bin/magento cache:clean and php bin/magento cache:flush

Thursday, April 27, 2017

Install git on Ubuntu 14.04

There are two ways to install, one is directly through ubuntu APT installation, this method is the most simple, the disadvantage is that the version may not be up to date. There is another way to download the source code for installation, which can be installed to the desired version. Here only say the first:


sudo apt-get update
sudo apt-get install git

 and then configure their own Git account information, so as to carry out the relevant operation:

git config --global "Your Name"
git config - -global ""

You can view the git configuration information with the following command:
git config --list

 The following information is displayed: = Your Name

Ubuntu in the sudo apt-get update exception handling

Error information:

W: Failed to fetch bzip2:/var/lib/apt/lists/partial/us.archive.ubuntu.com_ubuntu_dists_precise_main_source_Sources  Hash Sum mismatch

  • sudo mv /var/lib/apt/lists /var/lib/apt/lists.bak
  • sudo mkdir /var/lib/apt/lists
  • sudo apt-get update

SSH into your Virtualbox VM from the same computer

  • apt-get install openssh-server
  • sudo service ssh status
  • Go to ->setting->Network->Bridged Adapter
  • ifconfig get the ip
  • Open SecureCRT  ssh to server

Wednesday, April 26, 2017

Longest Absolute File Path

Suppose we abstract our file system by a string in the following manner:
The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents:
The directory dir contains an empty sub-directory subdir1 and a sub-directory subdir2 containing a file file.ext.
The string "dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext" represents:
The directory dir contains two sub-directories subdir1 and subdir2subdir1 contains a file file1.ext and an empty second-level sub-directory subsubdir1subdir2contains a second-level sub-directory subsubdir2 containing a file file2.ext.
We are interested in finding the longest (number of characters) absolute path to a file within our file system. For example, in the second example above, the longest absolute path is "dir/subdir2/subsubdir2/file2.ext", and its length is 32 (not including the double quotes).
Given a string representing the file system in the above format, return the length of the longest absolute path to file in the abstracted file system. If there is no file in the system, return 0.
  • The name of a file contains at least a . and an extension.
  • The name of a directory or sub-directory will not contain a ..
Time complexity required: O(n) where n is the size of the input string.
Notice that a/aa/aaa/file1.txt is not the longest file path, if there is another path aaaaaaaaaaaaaaaaaaaaa/sth.png.

Tuesday, April 25, 2017

Reverse Words in a String

Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
  • What constitutes a word?
    A sequence of non-space characters constitutes a word.
  • Could the input string contain leading or trailing spaces?
    Yes. However, your reversed string should not contain leading or trailing spaces.
  • How about multiple spaces between two words?
    Reduce them to a single space in the reversed string.

Monday, April 24, 2017

LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
Follow up:
Could you do both operations in O(1) time complexity?
LRUCache cache = new LRUCache( 2 /* capacity */ );

cache.put(1, 1);
cache.put(2, 2);
cache.get(1);       // returns 1
cache.put(3, 3);    // evicts key 2
cache.get(2);       // returns -1 (not found)
cache.put(4, 4);    // evicts key 1
cache.get(1);       // returns -1 (not found)
cache.get(3);       // returns 3
cache.get(4);       // returns 4

Thursday, April 20, 2017

Longest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring"pwke" is a subsequence and not a substring.

Number of 1 Bits

Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return 3.

Wednesday, April 19, 2017

Min Stack

Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

push(x) -- Push element x onto stack.
pop() -- Removes the element on top of the stack.
top() -- Get the top element.
getMin() -- Retrieve the minimum element in the stack.
MinStack minStack = new MinStack();
minStack.getMin();   --> Returns -3.
minStack.pop();;      --> Returns 0.
minStack.getMin();   --> Returns -2.

Tuesday, April 18, 2017

Maximum Depth of Binary Tree

Maximum Depth of Binary Tree

Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.