Tuesday, May 2, 2017

Mercurial commands

Create a branch
hg bookmark [name]
Reset local changes
hg revert --all
Fetch latest code
hg pull
Fetch latest code and update local code
hg update master
Commit
hg commit [-m "message"]
Update commit with new changes
hg amend [!! use of -m "message" overwrites the log]
Status
hg diff
hg status
Current bookmark (branch)
hg identify
Switch bookmark and rebase
hg update [name]
Difference from the rev
hg diff -r [rev_num]
Use file from a revision
hg revert -r [rev_num] [file]
Use theirs or yours version on rebase
hg resolve -t internal:other --all
hg resolve -t internal:local --all
Use manual resolve on rebase

hg resolve -m [file]



Friday, September 16, 2016

Integer overflow

Integer overflow in JVM can lead to negative, zero and positive values, i.e. can everything:
scala> val x = 1 + (Int.MaxValue - 1) / 2
x: Int = 1073741824
scala> x * x
res16: Int = 0
scala> val x = 1 + (Int.MaxValue - 5) / 2
x: Int = 1073741822
scala> x * x
res18: Int = 4
scala> val x = 1 + (Int.MaxValue - 6) / 2
x: Int = 1073741821
scala> x * x
res19: Int = -2147483639
The check for overflow due to multiplication divide back and check if get the same result. Summation overflow can be checked by the sign of result. The other option is to use double and long. 

Thursday, August 4, 2016

Check scalastyle

Maven - checks only main sources:
mvn scalastyle:check
Sbt check main:
sbt scalastyle
Sbt check test:
sbt test:scalastyle

Friday, June 24, 2016

Java and Hadoop URI differences

Hadoop Path.toUri adds only / to the beginning of local path but does not add file:. Java File toURI adds file:/ to the beginning and / to the end of any path. In particular, JavaFile.toURI.getPath equals to Hadoop Path.toUri.toString

Saturday, June 11, 2016

Most frequently used git commands


init local repo and push it to the remote repo (it has to be already created on github)
git init
git add .
git reset [file to exclude]
git commit -am "First commit"
git remote add origin [github address]
git push origin master
add remote repo, give it a name [name] and fetch it locally
git remote add [name] [github address]
git fetch [name]
create a new branch based on some branch
git checkout -b [new_branch] [some_branch]
create a new branch on top of uncommited changes
git checkout -b [new_branch]
edit/merge history of N last commits (replace pick with squash to merge commit)
git rebase -i HEAD~N
get file from the other branch
git checkout [branch] -- [file]
rebase on top of some branch
git rebase [branch]
  if merge conflict - resolve by hand then
  git add [resolved file]
  git rebase --continue
  if merge conflict - use either ours or theirs file
  git checkout --ours|--theirs [file]
  git add [resolved file]
  git rebase --continue
cherry-pick a commit
git cherry-pick [commit 6-number hash]
patch
   add '.patch' to the pull request URL and press 'Enter' in the browser
   curl -L [url] > /tmp/my.patch
   git apply (--check) /tmp/my.patch
git cherry-pick [commit 6-number hash]
delete a branch
git -d [branch]
revert local changes to the last commit
git reset --hard HEAD
git push from some local branch to some remote
git push <REMOTENAME> <LOCALBRANCHNAME>:<REMOTEBRANCHNAME>
Pull/fetch/merge/rebase reference
https://www.derekgourlay.com/blog/git-when-to-merge-vs-when-to-rebase/