Eclipse: improve html formatting

When format html file in eclipse, some tags such as input, td, th ... will be put on one line and break line at middle of tag when it reach to max character of one line, make it hard to read.

It's becasue of these tags is inline, and eclipse format all side by side inline tags in to one line.

To fix this, just remove these tags from inline list at: Window -> Preferences -> Web -> HTML Files -> Editor -> Inline Elements.

Eclipse: "No repository found containing ..." when install update

I got following errors when installing the update:
An error occurred while collecting items to be installed
session context was:(profile=epp.package.jee, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).
No repository found containing: osgi.bundle,org.eclipse.team.svn,0.7.9.I20110318-1700
No repository found containing: osgi.bundle,org.eclipse.team.svn.core,0.7.9.I20110523-1700
No repository found containing: osgi.bundle,org.eclipse.team.svn.help,0.7.9.I20110318-1700
No repository found containing: osgi.bundle,org.eclipse.team.svn.mylyn,0.7.9.I20110318-1700
No repository found containing: osgi.bundle,org.eclipse.team.svn.ui,0.7.9.I20110523-1700
No repository found containing: org.eclipse.update.feature,org.eclipse.team.svn,0.7.9.I20110523-1700
No repository found containing: org.eclipse.update.feature,org.eclipse.team.svn.mylyn,0.7.9.I20110523-1700
No repository found containing: org.eclipse.update.feature,org.eclipse.team.svn.resource.ignore.rules.jdt,0.7.9.I20110523-1700


It because of some package missing dependency (i dont know why).

Solution is:

1. Go to: Window -> Preferences -> Install/Update -> Available Software Sites.

2. Uncheck update sites one by one then perform update to find out where is that missing dependency package come from.

With each update site cause problem, do steps 3, 4 and 5:

3. Copy update site url and remove update site from "Available Software Sites" window.

4. Go to: Help -> Install New Software.

5. Put copied url into "Work with" field and click "Add" -> click "Ok" when eclipse ask for name -> close window.

6. After all, perform update again.

Eclipse: Exclude folder from validation

Eclipse version: Neon.3 Release (4.6.3)

1. Right click on project name in "Project Explorer" -> select "Properties".

2. Select "Validation" -> check "Enable project specific settings".

3. Click setting in which type of validation that need to exclude from.

4. In new popup, click "Add Exclude Group" -> click "Add Rule".

5. Select "Folder or file name".

6. Click "Browse Folder" -> select folder inside current project to exclude.

7. After all, we need to clean project to take effect.

Note that some time validation type will auto unchecked columns "Manual" and "Build" in validator list window at step 2, so we need to check it again.

Javascript: Promise understanding

1. Return value of .then() function (.catch() is exactly same)

Let's check this code
var promise1 = new Promise(function(resolve, reject) {
  // code here
});

var promise2 = promise1.then(param1); // promise2 is a promise
If param1 is not a function, promise2 = promise1.
If param1 is a function but promise1 is rejected (param1 is not called), promise2 = promise1.
If param1 is a function and promise1 is resolved (param1 is called), promise2 is new promise and state as below:
var promise1 = new Promise(function(resolve, reject) {
  // code here
});

var promise2 = promise1.then(function param1() {
  // code here

  return return1;
});
If param1 has exception, promise2 is rejected.
If param1 has no exception and return1 is not a promise, promise2 is resolved.
If param1 has no exception and return1 is a promise, promise2 = return1.
Note: when .then() have two param promise1.then(param1, param2).
If promise1 is resolved, return value same as promise1.then(param1)
If promise1 is rejected, return value same as promise1.then(null, param2) and same as promise1.catch(param2)

2. Params

From above code, if we call promise2.then():
promise2.then(function(param3) {
  // code here
});
If promise2 is resolved and return1 is not a promise, param3 = return1.
If promise2 is resolved and return1 is a promise, param3 is whatever pass on resolve() function inside return1.

Git: Setting up private server on CentOS via HTTP using git-http-backend

1. Install git and apache

Open terminal and run commands:
$yum install httpd git
Start apache
$apachectl start

2. Create users file

/etc/git-users
username:password
othername:otherpassword
If you don't know how to create that file then install nano editor:
$yum install nano
and create file
$nano /etc/git-users
enter content and press Ctr + O to save, Ctr + X to exit.

3. Create folder that you want to push git base in

$mkdir /var/www/git

4. Create apache config file

/etc/httpd/conf.d/git.conf
SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]

<LocationMatch "/git">
  Order Deny,Allow
  Deny from env=AUTHREQUIRED

  AuthType Basic
  AuthName "Git Access"
  AuthUserFile /etc/git-users
  Require valid-user
</LocationMatch>
If you don't know how to find apache config folder, use this command
$apachectl -V
For example we found that apache config file in /etc/httpd/conf/httpd.conf then we create file
/etc/httpd/conf.d/git.conf
Restart apache
$apachectl restart

5. Create git base

$cd /var/www/git # folder that we created in step 3
$mkdir test.git
$cd test.git
$git init --bare --shared
Open config file /var/www/git/test.git/config in git base then add this
[http]
 receivepack = true

6. Using

Access git server via http://your_server_ip_address/git/test.git with username and password set at step 2.

Eclipse: Tomcat integration

1. Download and install tomcat

You can either install tomcat or use portable versions from http://tomcat.apache.org/.

2. Create tomcat runtime environment

Open eclipse (we use eclipse java EE) and go to: Window -> Preferences -> Server -> Runtime Environments then click "Add".


Select tomcat version to fit with your installed tomcat (for example with tomcat 8.0.41 we select "Apache Tomcat v8.0") then click "Next".


Browse to your tomcat installed folder (or portable version folder).


Click "Finish".

3. Set runtime environment for project

This step is not for project runing but for fix some problems like "The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path".
Right click on your project and select Properties -> Targeted Runtimes then select tomcat runtime that we created above.


Click "Ok".

4. Create server and add project to run

Go to Window -> Show View -> Servers to open server tab.


Click link to create new server. Select runtime environment created above and click "Next".


Add your project to server and click "Finish".


Right click on server and select "Start" to run.


View runing project on browser.

CSS: min-height 100% of browser window

When we want to set min-height: 100% (of browser window), we must set all parents height: 100% (not min-height: 100%).
Let’s see this code:
<div id="wrapper">
  <div id="content">
    <div id="box">
      <div id="text"></div>
    </div>
  </div>
</div>

set #wrapper min-height: 100%

html, body {
  height: 100%;
}

#wrapper {
  position: static; /* or relative */
  min-height: 100%;
}

or set #content min-height: 100%

html, body, #wrapper {
  height: 100%;
}

#content {
  position: static; /* or relative */
  min-height: 100%;
}

now what if we want to set both #wrapper and #content min-height: 100%

this will not working:
html, body {
  height: 100%;
}

#wrapper {
  min-height: 100%;
}

#content {
  min-height: 100%;
}
min-height 100% in #content is not working because it’s parent hasn't height 100%
instead do this:
solution 1
html, body {
  height: 100%;
}

#wrapper {
  position: relative;
  min-height: 100%;
}

#content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
solution 2 (best)
html, body {
  height: 100%;
}

#wrapper {
  display: table;
  width: 100%; /* need when display table to be normal block */
  height: 100%; /* not min-height */
}

#content {
  display: table;
  width: 100%; /* need when display table to be normal block */
  height: 100%; /* not min-height */
}
use solution 2 to make multiple nest tags with min-height 100%.

MySQL: Copy table structure to excel using Sequel Pro

Just run this command and copy all results:

describe table_name;
Or if need more infomation about structure:
SELECT * from information_schema.columns
WHERE table_schema = 'database_name'
AND table_name = 'table_name';

Or export to file:

SELECT * from information_schema.columns
WHERE table_schema = 'database_name'
AND table_name = 'table_name'
INTO OUTFILE '/tmp/export.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n';

OSX: Make bash alias

1. Open ~/.bash_profile or create a new one

nano ~/.bash_profile

2. Add new alias to bottom of file

For example i add alias to get my ip address:
alias myip='ipconfig getifaddr en0'

3. Add refresh bash environment on terminal start up

Open terminal's preferences and add source ~/.bash_profile;clear like this:

Restart terminal and try command myip
Now alias will available wherever you open a new terminal or new tab.