Saturday, October 27, 2012

Mac OS X terminal supports colored output

Mac OS X Mountain Lion Terminal hasn't been configured to support coloured output.
You can check it via simple command run "ls -la":
Let's fix this.

1. Add the next string to  .bash_profile
export CLICOLOR=1

2. Create script:
$ cat ./

echo -e "\033[0mCOLOR_NC (No color)"
echo -e "\033[1;37mCOLOR_WHITE\t\033[0;30mCOLOR_BLACK"
echo -e "\033[0;34mCOLOR_BLUE\t\033[1;34mCOLOR_LIGHT_BLUE"
echo -e "\033[0;32mCOLOR_GREEN\t\033[1;32mCOLOR_LIGHT_GREEN"
echo -e "\033[0;36mCOLOR_CYAN\t\033[1;36mCOLOR_LIGHT_CYAN"
echo -e "\033[0;31mCOLOR_RED\t\033[1;31mCOLOR_LIGHT_RED"
echo -e "\033[0;35mCOLOR_PURPLE\t\033[1;35mCOLOR_LIGHT_PURPLE"
echo -e "\033[0;33mCOLOR_YELLOW\t\033[1;33mCOLOR_LIGHT_YELLOW"
echo -e "\033[1;30mCOLOR_GRAY\t\033[0;37mCOLOR_LIGHT_GRAY"

$ chmod +x

3. Run ./, you should get something like this:

Also, command "ls -la" should produce colored output. 


Wednesday, October 24, 2012

Github Gists in Eclipse

I'd like to describe simple steps regarding integrating GitHub Gists in Eclipse.
There are several sources which provoke me to do this:
I've been using Eclipse Java EE destibution, Mylyn plugin has been already installed there:
1. Install EGit plugin via Eclipse Marketplace:

2. Install GitHub Mylyn Connector via Eclipse Marketplace:
3. Open View "Task List" and click "Add Repository":
4. Add Mylyn Task repository - "GitHub Gists":
5 .Then you should create Mylyn Query to fetch all Gists:

6. You should get something like this:
That's it. Have fun.

PS. Please note I've excluded such common sense steps as providing credentials for your GitHub account.

Saturday, October 20, 2012

Git command extention

You probably know about "git config alias.*" command. See quote from documentation:
If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining " = !gitk --all --not ORIG_HEAD", the invocation "git new" is equivalent to running the shell command "gitk --all --not ORIG_HEAD". Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory.
Base on this we can define some "new" command via aliases. But, there is another way for extending git. Let's have a quick view into git.c source:
int main(int argc, const char **argv)
const char *cmd;

startup_info = &git_startup_info;

cmd = git_extract_argv0_path(argv[0]);
if (!cmd)
cmd = "git-help";


* "git-xxxx" is the same as "git xxxx", but we obviously:
* - cannot take flags in between the "git" and the "xxxx".
* - cannot execute it externally (since it would just do
* the same thing over again)
* So we just directly call the internal command handler, and
* die if that one cannot handle it.
if (!prefixcmp(cmd, "git-")) {
cmd += 4;
argv[0] = cmd;
handle_internal_command(argc, argv);
die("cannot handle %s internally", cmd);

It means we can define some executable peace of code (shell script, ruby script, etc.) which has prefix "git-". Put this script on system path (add to $PATH variable) and it will be treated as git command.

Let's clarify all this via sample code:
$ cd ~
$ mkdir bin

$ #create git-foobar file 
$ cat > git-foobar
echo "[foobar] commad"
$ chmod +x git-foobar

$ git-foobar
[foobar] commad
$ cd ~

$ #check if ~./bin folder is in $PATH variable
$ cat .bash_profile
export PATH="$HOME/bin:$PATH"

$ #now check git 
$ git foobar
[foobar] commad

Wednesday, October 17, 2012

How to configure Mac OS X terminal to support git completion and context based prompt?

Msysgit on Windows has several nice features:
  • git commands completion upon press <tab>
  • current git branch name in terminal command prompt
By default git on Mac OS X doesn't have these nice features. Let's configure OS X terminal to support them:
  1. Download two scripts (in $HOME/bin folder) from git contrib which support these features (
    cd ~
    mkdir bin
  3. Now we should update .bash_profile file:
  4. export PATH="$HOME/bin:$PATH"
    source ~/bin/git-completion.bash
    source ~/bin/
    export PS1='[\w$(__git_ps1 " (%s)")]\n\$ '
So, here we have:
  • git-completion.bash does all <tab> completion "magic"
  • is responsible for adding git current branch info, see __git_ps1 function call when defining PS1 variable

Monday, October 08, 2012

Review: Practices of an Agile Developer: Working in the Real World

I've read this book the third time. Authors (Venkat Subramaniam and Andy Hunt) shared their ideas and better practices regarding "how to become a real agile developer".
Each chapter has predefined structure:
  1. General idea
  2. Why something went wrong
  3. Applying the practice
  4. What might go wrong if we try to follow the practice without common sense
  5. Summary
I can suggest this book for any developer who has been diving in the world of "agile". Even more, any junior developer must read this book. After the reading and applying some of the recipes you've got real improvements in your daily work. Do not hesitate and start reading right away.

Monday, October 01, 2012

RubyShift 2012 Conference Report

Recently, a day ago :-) I visited RubyShift 2012 conference (September 29—30, 2012, Kiev, Ukraine). It's primary a Ruby conference with additional mixing from related technologies.

I'm a seasonal Ruby developer and Java is my primary programming language. So, what do I find so interesting in Ruby conference? Well, it's totally a different community with own culture, tools, frameworks and issues. It's better to break the borders and look out of the box. We might find there something interesting and amazing there.

Here is a list of speeches which are favored by me:
  1. DataMapper 2 — an object mapping toolkit, by Piotr Solnica
  2. Data Mapper is well-known pattern in Java community. It was breakthrough for me that Ruby/Rails community is not satisfied with ActiveRecord :-) Nice movement in "better" OO design direction.
  3. RVM 2: what we have learnt and where are we going, by MichaƂ Papis
  4. I was really happy to see the guy behind this tool. The author is going to do a very important work to get rid off shell scripting and re-write RVM 2 in Ruby. I can predict that RVM 2 will be available on Windows as well.
  5. RabbitMQ Hands On, by Alvaro Videla
  6. Simple introduction in RabbitMQ. Nothing special (because it's quite popular in Java), but based on this talk it isn't popular in Ruby community (additional findings for myself).
  7. No nonsense asciicasting for serious hackers, by Marcin Kulik
  8. ASCII.IO is the simplest way to record your terminal and share the recordings with your fellow geeks.
    Very nice tool, well done and pragmatic. The presenter shared with the audience the ideas behind, technical issues and implementation details. It was really interesting.
  9. PostgreSQL in Highload Projects, by Alexey Vasiliev
  10. Alexey presented us "magical" sides of PostgreSQL. I haven't known about all those powerful extension and techniques which can be used with PostgreSQL. Well done :-)