[Linux/Ubuntu] How to fix graphic issues (nvidia display)

Hi,

Sometimes after usual system update/upgrade your graphic drivers can also get updated. On some occasions you may have few issues after such update including for example:

  • cannot login to the system
  • blank screen / black screen
  • login loop
  • and simialar

In order to fix it you will need to login to separate console, so first thing is:

CTRL + ALT + F2

And then try the following actions:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install gdm 
  • sudo dpkg-reconfigure lightdm // and choose lighttdm
  • sudo apt-get purge nvidia* // remove nvidia
  • sudo apt-get dist-upgrade
  • sudo apt-get install nvidia-current
  • sudo update-alternative --config i386-linux-gnu_gl_conf // or x86_64-linux-gnu_gl_conf 
  • // find out which version you got nvidia-xxx
  • then: sudo apt-get install nvidia-xxx-updates
  • sudo nvidia-xconfig
  • sudo reboot

A bit of command chaos but it did the trick :)

Android: how to enable developer options?

Hi,

If you have connected your mobile phone via USB to your PC in order to test the app you are developing you may end up having problems. Your IDE may not be able to find your device until you enable developer options on the device. And it's not obvious where to find it so follow the steps below:

  1. Go to Settings
  2. Scroll down to the bottom and tap on About phone
  3. Scroll down to the bottom and tap on to Build number 7 times :)
  4. You should get a message after tapping few times about how many times left
  5. Now you can go back to the previous screen and find Developer options at the bottom
In there you can enable debugging via USB and any other setting whatever you need.

Happy coding!

How to: migrate SVN repository to Git and keep history

Hi all,

Today we are going to cover topic about moving from Subversion to Git and ways to copy / migrate SVN data to Git repository (so we can keep the history of commits)

I would recommend doing the migration process using Linux OS as it seems to be much faster than on Windows OS (at least when I was testing it) - this is especially for large repositories.


  • Create "authors" file that relates to SVN repo commit authors. It should be in the following format:
username1 = user_firstname user_lasname <user_email>


username2 = user_firstname user_lasname <user_email>
and so on...



  • Tell Git about it: 
git config --global svn.authorsfile <path_to_authors_file>

  • Init Git repository with SVN reference:
git svn init <svn_repo_url> --stdlayout --prefix=svn/

  • Review/edit .git/config file, it should look like this:
[svn-remote "svn"]
url = <svn_repo_url>
fetch = trunk:refs/remotes/svn/trunk
branches = branches/*:refs/remotes/svn/*
tags = tags/*:refs/remotes/svn/tags/*
[svn]
authorsfile = /path/to/authors.txt

If the SVN repository is large you might want to limit the fetch to only some branches and tags. If so you can do it by specifying them in the .git/config file, for example:
[svn-remote "svn"]
url = <svn_repo_url>
fetch = trunk:refs/remotes/svn/trunk
branches = branches/{feature_branchA,old_branchB,branch_test}:refs/remotes/svn/*
        tags = tags/{tagA,tagB,tagC}:refs/remotes/svn/tags/*


  • Fetch the commits: git svn fetch
Occasionally it may stop due to some random errors or due to unknown commit author. In that case you can add new row/entry in your authors. You can also try to clear memory by running:
git gc OR/AND git svn gc

To resume and continue the fetch run: git svn fetch

  • After a while depending on the repository size it will finish and you can view all available SVN branches by running the command: git branch -a

  • Next step is to create Git branches and tags to the corresponding SVN branches and tags. For each SVN branch run the following command:
git checkout -b <BRANCH_NAME> svn/<BRANCH_NAME>

  • The similar thing for tags, but you might choose to leave tags as branches whatever you prefer:
git checkout -b <tag_TAGNAME> svn/tags/<TAG_NAME> // creates a branch for SVN tag
git checkout master
git tag <TAGNAME> <tag_TAGNAME> // create git tag to that branch
git branch -D <tag_TAGNAME> // delete the previously created branch, tags stays

Repeat for each SVN tag.
  • Switch to the master and create .gitignore file:
git svn show-ignore > .gitignore
// edit .gitignore to manually add whatever you want to ignore
git add .gitignore
git commit -m 'Convert svn:ignore properties to .gitignore.'

Alternatively and/or additionally you can set ignore globally for that repo:
git svn show-ignore >> .git/info/exclude 
  • define remote Git repository so it's added to the .git/config
git remote add origin <GIT_REPO_URL>
  • push everything to the Git repository
git push -u origin -all // push all branches and changes to the repo named origin
git push --tags origin // push the tags as previous command ignores tags

Additions/updates

A) If you want to add some branch or tag later you can do it by telling about it in .git/config:
[svn-remote "branch_MyBranchX"]
url = <SVN_REPO_URL>branches/MyBranchX/

    fetch = :refs/remotes/svn/MyBranchX

Then:

  • Fetch it: git svn fetch
  • Create git branch for it: git svn checkout -b MyBranchX svn/MyBranchX
  • Push it: git push origin MyBranchX

B) If you want to update existing branch from SVN because your team has not switched SVN off yet and you want to sync later changes just fetch the changes:

git svn fetch OR git svn fetch <BRANCH_NAME>

Then switch to related Git branches and rebase:
git checkout <EXISTING_GIT_BRANCH_NAME>
git rebase svn/<BRANCH_NAME> // sync with the recent changes from SVN
git push origin <BRANCH_NAME>

This is it! Happy migrationg :)

Maven - useful tips and tricks

Hello,

Here are some commands and settings which you may find useful when working with Maven.


  • Installing third party JAR artifacts into the local repository

mvn install:install-file -Dfile=<path_to_jar> -DgroupId=<groupid> -DartifactId=<artifactid> -Dversion=<version> -Dpackaging=<packaging>

  • Running build in the offline mode: mvn clean install -o
  • Copy all project dependencies to the folder target/dependencies:
mvn dependency:copy-dependencies

Note: you may actually only be interested in the 'runtime' dependencies:
mvn dependency:copy-dependencies -DincludeScope=runtime

  • Delete / purge the existing dependencies and download again:
mvn dependency:purge-local-repository

  • Check for newer versions of project dependencies and plugins:

mvn versions:display-dependency-updates
mvn versions:display-plugin-updates

  • Skipping unit test from the build: mvn clean install -DskipTests=true

Note: you can make it permanent in the POM file configuration:
<properties>
  <skip.tests>true</skip.tests>
</properties>

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
          <skipTests>${skip.tests}</skipTests>
        </configuration>
      </plugin>
    </plugins>

</build>


For more info and guides please visit the official webiste: https://maven.apache.org/



Gerrit with MySQL installation guide

Hello,

Gerrit is a great tool for pre-commit code review. Installation on Linux based OS is kind of default and it's nice and simple. However when you try to do it on Windows you may end up having some sort of issues. So this has been tested on Windows OS but you can also try it on Linux based OS.

1. Download and install MySQL: http://dev.mysql.com/downloads/

2. Download and install MySQL Workbench - useful tool for accessing the databases: http://dev.mysql.com/downloads/workbench/

3. Create Gerrit review database and user for it:

CREATE DATABASE gerritdb;
ALTER DATABASE gerritdb charset=latin1;

CREATE USER 'gerrit'@'localhost' IDENTIFIED BY 'gerrit';
GRANT ALL ON gerritdb.* TO 'gerrit'@'localhost';
FLUSH PRIVILEGES;

CREATE USER 'gerrit'@'<hostname>' IDENTIFIED BY 'gerrit';
GRANT ALL ON gerritdb.* TO 'gerrit'@'<hostname>';
FLUSH PRIVILEGES;


5. Create a folder to host gerrit and place the WAR in it.

6. Installation:

gerrit/$ java -jar gerrit.war init

It will ask for various different settings. For some of them default option seems OK. See below some of the setting you may want to specify other than defaults:

canonicalWebUrl = http://gerrit:8080/

[database]
    type = mysql
    hostname = localhost // OR network hostname
    database = gerritdb
    username = gerrit (password prompt = gerrit)

Run as user: gerrit

NOTE: if you use LDAP and/or you have a mail server it's better to set it up directly during installation rather than later. Note all passwords provided will not be visible in the /gerrit/etc/gerrit.config file which is good.

Example of LDAP settings:
[ldap]
    server = ldap://ldapSrvName.aaa.bbb
    username = CN=John Smith, OU=Country,OU=Users,DC=aaa,DC=bbb
    accountBase = DC=aaa,DC=bbb
    groupBase = DC=aaa,DC=bbb

Example of e-mail server settings:
[sendemail]
    enable = true
    from = SERVER
    threadPoolSize = 1
    smtpServer = emailSrvName.aaa.bbb
    smtpServerPort = 25
    smtpEncryption = tls
    sslVerify = false

7. Go to /gerrit/etc and generate ssh keys with the specified names:
gerrit/etc/$ ssh-keygen
name: ssh_host_key

chmod 600 ssh_host_key && chmod 600 ssh_host_key.pub

8. On Windows there may be an error regarding virtual memory command, so if you are installing this on Win OS edit /gerrit/bin/gerrit.sh:
- comment out virtual memory command (on or near line #303)
- add line at the beginning GERRIT_SITE=<path_to_gerrit_folder>
e.g. GERRIT_SITE=/c/gerrit

9. It's likely that gerrit has failed to create some of the tables (if not then you can skip this step). Create the missing tables manually in the MySQL database:
create table account_group_by_id_aud (
  added_by INT DEFAULT 0 NOT NULL,
  removed_by INT,
  removed_on TIMESTAMP NULL DEFAULT NULL,
  group_id INT DEFAULT 0 NOT NULL
  include_uuid VARCHAR(255) BINARY DEFAULT '' NOT NULL
  added_on TIMESTAMP NOT_NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY(group_id,include_uuid,added_on)
);

create table account_group_members_audit (
  added_by INT DEFAULT 0 NOT NULL,
  removed_by INT,
  removed_on TIMESTAMP NULL DEFAULT NULL,
  account_id INT DEFAULT 0 NOT NULL
  group_id INT DEFAULT 0 NOT NULL
  added_on TIMESTAMP NOT_NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY(account_id,group_id,added_on)
);

create tables changes (
  change_key VARCHAR(60) BINARY DEFAULT '' NOT NULL,
  created_on TIMESTAMP NOT NULL,
  last_updated_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  owner_account_id INT DEFAULT 0 NOT NULL,
  dest_project_name VARCHAR(255) BINARY DEFAULT '' NOT NULL,
  dest_branch_name VARCHAR(255) BINARY DEFAULT '' NOT NULL,
  status CHAR(1) DEFAULT ' ' NOT NULL,
  current_patch_set_id INT DEFAULT 0 NOT NULL,
  subject VARCHAR(255) BINARY DEFAULT '' NOT NULL,
  topic VARCHAR(255) BINARY,
  original_subject VARCHAR(255) BINARY,
  row_version INT DEFAULT 0 NOT NULL,
  change_id INT DEFAULT 0 NOT NULL,
  PRIMARY KEY(change_id)
);

10. Run again gerrit WAR to check if there are no table errors this time:
gerrit/$ java -jar gerrit.war init --batch -d <installation_folder>

11. Run reindex task:
gerrit/$ java -jar gerrit.war reindex

12. Make sure the changes done for /gerrit/bin/gerrit.sh are still there. If not apply step 8 again.

13. There may be an error when querying users accounts, so to prevent run the following updates on the database:
SET collation_connection = 'utf8_general_ci'
ALTER DATABASE gerritdb CHARACTER SET utf8 COLLATE utf8_general_ci
ALTER TABLE accounts CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
ALTER TABLE account_external_ids CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci


14. Start gerrit.sh script

If failed to start no worries, check it if it's actually running because the message may just be misleading. If really failed then possible errors / fixes:
- port blocked - kill all java processes and try again
- reindex gerrit (see the step 11)

If nothing else helps you can try to drop the database and recreate it again.


Hope that helps. Cheers!

If you have other issues or questions check out official documentation and tutorials: https://www.gerritcodereview.com/


Welcome to GIT - revisited

Hello,

Git is getting more popular and it's really good. So here is a quick introduction how to get started with it.

First step is to install the tool - you can download it from the official website:
https://git-scm.com/downloads

There are versions for many different OS such as Linux, Windows, Mac OS X and Solaris.

After installing it you should be able to open GIT bash where the fun begins :)

Set your user details such as name and e-mail - this will appear in the commits.
git config --global user.name <your_username>
git config --global user.email <your_email>


It's good to have nice merge tool. There are some supporting 3-way diffs and some usual 2-way diffs. Two of them are worth recommending at this point:


Once you choose your favourite you can set it up for Git using the following command:
git config --global diff.tool <your_diff_tool>

If you want to display the list of config settings use the command:
git config --list

Before you can start working with Git you should also set up your SSH keys. Follow our guide for setting them up:


Most common way of using Git is using the command line via Git Bash tool - and most of the users are OK with it. However there are some users who prefer graphic user interface - so good news is there are GUI tools for Git. Some of them are integrated in the development IDE such as for example Eclipse or NetBeans.
You can also install the dedicated tool such as for example:



That's it basically. Cheers!


How to run bash script on Windows at system startup

Hello,

This topic may be a bit confusing but here is the story.
Let say we have a SH script startApp.sh and we would like to run it on Windows because there is no equivalent BAT script available. In general if you want to run bash script you need some sort of bash command line interpreter. For example you can install Git bash:

Then it's simply - open Git bash and cd to the target script directory and run it manually by invoking the command:
sh startApp.sh
OR
./startApp.sh

Now if you would like to run it without touching the command line you can create a windows shortcut to run the bash script. In the shortcut command you also need to provide a bash program that will execute the script - in this case it will be Git bash. So the shortcut underlying command will be something like this:
"C:\Program Files\Git\bin\sh.exe" C:\tool\bin\startApp.sh

Or if the SH script takes parameter it could look like this:
"C:\Program Files\Git\bin\sh.exe" C:\tool\bin\startApp.sh start

That's pretty cool :) Now if you would like to have it run at windows startup you place this shortcut in the menu start startup folder. On Windows 7 for example it's in the following location:
C:\Users\user.name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Just copy your shortcut there and you are done.

Hope that will help in some cases.

ProGuard - decoding obfuscated stack traces

Hello,

If you develop and publish mobile apps you will most likely see some crash reports with some kind of stack trace attached. If you used ProGuard to obfuscate the code it may be difficult to read such error message / stack trace.
Luckily for us it can be easily decoded using the same tool.

Following command does the trick:
retrace.sh [-verbose] mapping.txt <stacktrace_file>

Retrace tool is available in your proguard/bin path which usually is <sdk_root>/tools/proguard/bin directory

Important thing is to use the same mapping.txt file that has been used to obfuscate the code (this can be find in you <app_project_root>\proguard )


Reference: http://developer.android.com/tools/help/proguard.html#decoding

How to implement "share" functionality for Android app

Hi,

Today basics of implementing the share action which should let share content via e-mail, SMS message, etc. The common way would most likely be to use the action bar and it's menu icons.
So first step is to add 'share' menu item:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity" >


<item
    android:id="@+id/menu_item_share"
    android:title="@string/share_action"
    app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
    app:showAsAction="always"/>


We use ShareActionProvider widget from support library to account for older devices.

Next step is to override onCreateOptionsMenu method in your MainActivity:

ShareActionProvider mShareActionProvider;
Intent mShareIntent;
 
public boolean onCreateOptionsMenu(Menu menu) {
    // this is common just inflate the menu
    getMenuInflater().inflate(R.menu.main, menu);

    MenuItem shareItem = menu.findItem(R.id.menu_item_share);

    mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
    if (mShareActionProvider != null) {
        if (mShareIntent == null) {
            mShareIntent = new Intent();
            mShareIntent.setAction(Intent.ACTION_SEND);
            mShareIntent.setType("text/plain");

    // here you can put data that you would like to share
            mShareIntent.putExtra(Intent.EXTRA_TEXT, "SOME_SHARE_DATA");
        }
        mShareActionProvider.setShareIntent(mShareIntent);
    }

    return true;

}

And that's basically it. Usually you don't need to do anything special in the implementation of onOptionsItemSelected.

Important
You may notice that it works in the debug mode / locally but when you deploy to live it does not. That may happen if you use ProGuard. Following line should be added to the proguard configuration in order to make it work:
# to keep shareactionprovider working
-keep class android.support.v7.widget.ShareActionProvider { *; }



Cheers!

Create bootable Win 7 USB pendrive on Ubuntu

Hiya!

If anyone is looking for how to install Windows 7 from USB drive here it is. This guide is for people who run Linux.

One of the most popular and common tool for creating bootable pendrive is called unetbootin and will be using it for completing this task.

First of all you need to format your USB device to ntfs. You can do it using gparted tool (be careful to choose correct drive ;)

You may also need to install support for NTFS:
sudo apt-get install ntfs-3g

If you want your device to be bootable you can set such flag in gparted itself.

Here is the version of unetbootin that happens to support the NTFS:
http://sourceforge.net/projects/unetbootin/files/UNetbootin/494/unetbootin-linux-494/download


After you run unetbootin follow on screen instruction, i.e. select image from ISO,
and select the correct drive - you may need to tick the checkbox called: "Show all drives". Make sure you know what drive is your USB to avoid destroying data on your real drive - follow at your own risk of course.

That's it.

ssh-add problems with SSH agent and related

Hi,

Some time ago we have posted about resolving git errors related to permissions denied for the ssh keys: http://devmain.blogspot.co.uk/2014/09/git-error-permission-denied-publickey.html

The solution was to try running the following command:
ssh-add

However what if running it results in the following error:
"Could not open a connection to your authentication agent"

Well there is a solution to that one too :)

It may mean that the SSH agent is not running and you can try to start it prior to running the command. If you run GIT bash on Windows you can try the following command:
eval `ssh-agent -s`

or if that's not the case you can try directly start ssh-agent

After that just try again with ssh-add.

Hope that helps someone.

Cheers!

Java Mail API for Android and proguard errors

Hi,

If you would like to send e-mails directly from within your mobile app you can use Java Mail API.  Here is the special lightweight port for Android:
https://code.google.com/p/javamail-android/

You will need to include all 3 jar files in your libs folder:
  • additional.jar
  • mail.jar
  • activation.jar
Then you can use common way to implement sending e-mails. Both should work: TLS and SSL.

Everything seems to be working fine until you are ready to publish your app. If you are going to export signed APK and use ProGuard to obfuscator you may notice errors and warning for proguard saying about missing classes, references or jars.

In order to fix just add the following rules to your proguard config file:
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**

-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}

-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}



This may or may not work for you but it did the trick for me :)

How to: backup and restore MySQL data

Dumping/backup table for the MySQL database
mysqldump -u <dbuser> -h <dbhost> -p <dbname> tablename > tablename.sql

Restoring data
mysql -u <dbuser> -h <dbhost> -p <dbname>
mysql> source <path>/tablename.sql

OR
mysql -u <dbuser> -h <dbhost> -p db_name < /path/to/tablename.sql