Friday, July 12, 2013

Terminal IDE - builder

There's an app for Android devices called Terminal IDE by Spartacus Rex. It's a command line development environment for Java and Android and appears to now be hosted in Google Code.

I've been using it for a while off and on, when I'm working on something that won't wait until I have a computer but doesn't warrant carrying a machine with me (like on a backpacking trip). Its power and simplicity make it perfect for a little on-the-go coding as ideas come to mind.

One part that wasn't so simple when I first got started was the builder. I found it to be a little clunky to use. There is another builder script here, along with a few other utilities. That one has lots of options.

Below, I'm posing a builder that I wrote some time ago that is very simple and only has a couple options. It has served me well so perhaps you'll also find it useful.

The simplest way to build and execute your code is to place the script in your home directory (~). Then, cd into the directory containing your .java file, and run this line:
. ~/ -l

For the help file, you can always run: . ~/ -h

Here is the entire script:


#Simple Build Script

#For some reason the getopts index needs to be reset manually...


while getopts "f:hlo" opt
case $opt in
     \? | h)

cat << EOF
usage: $scriptname [ hlo ] [ f ]
-h    Show this message
-l    Launch file after building
-o    Only launch, no build
-f    Specify a file instead of finding the java file in the current directory

You may specify class locations by listing them in a file named "includes" in the same directory as the java file to be launched.

Execution examples:
To build the java file in the current directory: $scriptname
To build and launch:                             $scriptname -l
To launch only:                                  $scriptname -o
To specify a file to build and launch:           $scriptname -lf

Example includes file:
# Bring in my utilities classes


#Find java javaFilename if none given
if [[ $javaFilename == "" ]]; then
if [ `ls -l |grep -c .java` != 1 ]; then
       echo  Because there is not a solitary java file in the directory, you must specify a filename using the -f switch.
javaFilename=`find . -name *.java`
if [ ! -f ${javaFilename}.java ]; then
echo File ${javaFilename}.java not found.

#Prepare to include other classes, if specified.
if [ -f includes ]; then
while read line; do
if [ "${line}" != "" -a "${line:0:1}" != "#" ]; then
includeList=${includeList}" "${line}"/*.class"
done < includes
echo No \"includes\" file.

if [ $compile -eq 1 ]; then
#Clean up. This does not clean up inner class classfiles but does allow for multiple class files in the same directory to be included in the generated jar.
if [ -f ${javaFilename}.class ]; then
rm ${javaFilename}.class
if [ -f ${javaFilename}.jar ];then
rm ${javaFilename}.jar

#Compile java file into classfile(s).
if [ -z $compileList ]; then
javac -verbose ${javaFilename}.java
javac -verbose ${javaFilename}.java -classpath $compileList

#Now convert to dex file. The assumption is you want to include all class files in the directory.
dx --dex --verbose --output=${javaFilename}.jar ./*.class $includeList

#Finally, launch if specified.
if [ $launch -eq 1 ]; then
java -jar ${javaFilename}.jar $javaFilename

MacBook Pro Retina SD card slot problem

I bought a 13" MacBook Pro Retina from a nice guy on craigslist a few months ago. It has been a spectacular machine in speed, capacity and light weight. SSD drives are certainly the way of the future.

One of the features of MacBooks has been the SD card slot, allowing users to plug in the memory chip from their camera or whatever, for quick and easy file transfer. Historically, I've not made use of these slots so I thought it would merely be another way water could be spilled into the machine, rather than a useful port. Since switching to a Canon Rebel t3i which uses an SD card, I have found the slot to be very handy and my preferred method of pulling photos and clearing out the camera memory.

After a few months of use however, the slot stopped working. I ignored it for a few weeks, thinking it would go back to working either through magic or the slight jarring that probably occurs when the machine rides around in my bag. When I tried it again and found it had not repaired itself, I gave it a scornful look and started messing with the seating of the SD card. I found, as I later discovered others had, that if the card is seated completely in the slot, it will not be recognized by the machine. If you pull the card out about 1-2 millimeters, the card will be recognized and work, though not consistently.

I brought the machine into the Genius Bar and they said the SD card board should be replaced. This was done under warranty because the machine is only 7 months old, but all told it would have cost $83.32. For anyone who is facing this troubling problem, see if your machine is still under warranty. If so, pop into a Mac shop and get it fixed. If you're not under warranty and want to save money, maybe you can ride out the millimeter fix until the board finally dies. Then you'll have to belly up and pay the piper or use a USB reader, which is no big deal.

Droid 4 and Webtop

The intended post was to be about an app on my phone but as my first and only post was about the G1 5 years ago, I'll provide a quick update.

The G1 was great. It's small, resilient and has the physical keyboard with separate row for number keys. Unfortunately, the "c" key basically stopped working, which is a bit of a nuisance. When that became truly painful and large improvements in the camera had come to pass, I was looking at a Droid 1 that seemed to function really well, but the writing was on the wall that it would soon be outdated. The Droid 2 arrived on the market and I got one the next day. It was exciting, though it lacked the huge crowds generated at the G1 launch years earlier.

The Droid 2 was a great phone though it lacked a separate row for the number keys, instead requiring use of the Alt modifier key. This is still a pet peeve of mine with respect to many of the physical keyboards available.

Thankfully the issue was remedied with the Droid 4, which I now use and enjoy thoroughly. Along with the separate number row, it has a micro hdmi port for use with a monitor or TV. I didn't think I'd ever have any real need for it, but I bought a cable anyway, just in case. That gambit paid off recently when I had to leave my MacBook at the shop for an SD card slot repair.

That night I dug up my micro hdmi cable, plugged the phone into my monitor and connected the bluetooth keyboard. It was excellent! Not great resolution, and the OS lacks the flexibility, speed and power of a notebook, but I could continue working on some scripting with a nice, big screen and full keyboard.

Though the need rarely comes up, I think the Webtop and hdmi port were a great addition to the Motorola Droid family of phones. Looks like subsequent models let go of this feature because, like me, few people really made use of it. Maybe if Android becomes more flexible (like being able to have more than one app on screen at a time) this technology could be in demand. In the meantime, we'll keep working with our notebook and phone or phablet combinations.

Tuesday, October 21, 2008

G1 - The Google Phone

After hanging in there with my old HP iPaq for an unknown number of years, I've finally found my upgrade. The Google Phone, aka G1.
I've only just started using it but it's such a huge improvement over my iPaq, it really can't do any wrong. It'll take a few days to figure it out but for now, I'm very pleased.