Tuesday, June 25, 2013

How to install the latest Git on OS X

            

I've been using git v.1.7.10.2 long time, despite the fact that git v.1.8+ released several months ago. So, I've decided to updated my local git via homebrew.

$ git --version
git version 1.7.10.2 (Apple Git-33)

$ brew install git

==> Downloading http://git-core.googlecode.com/files/git-1.8.3.1.tar.gz
######################################################################## 100.0%
==> make prefix=/usr/local/Cellar/git/1.8.3.1 CC=cc CFLAGS= LDFLAGS= install
==> make CC=cc CFLAGS= LDFLAGS=
==> make clean
==> make CC=cc CFLAGS= LDFLAGS=
==> Downloading http://git-core.googlecode.com/files/git-manpages-1.8.3.1.tar.gz
######################################################################## 100.0%
==> Downloading http://git-core.googlecode.com/files/git-htmldocs-1.8.3.1.tar.gz
######################################################################## 100.0%
==> Caveats
The OS X keychain credential helper has been installed to:
  /usr/local/bin/git-credential-osxkeychain

The 'contrib' directory has been installed to:
  /usr/local/share/git-core/contrib

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
  /usr/local/Cellar/git/1.8.3.1: 1324 files, 28M, built in 113 seconds

$ git --version
git version 1.7.10.2 (Apple Git-33)
As you can see the latest git isn't on PATH. Than I've asked the doctor's help:
$ brew doctor
Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

    git
    git-cvsserver
    git-receive-pack
    git-shell
    git-upload-archive
    git-upload-pack
    gitk

Consider amending your PATH so that /usr/local/bin
occurs before /usr/bin in your PATH.
I.e. I need to put the homebrew git before system git:
$ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile
After the terminal's restart I've got the next:
$ git --version
git version 1.8.3.1

Friday, June 14, 2013

Java Barcode Generation and Scanning Library

Recently I had to pick library which can generate and scan different 2D barcodes. Actually I was interested in QR Code and Data Matrix. There is only ONE open source Java library which generates and scans barcode, it's Zxing. You might say there are others, but they cost money.

I've been following Zxing some time and must admit that this library has very vibrant community, code base is clean, plenty of unit tests. Also, API is very clean. Here is a simple code snippet for scanning Data Matrix barcode:

String filename = "file.png";
    
Map<DecodeHintType,Object> hints = new EnumMap<DecodeHintType,Object>(DecodeHintType.class);
hints.put(DecodeHintType.POSSIBLE_FORMATS, Arrays.asList(BarcodeFormat.DATA_MATRIX));
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
        new BufferedImageLuminanceSource(
            ImageIO.read(new FileInputStream(filename)))));

Result result = new MultiFormatReader().decode(binaryBitmap, hints);
System.out.println(result.getText());

I've tested Zxing v.2.2 QR Code/Data Matrix scanning. And Zxing implementation for QR Code scanning is more robust and well implemented in comparison to Data Matrix. I.e. if you have freedom and can choose any of these two barcodes, than select QR Code.

Note, there are several open source barcode generation libraries and only a few barcode scanners (actually one Zxing for Java)