Tuesday, December 18, 2018

How to quickly checkout github pull request

Two ways:

1.
$ git fetch origin pull/117/head:local-branch-name
$ git checkout local-branch-name

Or you can put in  ~/.profile following function:

checkoutPull() {
  #Usage: checkoutPull pr-number pr-branch
  #   or  checkoutPull pr-number user:pr-branch
  BRACH=$(echo $2 | sed -e "s/^.*://")
  if git branch | grep $BRACH; then
    echo "Branch $BRACH already exists and should be removed"
    read -p "Are you sure (y/n)? " -n 1 -r
    echo    # (optional) move to a new line
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
      git branch -D $BRACH
    fi
  fi
  echo "git fetch upstream pull/$1/head:$BRACH"
  git fetch upstream pull/$1/head:$BRACH
  echo "git checkout $BRACH"
  git checkout $BRACH
}

And use it as:
$ checkoutPull 3058 my-coworker-username:issue-51502

2.
One more approach is or create function that consume easy to copy value from Github page. All PRs pages show this value as text "my-coworker-fork:his-branch".
Add to ~/.profile
checkoutForked() {
  #usage: checkoutForked another-fork:branch-in-fork
  FORK=$(echo $1 | cut -d ':' -f 1)
  BRANCH=$(echo $1 | cut -d ':' -f 2)
  REPO=$(grep -A 1 "\"origin\"" .git/config | grep github | sed -E "s/.*\///");
  if git remote | grep $FORK; then
    echo "Fork already exists"
  else
    echo "git remote add $FORK git@github.com:$FORK/$REPO;"
    git remote add $FORK git@github.com:$FORK/$REPO;
  fi
  echo "git fetch $FORK"
  git fetch $FORK
  if git branch | grep $FORK/$BRANCH; then
    echo "Branch $FORK/$BRANCH already exists"
  else
    echo "git checkout $FORK/$BRANCH"
    git checkout $FORK/$BRANCH
    echo "git checkout -b $FORK/$BRANCH"
    git checkout -b $FORK/$BRANCH
  fi
}
execute:
$ checkoutForked my-coworker-fork:his-branch

NOTE:
to push to forked repo remote you will need bind your branch and his branch:
git push my-coworker-fork my-coworker-fork/his-branch:his-branch -f

Tuesday, May 1, 2018

How to find and install missed man page or section in linux


Two options:
1) web
2) in server repositories

1) In web - just google it
https://www.google.com/search?q=man+7+signal
Will result in smth like http://man7.org/linux/man-pages/man7/signal.7.html

2) In server
$ man kill
# no signals details , most likely in "SEE ALSO .... signals(7)"
$ man 7 signal
No manual entry for signal in section 7
$ yum provides */signal.7.gz
...
#man-pages-3.53-5.el7.noarch : Man (manual) pages from the Linux Documentation Project
#Repo : rhel-7-server-rpms-master
#Matched from:
#Filename : /usr/share/man/man7/signal.7.gz
..
$ sudo yum install man-pages
$ man 7 signal

Tuesday, January 10, 2017

How to get name of laptop from windows command line


In Windows CMD:
wmic csproduct get vendor,name,identifyingnumber

Result is smth like:
IdentifyingNumber  Name            Vendor
JG1Z111            Latitude E6420  Dell Inc.

Tuesday, January 3, 2017

Process maven's pom xml file with xmlstarlet

General command  to get version of certain plugin dependency from pom file:

xmlstarlet sel -N pom=http://maven.apache.org/POM/4.0.0 -t -m "/pom:project/pom:build/pom:pluginManagement/pom:plugins/pom:plugin[pom:artifactId='maven-checkstyle-plugin']/pom:dependencies/pom:dependency[pom:artifactId='checkstyle']/pom:version" -v . pom.xml

Examples for editing and selection are at:
https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/pom-version-bump.sh

https://github.com/checkstyle/checkstyle/wiki/How-to-generate-Checkstyle-report-for-Google-Guava-project

Few XPATH conditions for query:
http://stackoverflow.com/questions/28370054/find-a-specific-groupid-from-a-maven-pom-xml-using-xmstarlet


Useful command to print all tags from xml file to help construct XPATH:
xmlstarlet el -v pom.xml


Wednesday, September 28, 2016

Comments on "To what extent can maintenance problems be predicted by code smell detection? – An empirical study"

Article: To what extent can maintenance problems be predicted by code smell detection? – An empirical study

I highly recommend to all to read this article, it is big but have valuable details of great experiment. I doubt that smb could conduct smth similar as it is very costly.

Some valuable quotes from article:

Results: From the total set of problems, roughly 30% percent were related to files containing code smells. ......
Conclusions: The role of code smells on the overall system maintainability is relatively minor, thus complementary approaches are needed to achieve more comprehensive assessments of maintainability.
Moreover, to improve the explanatory power of code smells, interaction effects amongst collocated smells and coupled smells should be taken into account during analysis.

Is 30% of problems are minor ? 30% of problem that can be predicted on the moment of writing code in automatic mode without wasting time of other engineers. I doubt that it is minor.

Lets take a look deeply to report:

Twelve different code smells were detected in the systems via Borland Together and InCode.

Ancient systems , non of them is alive now !
Where is opensource stack of tools like: Checkstyle, PMD, FindBugs, SonarQube, IntelijIdea inspections, nondex, forbiddenapis, error-prone, ..... ?

We report on a multiple case study in which the problems and challenges faced by six developers working on four different Java systems were registered on a daily basis, for a period up to four weeks.
.....
there is a substantial body of work that investigates if certain source code characteristics (i.e., a code smell) affect a given maintenance outcome (e.g., effort, changes, defects).

Selected model is pretty impressive and based on real code.

Individual progress meetings (20–30 min): were conducted daily, with each of the developers and the researcher present at the study to keep track of the progress, and register problems encountered during the project (ex. Dev: ‘‘It took me 3 h to understand this method. . .’’)

3h is too much for a method , if that is more than 20 min or even 5 min - it is problem and code smell.

Code smells automatically detected in the systems:
Data Class
Data Clumps
Duplicated code in conditional
branches
Feature Envy
God (Large) Class
God (Long) Method
Misplaced Class
Refused Bequest
Shotgun Surgery
Temporary variable for various
purposes
Use interface instead of
implementation
Interface Segregation Principle
(ISP) Violation

it is strange why that minimal amount of code smells are detected only , look like list whole smells were not that big. Not clear why minor smells are ignored in investigation. In you have 5K minor problems in project , you have a lot of problems, and you will pay for that on daily basis. Minor problems stumble engineer for 2min, 5min .... but that time is valuable too! At the end of the day it could come up to 30min or even an hour.
Minors can not be ignored, as they can make engineer to tire and slightly demotivate and in general performance will be slightly lower.

In total, 137 different problems were identified from the differ-
ent maintenance projects. From the total, 64 problems (47%) were
associated to Java source code. The remaining 73 (53%) constituted
problems not directly related to code such as: lack of adequate
technical infrastructure, developer’s coding habits, external ser-
vices, runtime environment, and defects initially present in the
system.

almost 50% of problems could be find automatically . And by the way, "developer’s coding habits" is also code smell.

From the total set of difficulties identified during maintenance,
less than half (43%) were related to Java code, and from those, only
58% clearly related to any of the twelve code smells used to analyze
the code. This means that even if we count those difficulties that
are due to combination of factors, roughly only 30% of the total
set of difficulties can be explained and potentially foreseen by code
smells. As a result, we conclude that the subset of aspects that are
covered by current code smell detection has a relatively low
...
The results from our study reminds us of the limitations of evaluations based purely on static analysis and suggest the need of more comprehensive quality models and techniques that can incorporate the analysis of diverse factors.

Even in average it is 30% for purely static analysis ..... is it low ? Just offer your manager 30% bust in productivity in development that could be archive by using free tools in CI or IDE integrations!
I doubt I would say "Do not bother about this."

Thursday, April 28, 2016

How to do ssh-copy-id on SunOS

There is no ssh-copy-id command on SunOS(Solaris, SmartOS).

How to do ssh-copy-id on/from SunOS(Solaris, SmartOS) to another server:
cat ~/.ssh/id_rsa.pub | ssh user@server "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"

Friday, April 15, 2016

How to print whole command from ps in SunOs Solaris SmartOS

[sb@c-apps01 ~]$ uname -a
SunOS c-apps01 5.11 joyent_20160121T174331Z i86pc i386 i86pc Solaris

[sb@c-apps01 ~]$ ps -aef | grep mail
      sb 52561  5477   0 18:47:58 pts/38      0:00 grep mail
      sb 38414 38411   0 18:30:41 ?           0:03 /opt/java8/bin/java -mx256m -classpath :/www/mail-notifier/lib/act
      sb 38411 38408   0 18:30:40 ?           0:00 bash /www/notifier/sh/_shell.sh --processor com.revere.auth.j
      sb 43546 48142   0 14:38:12 ?           0:00 /www/bin/wd -p /www/sb/jobs/notifier/w.pid -- /www/sb
      sb 38408 43546   0 18:30:40 ?           0:00 bash /www/notifier/sh/listener.sh


As might notice all commds are cut to 80 symbols.


Answer is (undocumented "w" option): 
ps axwwl



Side note:
how to list all open ports on SunOs: "lsof -P"