Scenario:
I need to output some testing data using logger.debug, logger.info and write the JUnit test case to verify the logger output.
https://github.com/justinchuch/testing_junit
Scenario:
I need to output some testing data using logger.debug, logger.info and write the JUnit test case to verify the logger output.
https://github.com/justinchuch/testing_junit
Let’s review some mathematics!
Change a number n in base 10 to a number m in base x!
Let n be 110, x = 62,
110 / 62 = 1 … 48
1 / 62 = 0 … 1
So m = [1][48]62
To convert back:
48 * 620 = 48
1 * 621 = 62
48 + 62 = 110
According to the Oracle Java doc:
The signed left shift operator “<<” shifts a bit pattern to the left, and the signed right shift operator “>>” shifts a bit pattern to the right.
The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand.
The unsigned right shift operator “>>>” shifts a zero into the leftmost position, while the leftmost position after “>>” depends on sign extension.
| Left shift: | |
| x << n = x * 2^n | |
| Example: | |
| if x = 1, n = 3 | |
| 1 << 3 = 1 * (2^3) = 8 | |
| — — — — — — | |
| Right shift: | |
| x >> n = x / (2^n) | |
| Example: | |
| if x = 16, n = 2 | |
| 16 >> 2 = 16 / (2^2) = 4 |
Good place to start for beginners who want to learn about Docker!
https://docker-curriculum.com/
If you need to work with Spring, read the official guide by Spring!
Learn is fun!
Use google-java-format library to format and cleanup the java source code:
You need:
In the build.xml, define two targets. Make sure you change the corresponding properties!
<!-- google java format [start] -->
<target name="google_java_format">
<fail unless="google_java_format.srcfile" />
<echo message="google java format source file: ${google_java_format.srcfile}" />
<java classname="com.google.googlejavaformat.java.Main" fork="true" maxmemory="1024m" jvm="${java8_jvm}">
<arg value="-a" />
<arg value="-r" />
<arg value="${google_java_format.srcfile}" />
<classpath>
<pathelement location="${project.dir}/lib/google-java-format-1.3-all-deps.jar" />
</classpath>
</java>
</target>
<target name="google_java_format_all">
<fail unless="testcasename" />
<echo message="google java format: ${testcasename}" />
<!-- for each testcase -->
<foreach param="google_java_format.srcfile" target="google_java_format">
<path>
<fileset dir="${src}/${testcasename}" includes="**/*.java" casesensitive="yes" />
</path>
</foreach>
</target>
<!-- google java format [end] -->
Quick note, keeping good practices for source code management:
After git clone from a master branch,
Branch
Create a branch for working (e.g. dev):
git branch <branch name>
git branch dev
Add the files
git add
Add the updated files
git add -u
Commit the changes
git commit -m "What are the changes ..."
Push the branch to remote (if necessary)
git branch push origin <branch name>
git push origin dev
Tag
Create tag
git tag -a <tag name> -m “<tag description>”
git tag -a v0.1 -m "Version description" git push origin v0.1
Push the tag to remote
git push origin <tag name>
git push origin v0.1
Pull
Pull from remote before merge / rebase or push to avoid and resolve conflicts
git pull origin <branch name>
git pull origin dev
Merge
Switch to target branch first:
git checkout <target branch>
git checkout master
Merge from source:
git merge <source branch>
git merge dev
Rebase
Switch to target branch first:
git checkout <target branch>
git checkout master
Rebase from source:
git rebase <source branch>
git rebase dev
Push the changes to remote (if necessary)
git push origin <branch name>
git push origin master
In MacOS, the following command can be used to find and replace text in multiple files:
find . -type f -name <files> -exec sed -i ” s/<to be replaced>/<replaced by>/ {} +
Example:
Replace text target=”1.4″ with target=”1.6″ in all xml files under the current directory and the sub-directories.
| find . -type f -name '*.xml' -exec sed -i '' s/target=\"1.4\"/target=\"1.6\"/ {} + |
To compact / shrink the VirtualBox vdi, run the following command:
VBoxManage modifymedium --compact <vdi file, e.g. ubuntu-14.04.vdi>
To clone the VirtualBox vdi, use the following command:
VBoxManage clonemedium <source vdi file, e.g. source.vdi> <new vdi file, e.g. new.vdi>
To reset the hd uuid of a VirtualBox vdi, run the following command:
VBoxManage internalcommands sethduuid <vdi file, e.g. ubuntu-14.04.vdi>
References:
https://www.virtualbox.org/manual/ch08.html
1. ssh-keygen: to generate the ssh key pair
Use the default or enter the preferred path
E.g.
~/.ssh/justin/justin_id_rsa
2. ssh-copy-id: to copy the ssh-id to the remote host
ssh-copy-id -i <ssh pub key location> <remote host or ip>
E.g.
ssh-copy-id -i ~/.ssh/justin/justin_id_rsa.pub 192.168.0.1
3. Edit ~/.ssh/config
On the local side, edit the config file:
Host homeserver HostName 192.168.0.1 IdentityFile ~/.ssh/justin/justin_id_rsa User justin
Extra:
We can run command remotely through ssh, for example:
ssh homeserver "mkdir -p ~/test"
Reference(s):
http://askubuntu.com/questions/520030/script-that-ssh-to-remote-host-enters-pass-and-executes-a-command
http://stackoverflow.com/questions/2419566/best-way-to-use-multiple-ssh-private-keys-on-one-client
Things to do after fresh install of Ubuntu:
#ubuntu
sudo apt-get update
sudo apt-get install software-properties-common python-software-properties
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer