Best Practices to Handle Exceptions in Java


Autoboxing and Unboxing Tips and Traps in Java


Add Google Custom Search to WebSite


Git Tips Tricks for Developers


Untitled

Install Bash git completion

  • brew install git bash-completion

Caching GitHub password in Git

  • git config --global credential.helper 'cache --timeout 72000'
  • Remove cached password (to reenter new password when it’s changed)
    • git credential-osxkeychain erase

Temporarily ignoring files

  • git update-index --assume-unchanged file-path
  • git update-index --no-assume-unchanged file-path

Remove file from the repository but keep it locally

  • git rm --cached -r somedir/somefile then add them to .gitignore

Reset current HEAD to the specified state

undo last commit
  • git reset --soft HEAD~1
  • Undo commits permanently: git reset --hard HEAD~3
    • The last three commits (HEAD, HEAD^, and HEAD~2) were bad and you do not want to ever see them again.
  • Undo a merge or pull inside a dirty working tree: git reset –merge ORIG_HEAD
  • return to any previous revision
    • git reset --soft commit_hash
  • Reset committed changes to local changes
    • git reset HEAD~

undo git pull

  • git reset --hard

Reset local branch to be same as remote branch

  • git fetch --all && git reset --hard upstream/master
  • If need delete everything(just like re-clone): git clean -x -d -f

~ vs ^

  • Both ~ and ^ on their own refer to the parent of the commit.
  • ~2 means up two levels in the hierarchy, via the first parent if a commit has more than one parent
  • ^2 means the second parent where a commit has more than one parent (i.e. because it’s a merge)
  • HEAD~2^3 means HEAD’s grandparent commit’s third parent commit.

rebase

Edit your X most recent commits interactively (squash, fixup, reword, drop)
  • git rebase -i HEAD~X
Modify a specific commit
Split a commit in two with Git
Delete a commit
  • If it is the last commit this is very straight forward. git reset HEAD

Branch

  • Delete local branch: git branch -d <local_branchname>
  • Delete remote branch: git push origin --delete <remote_branchname> or git push origin :<remote_branchname>
  • Rename local branch name: git branch -m <new-branch-name>
Checkout remote brach

git log

  • git log –oneline [–pretty=oneline]
Show commit id only
  • git log -1 –pretty=format:“%H”

View change in a specific commit

  • git show

Undo anything

Wipes your unstaged changes
  • git checkout
undo rm -rf * - git stash - if no local update

undo git commit –amend

  • git reset –soft HEAD@{1}
Checkout remote file after merge conflict
  • git checkout HEAD the_file

shallow clone

  • git clone --depth 1 https://path/to/repo/foo.git -b bar
  • –no–single–branch instead -b bar, to download first commit form ALL branches.
  • –no-checkout(-n): No checkout of HEAD is performed after the clone is complete.

ls-remote

git ls-remote --tags remote_git_url

Tags

  • git tag

git clean

  • -n: –dry-run
  • git clean -x -d -f

git commit

  • Add change to your last commit, instead of making a new commit
    • git commit --amend
Commit messages
  • <type>(<scope>): <subject>
  • type: feat(new feature), fix, docs, style(format code, no code change), refactor, test(add test cases), chore

git remote

  • List all remotes: git remote
  • Add another remote: git remote add upstream the_url
  • git remote show
  • git remote show upstream

git stash

  • -u|–include-untracked
  • List all stashes: git stash list
  • git stash
  • Also stack untracked files: git stash -u
  • Apply the stash: git stash apply <stash@{n}>
  • Apply last stash and remove the stash: git stash pop
  • git stash clear
  • git checkout <stash@{n}> -- <filePath>

git diff

  • Ignore the white space: git diff -w
  • Show local staged change(added but not committed): git diff --cached
  • Show committed but not pushed change: git diff origin/master..master

emoji

Misc

How to Copy Text From Copy-Protected Web Pages


How to Copy Text From Copy-Protected Web Pages

Awesome Tips about Chrome Series


The Problem

Sometimes we want to copy some text/code from a website, but find out that it disables copy text or even completely disables right click, right context menu. It’s annoying, but we can fix it easily.

Using Proxy Sites

Specific Chrome Extensions

We can use the following Specific Chrome extensions to make us able to copy text.

Reader View Chrome Extensions

If we don’t want to install the above specific Chrome extensions, then we can use the more general reader view chrome extension which can also make us able to copy text.

Read here for more must-have google chrome extensions

Reader View

  • This opens the page in chrome-extension:// and we have to wait until (at least) the main content of the page is loaded.
  • The greatest thing is it reduces the memory usage a LOT for pages that load a lot of flashes, ads.
    • e.g. reduces this page from around 450+ mb to 87mb.
  • This also works well together with The Great Suspender: the page in reader view will not be suspended as it runs in extension mode.
  • Assign shortcut Ctrl+Shift+R to Toggle the Reader View
  • Print and save the reader mode version, show or hide image.
  • Able to change the speed of text-to-speech
  • The Cron is it doesn’t work with other extensions, e.g., Chrome Vimium
    • as It opens the page in chrome-extension.
Tips

Just Read

  • Able to change theme(dark or light), width, font size and save the config.
  • Assign Ctrl+Shift+L to Open the Just Read format for the current page
  • Assign Ctrl+Shift+K to Enable user text selection mode using Just Read, then choose which part you want to select then enter (it will automatically try best to choose), it will show the section in read mode.
  • When it doesn’t work(e.g. in quip), use View this selection in Just Read.
  • Works with Chrome Vimium

Clearly

  • Assign shortcut Ctrl+Shift+C to Toggle Clearly
  • Make not easy to copy text easier to copy
  • Support outline, different themes, fullscreen, text-to-voice
  • Cron: Can’t change the width
  • Distill Page from Chrome
  • the result is not that good, and hard to run the command.

Mercury Reader

  • can’t change width

Summary

  • Use Reader View when the page(website) is slow: load lots of ads, flash, uses a lot of memory and you will take time(2+ mins) to read it.
  • Use Just Read in other case.
  • Use Clearly to check the outline.

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)