Year: 2015

3 questions about your Git repository

2015-12-28 Git, Linux, Open source, Python 3 comments

Introduction

Can you answer the following questions about your Git repository?

  1. Does development branch has all changes from master branch?
  2. Is your gitlog a crap?
  3. How old are your branches?

If not, but you want to know answers, you’re lucky, because I prepared 3 simple scripts for you, which can help to find it out.

Does development branch has all changes from master branch?

git-branch-comparator is a python script, which checks if development branch has all changes from master branch in Git repository.

Another, easier way to accomplish the same task suggested in comments by Mike (thanks!) is to call simply:

$ git pull
$ git branch --contains master --no-merged development

When we are working in a Git Flow and critical bug occurs on production, sometimes there is a necessity to create so called hot-fix. We can create separate branch from master branch for this hot-fix and then merge it into master branch or we can commit a change on master branch. Second option is not recommended. After that, we have to remember to merge master branch into a development branch to have our hot-fix in a development version as well and avoid merge conflicts in the future.

This python script checks, if all changes made on master branch were also merged into development branch to keep those two branches consistent. We can add it as a job into Jenkins CI server and monitor branches consistency. In addition, release jobs can depend on that job and we can avoid merge conflicts or project unstability before release.

source code & documentation: https://github.com/pwittchen/git-branch-comparator

Is your gitlog a crap?

craplog is a python script, which checks if git git log of the given project is crappy or not. Right now, script is very simple. It just checks if more than half of the commit messages are good. Commit message is considered as good, when it contains more than two words. Of course, this is not the only condition determining the quality of the commit message, but this is early beta version of the script and can be improved later.

I’ve read a discussion in one of the pull requests to Linux kernel. It made me think about quality of Git commit messages. Of course, Linux kernel is a specific project and has its own standards. Maybe not all of these standards will be valid for a simpler or less complicated projects. Nevertheless, a lot of people don’t pay attention to git commit messages. They put crappy stuff inside them like random letters and numbers or stupid expressions, which has no specific meaning, aren’t related to the project or aren’t informative enough. In my opinion, good git log is one of the factors determining good quality of the project. Sometimes, we need to browse log to find some changes or analyze project history in order to fix a bug or find important information. It’s easier to do it, when git log is good. I’ve made some of the mentioned mistakes in the past, but I try to avoid them now.

source code & documentation: https://github.com/pwittchen/craplog

How old are your branches?

git-aged-branches is a shell script showing git branches of defined repository with age of their last commit. It works on Mac OS X, Linux and can be helpful while investigating old Git branches to delete. This script does not delete anything! It’s just for informational purposes.

source code & documentation: https://github.com/pwittchen/git-aged-branches

Summary

I hope, some of you will find these tools useful and maybe they’ll solve your current problems or help to improve quality of your projects.
If you would like to know more details about mentioned projects, check instructions how to use them and their source code, visit linked repositories on GitHub.

Note: Any feedback, new issues or pull requests are appreciated!

Reactive Live Coding during GDG DevFest 2015 in Poland

2015-11-29 Android, Conferences, Google, Java, RxJava 2 comments

I was asked to be a speaker during GDG DevFest 2015 conference in Warsaw, Poland. Of course, I accepted this invitation and prepared presentation titled “Reactive Live Coding”. Presentation covered basics of Reactive Programming, RxJava and RxAndroid. Besides my talk I’ve done live coding to show how to use mentioned libraries and basics principles of Reactive Programming in real life. I had only 20 minutes for all of that, so my time-box was very limited. Being a speaker at conference was really interesting and challenging experience, which I haven’t had before. Moreover, I could meet a lot of interesting people and hear very inspiring talks covering different topics. You can check activity from conference by browsing #devfest15pl hashtag on Twitter and Facebook event. You can also check official website of the conference at devfest.pl.

Slides from my presentation are available below.

Source code of the exemplary Android app shown and partially coded during the presentation is available at github.com/pwittchen/guitar-browser.

Picture documenting part of my short talk made by @depodefi can be found below.

CU59bM6W4AABP68

GDG DevFest organizers have done really good job and I can definitely recommend this conference to anyone interested in new IT technologies.

New release of Kirai – elegant string formatting library for Java

2015-11-22 Android, Java, Open source No comments

I’ve recently released version 1.4.0 of Kirai library. Kirai means phrase in Swahili language. It’s string formatting library written in Java. It originally started as an Android library, but it evolved to pure Java library. It’s first possibilities were basic string formatting and text formatting for Android TextViews. Now, it allows to format strings for Java, Web, Android and even Unix Terminal! Have you ever wanted to have colorful and styled text in your mobile app, website or terminal app? Now you can with an elegant and fluent API! Moreover, I’ve added test coverage supported by codecov.io. It’s really nice service, which integrates with Travis CI and is free for open-source projects. It’s available for various programming languages and build systems.

Check library source code and samples at: https://github.com/pwittchen/kirai

You can add it to your project via Maven:

<dependency>
    <groupId>com.github.pwittchen.kirai</groupId>
    <artifactId>library</artifactId>
    <version>1.4.0</version>
</dependency>

or through Gradle:

dependencies {
  compile 'com.github.pwittchen.kirai:library:1.4.0'
}

Bunch of updates in my OSS for Android

2015-11-08 Android, Java, Kotlin, Open source No comments

Introduction

In the last days I prepared a bunch of updates in my open-source software for Android. Most of them are bug fixes and are related to increasing robustness of the projects as well as their overall quality. I also decided to play a little with Kotlin language from JetBrains, which seems to be reasonable choice for mobile applications running on Android. Nevertheless, writing an app in Kotlin requires some additional configuration and we should remember, it’s still in beta version. If you are interested in Kotlin programming for Android, take a look at Getting started with Android and Kotlin guide from official Kotlin website. You can also take a look at one of my sample apps written in Kotlin and its configuration in Gradle.

Summary of updates

ReactiveNetwork v. 0.1.3

  • fixed bug with incorrect status after going back from background inside the sample app reported in issue #31
  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • added static code analysis
  • updated code formatting
  • added sample sample app in Kotlin

Unfortunately, in Android we cannot use Java 8 yet and code should be written in Java 7. We can do some hacks like using RetroLambda or libraries implementing part of functionalities available in Java 8 like streams, but these solutions are still hacks – not the right way. In Kotlin we can use lambdas like in Java 8. In addition, we have a lot of other cool features, which allow us to write less lines of code and detect possible mistakes while writing apps. E.g. Kotlin helps us to avoid NPEs with its additional operators like !!, which tells us that NPE can occur, so we can think of eliminating this possibility. If we don’t use this operator when we should, IntelliJ IDEA or Android Studio will warn us. Below, we can see exemplary usage of ReactiveNetwork library with Kotlin. In this code snippet, we are using so called synthetic properties from Kotlin Extensions for Android. Value connectivity_status is an id of the view defined in XML layout. We can call it directly in Kotlin code and treat as object. It’s really useful and allows us to avoid calling findViewById(...) method for every view in Activity or injecting views with additional libraries like ButterKnife or KotterKnife. It means that we can get rid of a lot of boilerplate code.

ReactiveSensors

  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • added static code analysis
  • refactored sample app and removed repetitions in code

In this project I made only changes inside the documentation, improved Gradle configuration and added another sample app. There were no changes inside the library code, so there was no need to release new library version to Maven Central Repository. Moreover, I’m going to add sample app in Kotlin for this project in the nearest future.

ReactiveBeacons v. 0.3.0

  • replaced distinct() operator with distinctUntilChanged() operator in Observable observe() method in ReactiveBeacons class
  • added permissions ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION to satisfy requirements of Android 6
  • renamed void requestBluetoothAccessIfDisabled(activity) method to void requestBluetoothAccess(activity)
  • added boolean isBluetoothEnabled() method
  • added boolean isLocationEnabled(context) method
  • added void requestLocationAccess(activity) method
  • modified sample app in order to make it work on Android 6 Marshmallow
  • reduced target API from 23 to 22 in library due to problems with additional permissions and new permission model (it can be subject of improvements in the next releases)
  • added package private AccessRequester class
  • added sample app in Kotlin

WeatherIconView v. 1.1.0

  • added icons from 2.0 version of the original weather-icons project
  • updated compile sdk version
  • updated Gradle Build Tools version

Prefser v. 2.0.2

  • fixed bug reported in issue #70: get(...) method now returns a null value instead of “null” string when setting default value to null of String type
  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • changed code formatting to SquareAndroid
  • added static code analysis
  • improved code according to static code analysis suggestions

Kirai v. 1.1.0

  • removed formatter(...) method from Kirai class
  • added format(...) method accepting implementation of Formatter interface to Kirai class
  • added Syntax interface and HtmlSyntax class implementing this interface
  • added put(String key, Object value, Syntax syntax) method to Piece class
  • set HtmlSyntax as default Syntax implementation in Piece class
  • removed dependencies to Android SDK
  • updated project dependencies
  • applied Square code style
  • updated tests, sample app and code snippets in README.md
  • added gh-pages with JavaDoc

Any suggestions of further improvements are more than welcome as usual!

An Opinionated Guide to Modern Java by Parallel Universe

2015-11-05 Java No comments

Introduction

I recently read series of three articles titled An Opinionated Guide to Modern Java by Parallel Universe. It presents really interesting point of view and can be read even by non-Java developers due to its form. Non-Java developers can learn that Java can be fast, elegant and lightweight as much as other hipster technologies like Ruby, Go or Node.js. The main difference is the fact that Java is quite old and widely used technology what means it’s well tested, stable, solid, has great development and monitoring tools. Besides widely known projects, author of the articles presents some information about tools built by Parallel Universe, which are not commonly used and are less popular, but are also worth considering for modern development. E.g. he writes about so called Capsule project, which is intended to be a Docker alternative for Java and Quasar, which is interesting high level API for multi-threading with concept of actors, which is also available in Akka and Erlang. I recommend any Java and non-Java developer to read this series to learn new things and consolidate the knowledge.

Series of articles

Introducing ReactiveBeacons

2015-09-30 Android, Context awareness, Java, Open source No comments

Recently, I’ve created yet another reactive library for Android. It’s called ReactiveBeacons and it’s responsible for observing BLE (Bluetooth Low Energy) beacons. Beacons are small devices, which became quite popular in the last years. They can be utilized in creating Contextual Awareness, Contextual Computing and Internet of Things. Beacons have lithium battery, are constantly turned on and emit signals via Bluetooth all the time. ReactiveBeacons library allows to transform these signals into Observable stream compatible with RxJava. Whenever new beacon is detected or RSSI (Received signal strength indication) changes, new immutable beacon data is emitted.

Usage of the library inside the Activity is simple:

We also have to remember to unregister subscription correctly in order to stop BLE scan, which can drain the battery.

If you want to use this library in your project, add the following dependency to your build.gradle file.

dependencies {
  compile 'com.github.pwittchen:reactivebeacons:0.0.1'
}

Don’t forget to add dependency to RxAndroid if you want to use Android-specific features of RxJava.

Source code of the library can be found at: https://github.com/pwittchen/ReactiveBeacons.

Any new issues or pull requests are welcome!
Happy coding!

Using tmux

2015-09-20 Linux No comments

What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more.

– tmux.github.io

ss-tmux1

Tmux feature, which I find very useful is tiling terminal window. We can have several tiles with different terminals within a single terminal window.

How to use tiling?

First, we need to install tmux:

$ sudo apt-get install tmux

Then, we need to start it:

$ tmux

When we are inside tmux, we can execute its commands. It’s good to check full list of tmux key bindings.

Default initial key binding for different commands is Ctrl+B. When we hold Ctrl and then press B, we can press next key for specific command. It’s tricky and it isn’t intuitive at the first time.

For example, if we want to split terminal window vertically, we need to do the following thing:

Start tmux, Hold Ctrl, press B (while holding Ctrl), release buttons and press % key (equivalent to Shift+5).

If we want to split terminal window horizontally, we need to do the following thing:

Start tmux, Hold Ctrl, press B (while holding Ctrl), release buttons and press " key (equivalent to Shift+' – code for ' sign is 47 for xdotool).

We can create any tile configuration we want like in i3 windows manager.

tmux-tiles

If we want to switch between tiles, we need to use the following key combination:

Hold Ctrl, press B (while holding Ctrl), release buttons and press O key (“O” letter – not zero).

Creating 4 tiles automatically

Popular terminal windows configuration is 4 tiles (2 columns and 2 rows). We can split windows horizontally or vertically pretty fast with default shortcuts, but creating layout consisting of 4 tiles requires some clicking. I’ve written a simple script, which generates such layout for us automatically and saves the time.

First, we need to install xdotool:

$ sudo apt-get install xdotool

Next, we can create file named tmux-4tiles, set its chmod to 777 and save it in /usr/local/bin/ directory.

File should have the following content:

#!/bin/bash
# generates 4 tiles in tmux (requires tmux and xdotool)
xdotool key ctrl+b shift+5 && xdotool key ctrl+b shift+48 && xdotool key ctrl+b o && xdotool key ctrl+b shift+48 ctrl+b o ctrl+b o ctrl+b o && clear

It’s also available in my dotfiles on Github.

When, we are done, we can enter tmux:

$ tmux

and run the script:

$ tmux-4tiles

After that, we’ll get the following layout:

tmux-4tiles

We can automate generating different layouts for our purposes in the same way.

Recap

In my opinion, tmux is very useful tool for people working with terminal who want to have organized windows in an elegant way.

References

Introducing ReactiveSensors

2015-09-05 Android, Java, Open source, RxJava No comments

Another month, another library. Recently, I’ve released yet another reactive library called ReactiveSensors. It’s an open-source Android library monitoring hardware sensors with RxJava Observables. Library is compatible with RxJava 1.0.+ and RxAndroid 1.0.+ and uses them under the hood.

Library is available at: https://github.com/pwittchen/ReactiveSensors.

In my opinion, hardware sensors are perfect case for applying RxJava, because in fact we’re constantly receiving a stream of events emitted by many sensors. With Reactive Programming approach we have plenty of possibilities and easy API for manipulating received sensor’s data.

Usage of the library is really simple. You just need to subscribe an Observable with RxJava in the same way like in any other reactive library.

Code sample below demonstrates how to observe Gyroscope sensor:

Please note that we are filtering events occuring when sensors reading change with ReactiveSensorEvent.filterSensorChanged() method. There’s also event describing change of sensor’s accuracy, which can be filtered with ReactiveSensorEvent.filterAccuracyChanged() method. When we don’t apply any filter, we will be notified both about sensor readings and accuracy changes.

We can observe any hardware sensor in the same way. You can check list of all sensors in official Android documentation.

I’ve created section about Good Practices regarding working with hardware sensors on Android in README.md file in the GitHub repository.You should also read an article about Best Practices for Accessing and Using Sensors in official Android documentation.

Read more in the README.md file located in the repository of the library at: https://github.com/pwittchen/ReactiveSensors.

You can also find JavaDoc at: http://pwittchen.github.io/ReactiveSensors/.

If you want to use ReactiveSensors in your project, add the following dependency to your build.gradle file:

dependencies {
  compile 'com.github.pwittchen:reactivesensors:0.0.1'
}

Feel free to send me feedback, report an issue or fork the library!

Learning Python

2015-09-01 Python No comments

Some time ago, I’ve decided to learn Python programming language. I thought it may be useful during performing some basic tasks in the system and Linux or Windows scripting. Moreover, it’s good language for developing web applications with frameworks like Django, Flask or Bottle. I’ve decided to go through all of the tasks in the Learn Python – The Hard Way course. Basic tasks weren’t surprising. They were similar to other object oriented languages. In the further tasks we can learn basic features available in Python language, which are not so common for e.g. Java programmers. I’ve placed all tasks in learn-python-the-hard-way repository on GitHub.

Moreover, in README.md file I’ve added information about:

  • Installing Python on Windows and Linux
  • Executing Python scripts from terminal
  • Pip package manager and installing it on Windows and Linux
  • Using Pip
  • Unit Testing
  • Virtualenv
  • Scripts on Linux
  • Style Guide for Python Code
  • Development Environments
  • Popular Python web frameworks
  • Useful Python libraries
  • Additional Resources & links

In addition, to learn this language better, I’ve decided to create a few simple projects:

  • android-resource-converter – scripts converting Android xml resources with translations to csv file and backwards
  • git-branch-comparator – checks if development branch has all changes from master branch in Git repository
  • craplog – verifies whether your git log is a crap or not

What’s interesting first two of them were used in production and second project is running regularly on a CI server.
Other developers also create similar tools and scripts. For example Pidcat is pretty handy and useful tool for Android developers and it’s just a single script written in Python.

To sum up, I can tell that Python is great object oriented language with a clean and simple syntax. With this language we can achieve our goals really fast with a few lines of code and readable solution. I recommend to learn this language to broaden our horizon even if we are programming in totally different technologies on daily basis.

Gnome Classic desktop environment on Ubuntu

2015-08-23 Linux, Ubuntu, UI No comments

Introduction

I was tired of non-minimal and quite slow Unity desktop environment. Of course, I performed a few tricks to make Unity faster, but still I wasn’t satisfied enough. I checked out different desktop environments. I wanted to have clean, minimal and productive environment. I like top panel from Unity as well as HUD and many workspaces. The last thing is quite common among different desktop environments.

New desktop environment

I decided to choose Gnome classic. It’s fast, clean, minimal, works easily with Ubuntu, has top panel and is configurable.
My current desktop looks like this:

screenfetch-2015-08-18-11_00_51

Unfortunately, I don’t have HUD like in Unity, but after a few days I got used to that. I also turned off all animations and visual effects. Everything works smoothly and looks much better than Unity. In the current configuration I have: Z Shell, Oh-my-zsh, dmenu, Numix Theme and Numix Circle Icons. In addition, I have the same indicators, which I had earlier on Unity and they work fine. I just needed to adjust look of Spotify icon in top panel. Moreover, Gnome Pie was installed later as additional launcher and media controller.

Installation of Gnome Classic and Numix Theme

I’ve installed Gnome Classic as follows:

sudo apt-get install gnome-session-fallback

Then, I installed Gnome Tweak Tool and Unity Tweak Tool:

sudo apt-get install gnome-tweak-tool unity-tweak-tool

and Compiz Config Manager with plugins:

sudo apt-get install compizconfig-settings-manager compiz-plugins-extra

Please note: to enable alt+tab in gnome classic fallback, open the manager and navigate to window management and check application switcher (previously disabled).

After that I could install Numix icons and theme:

sudo add-apt-repository ppa:numix/ppa
sudo apt-get update
sudo apt-get install numix-gtk-theme numix-icon-theme numix-icon-theme-circle

I’ve set appropriate theme and icons via Gnome Tweak Tool. After reboot of the computer changes should be successfully applied.

Detailed information about configuration

If you’re interested in detailed configuration information, you can check out my dotfiles at: https://github.com/pwittchen/dotfiles and system configuration at: https://github.com/pwittchen/ubuntu-config.

To generate system information for the screenshot I used screenfetch script. I didn’t worked correctly for gnome-session-fallback, but I’ve made small contribution on GitHub and now it’s fine.

Wallpaper

You can find wallpaper from the screenshot at papers.co website.

Alternatives & Resources

I’ve spent some time on analyzing alternative desktop environments and Linux based operating systems, which looks good.
Below, you can find my collection of information and resources. Maybe some of them will be better for your specific needs.

Interesting Reddit channels:

Selected Linux based systems with interesting user interface:

Selected Linux window managers:

Recap

After switching from Unity to Gnome my desktop is much more better, faster and cleaner. After mastering popular shortcuts for managing programs, windows, workspaces, etc. we can work very efficiently. Gnome Classic is fine for me right now, but maybe other WM will be better for you. It depends on your personal preferences. I’m gonna use Gnome Classic for some time and maybe I’ll try other environments in the future. For sure I won’t go back to Unity if it don’t evolve.