Friday, June 28, 2013

Bash: syntax error: unexpected end of file

When you get:

syntax error: unexpected end of file

You should make sure that you don't have problems with end of line characters, however the ERROR in logic of your code (bad command) wil cause that as well.

Sometimes it is easier to comment out all lines with "# your code"and turn on some little-by-little.

Unix: dos2unix on Mac

Removing Windows line ends on Mac:


$ cat file1.txt | col -b > file2.txt

Warning: Do not run this with destination of the same file, or it will become empty.

Thursday, June 27, 2013

Android: re-installing a bunch of apps with one script

I have a bunch (over a dozen) of APKs that go together on the device as a single solution, to remove them and reinstall all of them would be a time consuming effort, so I have scripts for that.

Do not believe "-r" option in "adb install -r", it does not always re-install the app.

I have a single script with bunch of uninstalls...

adb uninstall
$ adb uninstall
$ cd your_apks
# install all APKs in this folder
$ for i in *.apk; do adb install -r $i; done

UNIX: -bash: xyz.bash: cannot execute binary file

You create your script file but it does not want to execute... error:

 -bash: xyz.bash: cannot execute binary file

Step 1:

Make sure it has execute permissions

@ scripts $ chmod 777 xyz.bash 

Step 2:

Make sure scrip does not have ERROR inside, special characters that prevent execution.

Sunday, June 23, 2013

Starting with Go language by Google

1. Download and Install the Go - no configuration needed
2. Add variable:
~@ ~ $ edit ~/.profile

# Go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin

3. Close and open Terminal

@ ~ $ which go

4. create a sample program

@ workspaces $ mkdir go_programs
@ workspaces $ touch hello.go
@ workspaces $ edit hello.go 
@ workspaces $


package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")

Edit PATH again:

# Go
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=~/Documents/workspaces/go_programs

5. Run your first program
@ workspaces $  go run hello.go
hello, world

6. Take a tour

Sunday, June 16, 2013

Terminal: set command line prompt and PATH variables in Bash ~/.profile

As a developer you will find yourself using Command Line ( every day, all the time, so it is worthwhile to set it up to behave just right for you...

Open Application > Utilities > (drag it to your toolbar for quick access)

My shell looks like that, it tells me a lot of info just as verification...

Last login: Mon Sep 15 11:56:15 on ttys000
edit ~/.profile
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b05)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b05, mixed mode)
git version 1.9.0
uki@ CNH_PROD $ vi ~/.profile

We can use vi editor, but on daily basis I just type "edit ~/.profile"

# ANDROID - updated: Sept 15, 2014
export ANDROID_HOME=/Applications/Android/SDK/android-sdk-macosx
export PATH=${PATH}:${ANDROID_HOME}/build-tools/19.0.3
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PATH=${PATH}:${ANDROID_HOME}/tools

echo "edit ~/.profile"
# Adjust prompt.
# \d – Current date
# \t – Current time
# \h – Host name
# \# – Command number
# \u – User name
# \W – Current working directory (ie: Desktop/)
# \w – Current working directory, full path (ie: /Users/Admin/Desktop)
export PS1="\u@ \W $ "
java -version
git version
which adb

To EDIT hit "i" for insert
To Save and Quit you type ESC + :wq + Enter
I have MUCH MORE configurations in there, but it is specific to what you have on your computer.

Friday, June 14, 2013

Getting Info About APK

Often you have apk that you need (e.g. package, version) info for, but you have no documentation about it. This little command gives you a lot of info.

$ aapt dump badging  someapp.apk
package: name='' versionCode='1' versionName='1.1'
application: label='SomeApp' icon=''
uses-implied-feature:'android.hardware.touchscreen','assumed you require a touch screen unless explicitly made optional'
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--'
densities: '160' '240' '320'
uki:~ uki$

Wednesday, June 12, 2013

Android: updating SDK from command line

You may want to create a script "Update Android SDK.bash" that quickly gets you up to speed without starting IDE (e.g. Eclipse) UI.

echo 'Android SDK home ' $ANDROID_HOME
$ANDROID_HOME/tools/android update sdk --no-ui --all --force 

Notice that it will ask you several times to click letter 'y'
Do you accept the license 'android-sdk-license-bcbbd656' [y/n]: y

Installing Archives:
  Preparing to install archives
  Downloading Android SDK Tools, revision 23.0.2
     (15%, 525 KiB/s, 2 minutes left))

Thursday, June 6, 2013

Creating Google API key for Map v2

The key will be needed in AndroidManifest.xml like this... 



To get the key go to:

1) create a NEW app (drop-down on the left Create...)
2) Select "Services" and turn on Maps...

3) API Access "Create new Android Key.." button

4) Terminal:
$ cd .android/
uki$ keytool -list -v -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android 
Alias name: androiddebugkey
Creation date: Nov 23, 2011
Entry type: PrivateKeyEntry
Certificate chain length: 1
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 4ecdba20
Valid from: Wed Nov 23 21:29:36 CST 2011 until: Fri Nov 15 21:29:36 CST 2041
Certificate fingerprints:
MD5:  7E:FA:01...fkdjsflkjdlksjflkdsjlfjdsljfljlkdsf....:49:61:36
SHA1: D0:5...sdjkflkdsjflkjsdklfjdsljkdsl....F:A1:43
Signature algorithm name: SHA1withRSA
Version: 3 uki$ 

5) Enter the SHA1 key, SEMICOLON; and PACKAGE NAME of your app

6) copy the successfully generated KEY to AndroidManifest.xml


Wednesday, June 5, 2013

Apache Server on Mac OS 10.8

The Apache server is available on Mac by deploying your html pages to:


uki:Documents uki$ ls -alt /Library/WebServer/Documents/
total 80
-rw-r--r--  1 root  wheel   3726 Aug 24  2012 PoweredByMacOSX.gif
-rw-r--r--  1 root  wheel  31958 Aug 24  2012 PoweredByMacOSXLarge.gif
uki:Documents uki$

You start the Apache server by:
$ sudo apachectl start

Re-deploying your code:
remove old:
$ sudo rm -r /Library/WebServer/Documents/my_project
Make directory:
$ sudo mkdir /Library/WebServer/Documents/my_project
copy new code in:
$ sudo cp -r /Users/uki/Documents/workspaces/.../my_project/* /Library/WebServer/Documents/my_project

you can view your local server at:

Setting JAVA_HOME variable on Mac

$ edit ~/.profile

add line

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`


re-open Terminal

$ echo $JAVA_HOME


Please note that the most current version (1.6) is loading when 1.7 is missing.