Monday, February 14, 2011

Highlighting Standard Output in color

I trace many of my log files to the screen, things some times get overlooked when there is a bunch of output all at one time. So after googling a bit I found a nice little gem, I will try to find a reference to link to so I can give credit where it is due.


#!/bin/bash
# tputcolors

TPUT=$(which tput)
if [[ -n $TPUT && -x $TPUT ]] ; then
R=`tput setaf 1; tput bold`
G=`tput setaf 2; tput bold`
Y=`tput setaf 3; tput bold`
X=`tput sgr0`
P=`tput setaf 5; tput bold`
else
R=`echo -en "\\033[1;31m"`
G=`echo -en "\\033[1;32m"`
Y=`echo -en "\\033[1;33m"`
X=`echo -en "\\033[0;39m"`
P=`echo -en "\\033[0;35m"`
fi

while read line ; do
case "$line" in
*[Ee]rror*|*problem*|*ERROR*|*E/*)
echo -n "${R}"
;;
*[Ww]arning*|*WARNING*|*W/*)
echo -n "${Y}"
;;
*SUCCESS*|*SUCCESSFUL*|*D/*)
echo -n "${G}"
;;
*INFO*|*I/*)
echo -n "${P}"
;;
esac
echo -e "$line${X}"
done


Friday, October 29, 2010

Debugging Droid on Ubuntu / Fedora

I am a linux user, and recently I decided that I wanted to debug directly on my Motorola Droid. I went through the process of enabling debugging from the device (see below screenshots).


The problem I faced was when I plugged my device into my computer. When requesting a device list from adb I received the following message.

$ adb devices
List of devices attached
???????????? no permissions

After a few moments of googling I discovered an interesting blog, of a fella that had the solution of the same issue. The blog was entitled Debugging the droid on ubuntu karmic on aphyr.com.

I am re-blogging this for a quick reference for me to quickly find the solution, if I were to ever need it again. Thanks aphyr.com for the help in resolving this issue!!

The below line was the solution to grant the correct permissions needed to enable usb debugging

# /etc/udev/rules.d/99-android.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", SYMLINK+="android_adb", MODE="0666" GROUP="plugdev"

I also had to add more permissions for other devices i.g (droidX, dell streak). After doing some digging I found that usb-devices command prints out the list of all the devices that is plugged into the computer.

My Moto droid was in this list and I was able to repeat for all devices to get the vendor id to allow debugging from all devices.

Monday, October 18, 2010

How to make vim your primary editor for subversion.

How to make vim your primary editor

In Linux you can set the EDITOR environment variable by adding the following to your .bash_profile, .profile, .bashrc, or .bash_aliases file; depending on your distro.

export EDITOR=/usr/bin/vim

What about svn diff??

open subversion's config file, mine lives in /home/[user]/.subversion/config
Look for the line that talks about diff-cmd

diff-cmd = /home/[user]/.subversion/diffwrap.sh

Save and close the file.
save the contents of this code block as diffwrap.sh. Set the permissions to be executable by primary user. You will now be using vimdiff for your difference when you do an svn-diff

diffwrap.sh

#!/bin/sh
# Configure your favorite diff program here.
DIFF="/usr/bin/vimdiff"

# Subversion provides the paths we need as the sixth and seventh
# parameters.
LEFT=${6}
RIGHT=${7}

# Call the diff command (change the following line to make sense for
# your merge program).
$DIFF $LEFT $RIGHT

# Return an errorcode of 0 if no differences were detected, 1 if some were.
# Any other errorcode will be treated as fatal.

Sunday, October 17, 2010

Making Backgrounds Repeat in Android

Today, I was working with a layout that I wanted to have a background image repeat throughout the width and height of a Linear Layout.

My First Attempt

Initially it seemed to make sense to create a new layout, place the image into the drawable, resource directory, and reference this as the android:background attribute of the LinearLayout definition

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/honeycomb"/>

As you can see from the screenshot that what I had assumed did not automatically tile or repeat the background, rather it stretched the image the full dimensions of the container.

Second Attempt

After some digging on the internet. I found that you can create a drawable in xml, using a resource of an image drawable, in my case the honeycomb. In the drawable you can tell it that it should tile and repeat as needed.

honeycomb_tile.xml:

<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/honeycomb"
android:tileMode="repeat" />

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/honeycomb_tile"/>

Results:

Labels

android (2) debugging (1) fedora (1) linux (1) subversion (1) ubuntu (1) ui (1) vim (1)