Thursday, December 6, 2018

command + shift + G

command + shift + G is a handy shortcut.
In eclipse IDE, it means search the reference of a method in workspace, which is similar to Control + Option + H.

In mac os x finder, it means go to directory.

A useful usage scenario is as follows:

You look up a java method's references in workspace by typing command + shift + G, then  find an interesting class. You want to share the file to your coworker. So you right click the file, select properties, find the path in location, copy the path.

You then click finder icon or type command + space to open spotlight then type finder to open the finder.

Next you type command + shift + G to invoke "go to directory" UI, then paste the path and type enter. The finder will land on the file you want to send.

You then hightlight the file then drag it into the slack window to share it.

Tuesday, November 6, 2018

7 useful mac os x command line tools

Mac OS X has Darwin Unix like os. There are command line tools you can use in the console.

1. brew is a command to install other command line tools for mac os x.
To install brew and add the brew binary into the PATH, run the following commands in the console.


mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew;

echo export PATH=`pwd`/homebrew/bin:'$PATH' >> ~/.bashrc;
source ~/.bashrc;
which brew;

The last command "which brew;" should give the full path to brew binary file.

Now you have brew command available, you can install other command line tools easily.

2. pigz is a tool that is gzip equivalent but runs faster by exploiting parallel computing. pigz is useful when you need to unzip contents with gzip or zlib format. For example, you rabbitmq messages might be zlib compressed, then base64 encoded. Your decoding commands might looks funny:
base64 -D input.txt | pigz -d -z -c

To install pigz, issue the following command:
brew install pigz

3. apache bench (ab) is a command line tool that allows you to bench mark web sites. The most useful flag is -c, which allows you to specify the number of concurrent http requests sent to the host each time.
For example:

ab -n 100000 -c 10 -t 30 http://xyzcode.blogspot.com/

the above commands send total 10000 requests to xyzcode.blogspot.com, each time, 10 concurrent requests are sent.

ab is installed by default on mac os x, type which ab to check out. In case it is missing, you can install it with command:
brew install ab

4. pybot is a command line tool that automate stuff like ssh, web browsing etc. It is equivalent to have a robot to type the keyboard and read the screen then act upon it for you.

To install pybot, issue the following command:
brew install robot-framework

Since brew also installed python's package management tool, you can also use pip to install pybot:
pip install robotframework

5. in case pybot is an overkill for you, you can use expect command to automate ssh chat with remote hosts like a robot. Expect commands expect input, then send the response without any user interaction.
expect script is installed by default, check the installation path with
which expect;

6. zgrep is a better tool than grep.
zgrep allows you to grep content in zip files and normal files. It will be useful to search something in current log and backup logs.
The flexible syntax really compliments your searching strategy. So if you know the log will looks like

2018-11-07 16:42:25-05 HostNameppp Sophos Installer[72881]: [SGCCDFSBroker.m:306] Feedback json file was successfully uploaded (status code: 201).

Your searching strategy could be:
zgrep -i 'Sophos.*json.*successful' /var/log/install.log

each .* separated string became a filter string, so that you can narrow down the search.

You can use or syntax like:
zgrep -i 'Sophos.*json.*successful' /var/log/install.log | grep --color '72881\|72889'

zgrep is installed by default
which zgrep; will give you the installation location.

7. mysql is a command line tool to query mysql database. It allows you scripting mysql queries. You can pipe the result into zgrep to search relevant information.

mysql --host mysql.local -uuser -ppass -e 'select * from ct_prov.Student\G'

to install mysql command line tool
brew install mysql




Wednesday, October 31, 2018

7 tips for text edit efficiency

1. Inside chrome, use option + command + left to move tab by tab from left to right, use option + command + right to move tab by tab from right to left.

2. Inside chrome, right click then click inspect, then click network. Refresh the page to view the page loading process.

3. install chrome tools to handle json, xml etc.
jsonEditer to tidy and modify json string
https://chrome.google.com/webstore/search/jsonEdit?hl=en

ooxml tool to edit and compare xml files
https://chrome.google.com/webstore/detail/ooxml-tools/bjmmjfdegplhkefakjkccocjanekbapn?hl=en

4. install diffmerger to compare files side by side
https://sourcegear.com/diffmerge/downloads.php

5. use --color option to highlight text (good for your eye), use --text option to avoid searching missing in zip files with special characters.
>zgrep KEY --color --text demoClient.key
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----

6. In xterm2, if you get a huge file which can not be displayed on one screen, click Session -> Edit Session -> Terminal -> then modify scroll back lines to a bigger number.
7. In xterm2, if you want to view several terminals side by side, type command + D to split horizontally, click command + shift + D to split vertically, then type command + shift + i to type in all the terminals. Type command + shift + i again to negate the effect.

Wednesday, October 17, 2018

How to exit java ExecutorService without calling shutdown method

The java Executor framework encapsulated the thread lifecycle management under interface ExecutorService. By default, the ExecutorService implementation returned by Executors needs programmer to call shutdown() method to stop it. Forget to call shutdown for an ExecutorService will prevent the JVM to exit. The JVM won't exit if there are any non-daemon thread still running. The worker threads in the ExecutorService's thread pool won't exit unless you interrupt them, in another words, they will still be running after the main thread exits. These worker threads prevent JVM to exit.

For example, the following program will never finish.


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TheadTester {
public static void main(String... args) {
TheadTester ts = new TheadTester();
ts.test();
}

private void test() {
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> System.out.println("ok"));
//exec.shutdown();
}
}

You can override the default ThreadFactory, so that the worker thread in the thread pool will be daemon thread. Since daemon thread won't prevent JVM to exit, you don't have to call ExecutorService's shutdown() method. This approach has drawbacks, though. Once the main thread exits, the only threads remain are the worker daemon threads in the threadpool. When JVM exits, these threads may still have work to do. Since they are daemons, JVM won't wait them to finish. You need to give enough time for these daemon threads to finish the work and run to the last line so that they can exit normally instead of abruptly.


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TheadTester {
public static void main(String... args) throws InterruptedException {
TheadTester ts = new TheadTester();
ts.test();
//give enough time for deamon thread to finish
Thread.sleep(2000);
}

private void test() {
ExecutorService exec = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
});
exec.execute(() -> System.out.println("ok"));
//exec.shutdown();
}
}

This trick may be trivial, but it could be handy in big java project. For example, you need to add an ad-hoc threadpool in a class in a big project. If you use default ThreadFactory for the ExecutorService, you have to shutdown the ExecutorService somewhere. This "somewhere" might be in a thread that shutdown project level services before main thread exits, which you would rather not touch. You just want to create an ad-hoc threapool to handle events for a shot period of time, finish it, then exit. Next time, when new events come, you create a new threadpool to handle it. So on and so forth. The deamon worker strategy might be a good choice in this situation.

Tuesday, October 9, 2018

tools for handling multiple ssh on mac os x

If you ever worked in cooperate environment or be the network administrator, you sometimes need to login many servers and check stuff simultaneously.

On windows, you can use putty or smart putty to handle multiple ssh connections.

Here are some tools for mac os x equivalent.

csshx

installation:

brew install csshx

usage:

csshx --login username host1 host2 host3 host4

xterm

installation:

download the mac version from the xterm website www.iterm2.com 

usage:

add a connection profiles:

click Profiles -> Open Profiles... -> Edit Profiles -> click the + sign to add a list of hostnames and ip addresses you would like to connect to -> when creating a host record, select command radio button then type in ssh command.



open multiple profiles simultaneously in tabs:

click Profiles -> Open Profiles... -> use shift or control key to hightlight a list of hosts you want to connect to -> click New Tab
The highlighted hosts will be connected and open in tabs.

send commands to multiple tabs:

click Shell -> Broadcast Input -> Broadcast Input to All Panels in All Tabs



Monday, September 24, 2018

7 tools providing visibility for maven dependency tree

With maven pom.xml, you can have maven manage your project's dependency automatically. Whenever your project's code needs classes in a jar file, you can specify the dependency in your pom.xml, and give it a scope to specify whether this jars is needed for compile time, run time or test time. As long as the jars exist in maven repository, they will be downloaded into your local repository, which by default under ~/.m2/repository. Your project will include a set of jars which you specify in your pom.xml, they maps to the jar folders in ~/.m2/repository, and maven will include them in classpath. Those depended jars also has dependency specified in their own pom.xml. Maven goes one step further to download all the jars in the dependency chain, and have a set of rules to figure out which jar version takes precedence when it is declared in multiple places -- for example, when a jar version is declared in both parent pom and child pom, child pom takes precedence.

Enough theory about maven, here are 7 tools help you get visibility of maven dependency tree.
The example maven project used below can be checkout with "git clone https://github.com/GoogleCloudPlatform/appengine-gcs-client.git"

1. locate the dependency jar file. The groupId + artifactId + version in your pom.xml file is mapping to the corresponding directory. for example <groupId>org.codehaus.mojo</groupId> + <artifactId>versions-maven-plugin</artifactId> + <version>2.2</version> in the following example maps to ~/.m2/repository/org/codehaus/mojo/versions-maven-plugin/2.2/



>grep groupId pom.xml -A 2
    <groupId>com.google.appengine.tools</groupId>
    <artifactId>appengine-gcs-client-example</artifactId>

--
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>${appengine.version}</version>
--
            <groupId>com.google.appengine.tools</groupId>
            <artifactId>appengine-gcs-client</artifactId>
            <version>0.6</version>
--
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
--
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
--
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-stubs</artifactId>
            <version>${appengine.version}</version>
--
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.2</version>
--
                <groupId>org.apache.maven.plugins</groupId>
                <version>3.5.1</version>
                <artifactId>maven-compiler-plugin</artifactId>
--
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
--
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.version}</version>
--
              <groupId>com.google.appengine</groupId>
              <artifactId>gcloud-maven-plugin</artifactId>
              <version>${gcloud.plugin.version}</version>
>ls ~/.m2/repository/org/codehaus/mojo/versions-maven-plugin/2.2/
_remote.repositories versions-maven-plugin-2.2.jar versions-maven-plugin-2.2.pom
m2e-lastUpdated.properties versions-maven-plugin-2.2.jar.sha1 versions-maven-plugin-2.2.pom.sha1
>      

In eclipse, you can hold command key and click a dependency in your pom.xml to step into the dependency jar's pom.xml file which located in a folder under ~/.m2/repository.

2. display dependency tree. The command "mvn dependency:tree" will display the dependency hierarchy in a tree structure. For example, com.google.oauth-client:google-oauth-client:jar:1.21.0:compile is an indirect dependency introduced by com.google.appengine.tools:appengine-gcs-client:jar:0.6:compile in your pom.xml.


>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building appengine-gcs-client-example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ appengine-gcs-client-example ---
[INFO] com.google.appengine.tools:appengine-gcs-client-example:war:1.0-SNAPSHOT
[INFO] +- com.google.appengine:appengine-api-1.0-sdk:jar:1.9.36:compile
[INFO] +- com.google.appengine.tools:appengine-gcs-client:jar:0.6:compile
[INFO] |  +- com.google.guava:guava:jar:19.0-rc1:compile
[INFO] |  +- joda-time:joda-time:jar:2.3:compile
[INFO] |  +- com.google.apis:google-api-services-storage:jar:v1-rev68-1.21.0:compile
[INFO] |  |  \- com.google.api-client:google-api-client:jar:1.21.0:compile
[INFO] |  |     \- com.google.oauth-client:google-oauth-client:jar:1.21.0:compile
[INFO] |  +- com.google.api-client:google-api-client-appengine:jar:1.25.0:compile (version selected from constraint [1.19,2.0))
[INFO] |  |  +- com.google.oauth-client:google-oauth-client-appengine:jar:1.25.0:compile
[INFO] |  |  |  \- com.google.oauth-client:google-oauth-client-servlet:jar:1.25.0:compile
[INFO] |  |  |     \- com.google.http-client:google-http-client-jdo:jar:1.25.0:compile
[INFO] |  |  +- com.google.api-client:google-api-client-servlet:jar:1.25.0:compile
[INFO] |  |  |  \- javax.jdo:jdo2-api:jar:2.3-eb:compile
[INFO] |  |  |     \- javax.transaction:transaction-api:jar:1.1:compile
[INFO] |  |  \- com.google.http-client:google-http-client-appengine:jar:1.25.0:compile
[INFO] |  +- com.google.http-client:google-http-client:jar:1.25.0:compile (version selected from constraint [1.19.0,2.0))
[INFO] |  |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.5.5:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.9:compile
[INFO] |  |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  |  |  \- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  \- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] |  \- com.google.http-client:google-http-client-jackson2:jar:1.25.0:compile (version selected from constraint [1.19,2.0))
[INFO] |     \- com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] \- com.google.appengine:appengine-api-stubs:jar:1.9.36:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.037 s
[INFO] Finished at: 2018-09-24T21:19:12-04:00
[INFO] Final Memory: 17M/226M
[INFO] ------------------------------------------------------------------------
>

In eclipse, it is equivalent to the "Effective POM" tab's output.


The eclipse even goes one step further to list all the jar dependency chains in "Dependency Hierarchy" tab. Those needed but overruled jar versions are marked as "omitted for conflict".


3. you can force maven to download the source code for your jar files if they are available in maven remote repository. "mvn dependency:sources".

You can do the same in eclipse by right click a project -> Maven -> Download Sources


4. Sometimes you get a dependent jar that almost meets your requirement except some small dissatisfaction. You can check out the source code from svn, git, etc, modify the code, then issue "mvn install". This command will publish an artifact into your local repository. Other project want to use them can reference it with a dependency entry in pom.xml. For example, run "mvn clean install" for the example will create an artifact under .m2/repository/com/google/appengine/tools/appengine-gcs-client-example/1.0-SNAPSHOT/appengine-gcs-client-example-1.0-SNAPSHOT.pom, you can reference this artifact with

      <dependency>
            <groupId>com.google.appengine.tools</groupId>
            <artifactId>appengine-gcs-client-example</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>

        </dependency>

in other projects' pom.xml.

You can do the same in eclipse, by right clicking the project, then selecting Run as, then clicking Maven Install. Notice due to eclipse bug,  org.codehaus.mojo:versions-maven-plugin can not be executed, I comment it out to get the maven install running. It won't hurt main functionality, this plugin as the name says, is a nice to have step during compile.


5. You can build maven project with command line, then import the built project into eclipse or have eclipse synchronize with the update. To import an maven project in eclipse, you click File -> Import -> expand maven folder, select "Existing Maven Projects" -> click Next -> browse to the pom.xml you wan to import. To update maven project in eclipse, whenever you built maven project with command line, you right click the project, select maven then click "update project...". 

6. You can inspect exactly what jars your eclipse project has in the classpath, these jars are introduced by maven plugin. 



7. Finally, you resolved the dependency issue by specifying a particular dependent jar version to override the maven chosen version or adding a list of <exclusions><exclusion></exclusion>...</exclusions>  under some <dependency></dependency> to force maven to reconsider the version. Problem now solved, you can update the project versions to a higher one to mark this fix. You can change multiple pom.xml file versions with command "mvn versions:set -DnewVersion=1.3.x-SNAPSHOT. The versions:set goal will automatically climb up local directories to find the aggregation root. It will automatically update explicitly referenced dependencies.


Wednesday, September 5, 2018

7 useful google search syntax

We use google search all the time, mostly by typing a keyword into the search bar and press enter. This gives us lots of content, sometimes more than needed. With some constrain, we can narrow down the search.
  1. "java +xyzcode" this will search java, but the page must contains xyzcode, you can change + to - to indicate that the page must not contain xyzcode.
  2. "cache:xyzcode.blogspot.com" this will search google cached page history. As a blogger, if you saved something by mistake, don't panic, google has the backup. 
  3. "site:xyzcode.blogspot.com java" this will search java only on website xyzcode.blogspot.com
  4. "filetype:pom JGraphT" this will search JGraphT only in file type pom.
  5. "inurl:xyzcode" this will search xyzcode in the url itself.
  6. "xyzcode@facebook" this will search xyzcode in facebook.
  7. "#xyzcode" this will search hashtag xyzcode.

Sunday, September 2, 2018

how to setup ASUS HOME SERVER with mac os x

This is a small trick but will be handy if you need to access the ASUS HOME SERVER with system other than windows. The menu asked the user to install an windows application in order to access the server. However, notice the ASUS HOME SERVER are actually a reconfigured windows server 2003 with IIS server 6 up running. You can login it from you LAN with microsoft remote desktop.

Download and install microsoft remote desktop, configure the connection. You can find the ASUS HOME SERVER's LAN ip from your gateway router. The server generally don't response to LAN broadcast.

connect to windows server
connect to windows server


Double click the remote desktop icon to login, when ask for the administrator password, put the one you used to setup the server at the first place.

Once logged in, the windows home server console application is right there on the desktop, double click it, then you can configure the server as if you installed a windows access app. You will feel happy because this is actually a IIS server machine with windows server 2003 functionalities.

windows home server console
windows home server console

7 steps to allow you access your mac os x from internet

You can ssh into your home mac computer while traveling. There are a few steps to do:

step 1, go to system preferences, check sharing, check remote login. Only allow the unprivileged user to remote login, remove admin from the allowed list.

remote login enable
remote login enable


step 2. go to system preferences -> users & groups select the user you need to remote access the computer, change the password to be a very strong one.

step 3. if your firewall is blocking port 22, enable it. Go to system preferences -> Security and Privacy -> Firewall Options.

step 4. schedule wake up, if your computer go to sleep you won't be able to ssh into it. Go to system preferences -> Energy saver -> Schedule



schedule wakeup
schedule wakeup


step 5.  test remote login from LAN address, ssh <user>@<localIp>.

step 6. login your gateway router, add a port forwarding rule, forward port 22 to the ip address of your computer.

port forwarding
port forwarding


step 7. test remote login from internet address. The internet address can be found from gateway router.

You can disable password login and only allow certificate based login, but the above 7 steps should be able get your WAN access goal reached.

Sunday, August 26, 2018

7 mac os x shortcuts combo that save your time

Replacing a few clicks with a keyboard shortcuts seems to be trivial, but the time they save adds up. If you are a computer professional, using shortcuts means you are running at a faster cycle. Here are 7 mac os x shortcuts combos that save tons of time.


  1. Browsing shortcuts combo. When you are browsing websites using a browser, you press command + N to open a new window, then you regret, so you press command + W to close it. You press command + T to open a new search tab instead. You suddenly want to look up something in your local file system. You press command + O to open your Finder. You click a file, press command + I to get detailed information about the file, including the url the file is downloaded from. You are happy about the information, so you command + W to close the information window. Then, you press command + T to open a new finder tab. Here you want to open an document, so you type command + shift + O to switch to Document folder, then you click open a pdf file. Now you want to compare something in the pdf with a webpage, so you press command + tab to switch back and forth between your browser and the pdf viewer.
  2. Configuration shortcuts combo. You suddenly feels boring and want to change every mac os x default settings. Good idea, lets start with the browser window. You press command + "," to open the browser configuration no matter it is chrome, safari or firefox. You click advanced, take a look at your certificates -- suddenly wants to check if your firewall is on. So you press command + O followed by command + shift + U to open the utility folder in Finder. Then you click open the System information application, then verified that the firewall was on. So you regain your happiness and decided to turn the display brighter. The brightness adjusting key is at the top of the keyboard, you can just press it. However, you are very picky, you want more control from the system preference. So you press option + F2 to open the build in display panel in system preference and changed a few thing. How about sound? No problem, press option + F11 opened the Sound panel. You feels the power, so you want to go deeper. You press command + space to open spotlight and type "console" then hit enter. In the console window, you saw the log flows like a creek but there is no error and warning. So you are happier and want to open a terminal, you press command + space to open spotlight and type "terminal" then hit enter. In the terminal, you did your check and changes. There is only one problem -- you just opened too many configurations, its time to close them. 
  3. Closing shortcuts combo. You press F3 the mission control to display all the applications, you then press F3 again to restore the view. Too much stuff, so you press command + F3 to take a look at your clear desktop, draw a deep breath then press command + F3 to bring back the mess. Let's start from Finder windows. You press command + H to bring all the finder windows to the front, then press command + option + W to close them all. You press command + tab to navigate through the applications you have opened. Then you close them with command + W. In case you just want to check how many windows are open for a particular application, you can press control + down arrow to view them. Notice command + W only close active windows for an application, to quit an application, press command + Q.
  4. Reopening shortcuts combo. In case an application is minimized with command + M, you can maximize it with the following shortcuts combo: first select the application by pressing command + tab, then press option + command then release option key. The same trick can be used to reopen previously closed but not quit applications. To reopen a quit application, you press command + space to open spotlight, then type the application name.
  5. Navigating shortcuts combo. You have opened many applications, you press command + tab to navigate through them and land on browser app. Your browser opened many tabs, you press control + tab to navigate through them and stop at a page. The page has tons of contents, so you press option + down arrow and option + up arrow to scroll the contents page by page. The contents is long and you loose patient, so you press command + down arrow to scroll to the end of page, nothing there, so you press command + up arrow to scroll back to the top. Eye balling doesn't work, no worry, you can press command + F to open a finder dialog. Then type in the search string then hit enter. The matches are highlighted, you press command + G and command + shift + G to move your cursor to the next and previous match.
  6. Selecting shortcuts combo. Now you find what you are looking for, you want to copy those text. The shift control option command and arrow key combinations will let you look like a selecting pro. Try these out. shift + left selects one character at left, shift + option + left selects one word at left, shift + control + left selects everything at the left. I don't have to mention how right key behave, right? The up and down keys behave a little bit different. shift + up selects one line above, shift + option + up selects to the beginning of the current paragraph, shift + command + shift selects to the beginning of the text. I don't have to mention how down key behave, right?
  7. Zooming shortcuts combo. It will be nice to zoom in when you are trying to show something to your co-workers. Press command + "=" increases the text size, press command + "-" decreases the text size. Press command + shift + "=" zooms in, press command + shift + "-" zooms out.

Tuesday, August 7, 2018

7 eclipse debugging tips you should know

You may already know that you can set a breakpoint in eclipse for your java code, then have the program stop at the breakpoint in debug perspective, so that you can inspect the variable values or step through the code line by line. These are the basic usage of eclipse debugger. The following 7 tips will allow you do eclipse debug like a pro.

1. Change variable value
When a breakpoint is hit, you can right click a variable value then select "Change Value...".

2. Use breakpoint view
click Window -> Show View -> Breakpoint
In this tab, you can select/deselect breakpoints. High light one of the break point, you can set conditional match such as exceeding a certain hit count or matching a particular value.
For multi-threading program, "suspend VM" option allows you to exam the stack of the other threads. You can shift from one thread's stack to another thread's by clicking the thread name.

3. Use display view
click Window -> Show View -> Display
In this tab, you can write a few lines of code, highlight these code you want to run, then click the little triangle at the upper right corner to execute the code in the context of the breakpoint.

4. be able to inspecting code in project and depended jars.
If you are using maven project, install m2e plugin, then configure it to download both the source files and javadoc by going into Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc" options.


You can search a class in project and depended jars with shortcut Command + Shift + T (mac) or Control + Shift + T (windows).
You can search a string in the workspace with shortcut Control + H.
You can search call hierarchy with shortcut Control + Command + H.

5. Remote debug
When you are trouble-shooting an application running in a remote machine. you need two piece of information: hostname or IP, the debugger port.
If you are not sure what port is the debugger port, you can login the hostname, then issue command
"netstat -nulpt | grep java " and see which ports the java application is listen to, then try these ports one by one.



6. set up tomcat to run local.
If your application produces a war file which can be deployed into tomcat, you can setup eclipse (J2EE) to integrate with tomcat and run your application local, then you can debug the code. To do so, download and unzip tomcat, in eclipse
Preference -> Server -> Runtime Environment
Click Add -> apache -> select the version matching the apache server you downloaded
Click next, browse to the directory of your downloaded apache server.
Click finish


Now you can run your j2EE project local by select Run -> Run As -> Run on Server
Click choose an existing server, then select your apache server from the server list.
Now tomcat will run your project's war file as a web container. Even with apache server configured, you program still need Arguments to be set correctly.

7. Use jrebel for quick deployment. JRebel fast tracks Java application development by skipping the time consuming build and redeploy steps in the development process.

Tuesday, July 24, 2018

7 organizations you should know as a spam victim

Spammers are not just annoying, they sometimes turn into criminal. For example, spammers once get enough personal information, they can impose as the victim, then get more personal information from the friends, relatives, etc. Eventually, they might get some victim to give away credit card number, sending money to strangers etc. If you are reading this post, most likely you won't give away sensitive information at the first place. If you do, you can call 911, otherwise, you can call the local police station for the fraud attempt. Besides that, you can get help from these 7 organizations for telecommunication related crime.


  1. For Consumer Fraud and Identity Theft, contact Federal Trade Commission with phone number 877-3824357,877-4384338, the website: www.ftc.gov
  2. For Disaster-Related Fraud, contact National Center for Disaster Fraud with phone number 866- 7205721, website disaster@leo.gov.
  3. For General Fraud and Other Criminal Matters, contact FBI with phone number 202-3243000, website www.fbi.gov.
  4. For Health Care Fraud, Medicare/Medicaid Fraud, and Related Matters, contact Department of Health and Human Services with phone number 800-4478477, website www.oig.hhs.gov.
  5. For Internet Fraud and Lottery/Sweepstakes Fraud by Internet, contact Internet Crime Complaint Center. www.ic3.gov.
  6. For Mail Fraud and Lottery/Sweepstakes Fraud, contact U.S. Postal Inspection Service at phone number 800-3728347. website: postalinspectors.uspis.gov.
  7. For Securities Fraud, contact Securities and Exchange Commission at 800- 7320330. website: ww.sec.gov/complaint/select.shtml.

7162661793 is a spam caller

(716)266-1793 is a spam caller with bad reputation and many negative reports as a telephone marketer.

Monday, July 16, 2018

7 MAC OS X eclipse short cuts

The eclipse has many keyboard shortcuts that can potentially save you tons of time, so that you can focus on the programing itself instead of navigating the IDE.

If you have to remember one shortcut, remember this one:
Command + Shift + L


It will list all the defined eclipse shortcuts.
From the list, you can pick whatever shortcuts you want to remember. Here is my top 7 list.


  1. Control + Shift + L : list all shortcuts
  2. Control + space bar: content assist. You can type part of a java syntax, then type control + spacebar, the IDE will give you the suggested templates.
  3. Control + shift + space bar: context information, whenever you want hint about a method parameter, put you cursor in the (), then type Control + shift + space.
  4. Control + Shift + H: type search. If you know a class name, you can type Control + shift + H to open a search bar to quickly land on the java file.
  5. Control + option + H: open call Hierarchy. This one do the same as right click and select open call hierarchy, but if you look up lots of code, it adds up.
  6. Command + L: move to line number. This shortcut is handy for trouble-shooting a large file.
  7. Control + E: open editors. This is handy if you have lots of files open.



Tuesday, July 10, 2018

7 Mac OS X tools for web application trouble-shooting

Web applications use server-client pair to communicate via open sockets. In order to trouble-shooting them, we sometimes need to trace requests through computer system. We need to post request to web service end-point and analyze the returned xml, json etc. We sometimes need to check the server logs, databases, splunk, etc. Here are some tools to make these job easy.

TextMate


The software TextMate allows you to format text so that they are easy to read. Json, for example, is intended to be compact, so chances are the json string passed in web application request/response have no space or line break. In order to review the content, you need to format the compact string so that space and line break will be inserted for easy reading. You can copy the json string from a log and paste it into textmate then select json format to get an easy to read version. You can do the same for compact xml string, html string etc.

PostMan


Whenever you need to test rest services, you can use curl commands. However, with PostMan, your life will be easier. This tool allows you to easily construct the request body, set headers, credentials, etc. You can group and save various rest service requests for later use. The request and response are formatted too, sweet.

Iterm


Terminal is a basic scripting environment in mac os x, Iterm is a much better alternative. You can do many cool things such as sending commands to multiple tabs, script login session, split windows, highlight text to copy to clipboard, use many shot-cuts, etc.

Mysql Workbench



This tool manages your mysql database connections. You can browse schema, run query, check result, copy results, export results, analyze performance etc.

Oracle SQL Developer


a free tool to mange oracle database connections. UI provides many features such as browsing schema, view single record, syntax highlighting etc.

Slack


A computer system is developed by a team, so trouble-shooting often involves a team of engineers. Slack allows you to chat with partner, host online meetings across the internet. A meeting channel recorded the trouble-shooting history for later reference.

Notes


Last but not least, organize your thoughts before and after communication. Mac OS X notes is the handy tool for you.

Monday, July 9, 2018

7187911489 and 7187912630 are phishing numbers

7187911489 (718)791-1489 718-791-1489 (718)-791-1489 and 7187912630 (718)7912630 718-791-2630 (718)-791-2630 are phishing numbers. The robots are trying to call your phone in order to collect feedback. Don't give them any response by pressing key or call them back.

7 unix commands for trouble-shooting memory related issue

Your application has been running fine for months until a recent linux patch are applied and you want to figure out what's going wrong.

These commands will be handy during your adventure of figuring out the root cause.

top


top command will give a general idea of how busy your system is and what resources are depleting. It will also list the top consumers of your computer cpu and memory. 

free -ht

free will list all the RAM usage statistics. -h is human readable, -t will print out total. The Total line is where you should find out the amount of free memory for your program. 

df -h

df -h let you check if you have disk full. -h is human readable.

uname -a

this command allow you to check the OS related information. From the output, you will find the kernel version, which may have bug related to performance issue.

lsof -nP | grep '(deleted)'


sometimes, you deleted a large file but your running application still have a reference to the file descriptor. The disk space won't be freed until the application exits. You can find these invisible files with command lsof -nP | grep '(deleted)'.

sar -r


when you want to find the memory usage in the past, sar command will do the job. The command sar have many flags for different resources like cpu, memory or IO, -r flag list the memory usage for today. 

ps -ef | grep java

find out if your java application is still running. To your surprise, it might just exit without any runtime exception in the log. The reason might be memory related.

When java program is running in VM that is configured to overcommit memory, the JVM will suffer from performance issue. A garbage collection which normally completes in hundreds of milliseconds might take minutes to complete in such an environment and the applications within that JVM are frozen during this time. 

“Java provides a special challenge in virtual environments due to the JVM’s introduction of a third level of memory management. The balloon driver draws memory from the virtual machine without impacting throughput because the guest OS efficiently claims pages that its processes are not using. But in the case of Java, the guest OS is unaware of how the JVM is using memory and is forced to select memory pages as arbitrarily and inefficiently as ESX’s swap routine. Neither ESX nor the guest OS can efficiently take memory from the JVM without significantly degrading performance. Memory in Java is managed inside the JVM and efforts by the host or guest to remove pages will both degrade Java applications’ performance. In these environments it is wise to manually set the JVM’s heap size and specify memory reservations for the virtual machine in ESX to account for the JVM, OS, and heap.“



Thursday, July 5, 2018

7 mac os x short cuts for trouble-shooting


When your application run into trouble such as no response, you would like to figure out why or want to quickly move on. Here is some Mac OS X short-cuts that makes your life much easier.

  1. Do you want to quickly switch among different programs without clicking around? Command + Tab, Command + Shift + Tab will list all the open programs and allow you select the high-lighted one. 
  2. Have you ever try to open a program by opening the finder, then navigate to the application folder, then click open a program? There is a much faster way. Command + Space, then type the program name.
  3. windows user might wonder what is the Control + Alt + Delete equivalent in mac os x, the shot-cut is Command + Alt + ESC, use this force quit shortcut, if long clicking a program then select Quit don't work.
  4. Do you want to compare files side by side in shell window? Command + D split a terminal window into 2.
  5. Sometimes, you entered a long command line in terminal, then realized you want to modify the first a few characters. Instead of press left for 10 seconds, you can press fn + left to directly move to the front of the command. The fn + right move your cursor to the end of the command.
  6. Command + T will open a new tab in terminal.
  7. screen shot in mac os x: Command + Shift + 3 takes a full screen screenshot and Command + Shift + 4 takes a screenshot for a select area.

2125174674 is a phishing number

2125174674 or 212-517-4674 or (212)517-4674 is a phishing number. The robot call is trying to get user response so that they can do more damage in the future. Don't give this robot call any response.

Wednesday, June 6, 2018

phishing phone calls from (202) 495 - *

The following phone numbers are phishing numbers claimed to be from Washington, DC. The robot voice is telling some none sense trying to get the receiver to press button or return the call so it can gain personal information. These phone numbers are faked by software, don't give them any feedback in case it is a blind scan.

(202) 495-1110
(202)495-8077
(202)495-1964

help people who are searching these numbers:
2024951110
2024958077
2024951964

202-495-1110
202-495-8077
202-495-1964

Tuesday, May 29, 2018

Use git rebase to squash multiple commits to one

Why bother to squash commits

If you are a svn user, you probably formed a "bad" habit of committing many small changes. For svn, committing lots of small changes is fine, because svn only stores the diff between two commits. For git, committing lots of small changes is not fine, your remote repository will waste lots of disk space for these small changes. Git has a different way of storing your versioned files, unlike svn, git stores a snapshot of all changed files instead of just the diff.

For example, if you have a huge file, and you only changed one line then committed a version to remote repository. In svn, this commit only cost the storage of one line (a diff line is stored); in git, this commit/push costs the disk space of the whole file (a snapshot is stored).

How to squash multiple commits


The squash technique is like this:

Step 1. use "git log" command to figure out how many commits you have pushed to a branch. For example, you have 6 commits in development branch today, and you wish you have committed them as one big commit instead of 6 small ones.

Step 2. use "git rebase Head~6" command to squash unwanted commits. One you issued the command, the 6 commits are displayed in a list. Notice the # comment lines tell you the meaning of pick, edit and squash.
$ git rebase -i HEAD~6

pick 01a3124 add handleReq function
pick 6e342aa typo
pick 341a3ba format a space
pick 234be7 code review update
pick 2ab141c2 add annotation
pick 137a32a4 remove import

# Rebase 321191d.. 137a32a4 onto 321191d
#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

Step 3. you edit the above list using vi commands. For example type "i" to edit. The edited commit lists should looks like:
$ git rebase -i HEAD~6

pick 01a3124 add handleReq function
squash 6e342aa typo
squash 341a3ba format a space
squash 234be7 code review update
squash 2ab141c2 add annotation
squash 137a32a4 remove import

# Rebase 321191d.. 137a32a4 onto 321191d
#
# Commands:
#  p, pick = use commit
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

Step 4. once you typed "wq" the next screen will allow you to edit the commit comments. Use vi command to edit them. Type "i" to modify.

# This is a combination of 6 commits.
# The first commit's message is:
add handleReq function

# This is the 2nd commit message:

typo

# This is the 3rd commit message:

 format a space

# This is the 4th commit message:

code review update

# This is the 5th commit message:

add annotation

# This is the 6th commit message:

remove import

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i nor -o; assuming --only paths...
# Not currently on any branch.
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# new file:   src/main/java/com/fishtank/FishSpecies.java
# modified:   src/main/java/com/fishtank/FishHandler.java
# modified:   src/test/java/com/fishtank/FishHandlerTest.java
# modified:   pom.xml
#

Step 5. after modifying, type "wq" to save and quit.

# This is a combination of 6 commits.
# The first commit's message is:
add handleReq function

# This is the 2nd commit message:

# typo

# This is the 3rd commit message:

# format a space

# This is the 4th commit message:

code review update

# This is the 5th commit message:

#add annotation

# This is the 6th commit message:

#remove import

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i nor -o; assuming --only paths...
# Not currently on any branch.
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# new file:   src/main/java/com/fishtank/FishSpecies.java
# modified:   src/main/java/com/fishtank/FishHandler.java
# modified:   src/test/java/com/fishtank/FishHandlerTest.java
# modified:   pom.xml
#

Step 6. use "git push -f" to replace the remote branch commits with the squashed the commits. The reason to use -f (force) is now your local repository and remote repository have different commits, it is not a merge but a replace instead. You know you would like to replace the remote content with your local content for that branch, so you use -f to force the replace.

What happens if you messed up things

Not a big deal. As long as you didn't issue command "git push -f", the remote repository didn't get effected, you only messed up your local repository. You can issue command "git reset --hard origin/development" to replace your local repository with the remote repository content.

Tuesday, April 10, 2018

13473227341 or 3473227341 is a phishing phone number

My wife received a phone call from 13473227341. The robot claims to be the car dealer, and asks her car's model. After my wife answered the question, the phone is hang.

Searching for 13473227341 yield a Chinese city as origin; after removing the country code 1, searching 3473227341 shows it is a New York phone number.

This kind of robotic phishing phone calls are trying to collect legitimate phone numbers or even personal informations.

The best action is not to give any response and look up for the phone number to tell if it is really belong to a business.

7183180198 is a phishing phone number

Received a phone call from 7183180198, the robot voice is the first sign of phishing call. It claims that she is trying to deliver an import package to me but failed. For more information, press 1.

This number is not a real number, but from phishing software. It is trying to collect phone numbers if you pressed 1.

Sunday, April 8, 2018

How to secure your online assets

Nowadays, almost anybody has some online assets, from an email account you used to apply a job to the computer you used to check you online bank account. Hackers are there looking for these assets. If they thought the assets are valuable, they will try to enter your cyber space stealthily or with brutal force.

You guard your real estate with doors, alarm system, home association, police and most importantly common sense. You need to do the same to you online assets. The following posts are a collection of how to make your home network more secure.

Part one -- end nodes security


Part two -- know your wireless


for network administrators:

Part three -- secure your online account


Part four -- phishing phone call


Part five -- Introduction to network security

for network administrators:
You will learn about network attackers and intruders, how they get in, and how to keep your network save by keeping them out.

The need for network security
Classes of Hacker Attacks
Firewalls and Proxy Servers
The Attacker’s Arsenal
Intro to PIX, ASA, IDS, and IPS
Viruses, Worms, and Trojan Horses
Preventing Virus Attacks

chatgpt's view about universe

 is there god? The existence of a higher power, commonly referred to as "God," is a matter of personal belief and faith. There is ...