How to remove node_modules in git

You may accidentally add the node_modules or you forgot to add the node_modules directory to .gitignore list, no worry, you may remove it after you pushed to the git.

First, add the node_modules in to the .gitignore

vim .gitignore

After added the /node_modules and save it.

git rm -r --cached .
git add .
git commit -m "remove gitignore files"
git push origin master

How to use internal css in WordPress

One of the way to load CSS in your WordPress plugin. You no need to worry about caching while developing your code and no need to separate one more file.

function my_style_inline() {
  $content = file_get_contents(ABSPATH . 'wp-content/plugins/PLUGINNAME/CSSFILENAME.css');
  echo '<style type="text/css">' . "\n";
  echo $content;
  echo "</style>\n";
}
add_action('wp_head', 'my_style_inline');

How To Get Parent Category Name In WordPress

It is not difficult to get the name using the build in function from WordPress. You may use this for build your own plugin or list out the related post using the category data from the parent category.

Here is the PHP Code that can display out the name of the parent category.

<?php
$category = get_the_category();
$parent = get_cat_name($category[0]->category_parent);
if (!empty($parent)) {
echo $parent;
} else {
echo $category[0]->cat_name;
}
?>

How to rebuild /etc/yum.repos.d in CentOS


If you remove all the files in /etc/yum.repos.d you may see this error. You can restore using the way below.

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>
[22:09][~]# cat /etc/redhat-release
 CentOS Linux release 7.3.1611 (Core)

Check your version and reinstall using this way.

[22:09][~]# yum reinstall http://vault.centos.org/7.3.1611/os/x86_64/Packages/centos-release-7-3.1611.el7.centos.x86_64.rpm


How to Solve WordPress asked for FTP credentials

I know it is very annoying when you are going to install a PLUGIN in WordPress. I like the way, one click and install for PLUGINS and THEMES in WordPress. Here is the way that I’m using:

Edit your wp-config.php and add the line into it.

define('FS_METHOD','direct');

Why You Should Never Ever Buy XiaoMi Products ?

I’m not happy with their product, that’s why I write this article to let you know the service and the service policy of their product.
If you are using their product and is working fine, then you are good luck. If there is any problem with their product, you are in big trouble.

For personally, I do not like this brand, but I gave them a chance to try. I bought the model XiaoMi Mi A1 64GB Black on 11 November 2017 at IT City Fashion Island. Since this is the first Android One product from them, I use this for test for my APP development.
Most of the time I just put the phone on my office table and seldom use it unless I update and test for my APP.

Last week, 11 Feb 2019, I found out that the phone cover broken up, and I make a closer look and saw that is the battery expend the size and push the cover up. I’m feel lucky because the battery not yet explode.
So, I try to find out where is their service center. I found out that they do not have any official service center in here, so I have to take it back to the place that I purchase the phone for the service.

That time I passed to them, the LCD screen is still workable and the staff there turn off it and check it, and told me just need to change the battery. Then he charge me for 482 Baht. I thought it is the battery price at first.

So I provide the screenshots for the conversation, let you know what is going on.

Some people said that it is reseller problem, but before that I’ve contacted the Service Company that listed in Xiao Mi Website, https://www.mi.com/th/support/repair/
They told me IT City is a drop point and will send to them for service.

Why I didn’t go to the service company directly ? First you need to understand the working hour traffics in Bangkok is terrible.
The location of the VST ECS is far from my place, around 30KM, and the IT City is just 10KM from my place, sure I chose to take to the drop point.

Conclusion

  • No matter they fix your phone or not, you will get charged, this is their policy.
  • The battery maybe explode after a year of using period.
  • They do not have official service center in here.
  • They want to charge you more and ask you change for the LCD.
  • If you never contact them, they will just put you aside until you contact them, they will never call you.
  • Their service is slow, it can take 2 weeks and 2 weeks.

How to disable AutoSave in WordPress ?

Sometimes we do not need the auto save function in the editor in WordPress, it will increase your database or slow down you editing experience while you are in slow internet connection.

Here is the solution to disable it, if you need to re-enable it just comment them away.

define( 'AUTOSAVE_INTERVAL', 60*60*60*24*365 ); // Set autosave interval to a year
define( 'EMPTY_TRASH_DAYS',  0 ); // Empty trash now: Zero days
define( 'WP_POST_REVISIONS', false ); // Do not save any revisions

Publishing Failed in WordPress

When you post in WordPress with over 5MB text post, you may receive this error with red color.

Publishing Failed

or you found in your php error log

PHP Fatal error:  Maximum execution time of 60 seconds exceeded in /home/nginx/domains/juzhax.com/public/wp-includes/formatting.php on line 2295

This is because WordPress need more time to execute and process and formatting your post over the maximum execution time.

You may use the way below to solve this.

Edit the file wp-config.php and add in the line


@ini_set('max_execution_time', 1800);

But, use this with caution, because if many of your script in WordPress over this time, this way maybe kill your server.

An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.

Gem files will remain installed in /var/www/discourse/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.2 for inspection.
Results logged to /var/www/discourse/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0-static/mysql2-0.5.2/gem_make.out
An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' succeeds before bundling.
In Gemfile:
mysql2

I found the best way to solve the problem.

I think that you may missing the dev library of mysql:

On ubuntu

sudo apt-get install libmysqlclient-dev

On Red Hat/CentOS and other distributions using yum:

sudo yum install mysql-devel

On Mac OS X with Homebrew:

brew install mysql