Tuesday, May 26, 2009

Google Android - map not working in emulator? - how to fix it (in Windows) - by Alan Lupsha

Basically, you need a Google Mpas api key: http://code.google.com/android/add-ons/google-apis/mapkey.html

Example on how to do this:

1. find your debug.keystore file, for example:
C:\Documents and Settings\developer\.android\debug.keystore

2. list the md5:
C:\jdk1.6.0_13\bin>keytool -list -alias androiddebugkey -keystore "C:\Documents and Settings\developer\.android\debug.keystore" -storepass android -keypass android

androiddebugkey, May 18, 2009, PrivateKeyEntry,Certificate fingerprint (MD5): 83:4D:2C:6F:58:B3:D1:EA:2C:AF:0D:FC:70:19:57:D6

Save the fingerprint somewhere, you'll need it later.

3. Sign up for the maps API: http://code.google.com/android/maps-api-signup.html , use your generated MD5 fingerprint

Submission result:

Thank you for signing up for an Android Maps API key!

Your key is:
0h1d_-9Wwhaterver-your-key-is4yNt-SXgQ

This key is good for all apps signed with your certificate whose fingerprint is:
83:4D:2C:6F:58:B3:D1:EA:2C:AF:0D:FC:70:19:57:D6

Here is an example xml layout to get you started on your way to mapping glory:




Go to your project's layout, i.e. in main.xml, look for your MapView definition,
take out android:apiKey="apisamples" and replace it with whatever your key is,
for example: android:apiKey="0h1d_-9Wwhaterver-your-key-is4yNt-SXgQ"

or, if you didn't define your mapView in XML, but instead you did it in code, use:
mMapView = new MapView(this, "0h1d_-9Wwhaterver-your-key-is4yNt-SXgQ");

Also, make sure that in your manifest, you have this defined:

Monday, May 25, 2009

Linux: how to send emails with attachments from the command line

echo "Sending an attachment " | mutt -a my-superb-tar-file.tar -s "attachment" alan75@my-fun-domain.com

Friday, May 22, 2009

How to stop and restart subversion using a simple script

1. create the svn restart script:
sudo nano /etc/init.d/restartsvn

sudo cat /etc/init.d/restartsvn
#!/bin/bash
echo This is a startup script to stop and restart subversion - Alan

echo Now stopping previous svn instance...
sudo kill -9 `ps aux | grep -i svn | grep -i listen-host | grep -v grep | awk '{print $2}'`

echo Sleeping 3 seconds...
#sleep 3 seconds
sleep 3

echo Now starting svn for you: /usr/bin/svnserve -d --listen-host 10.0.0.10 -r /srv/svn
/usr/bin/svnserve -d --listen-host 10.0.0.10 -r /srv/svn

echo The process id of the new svn instance is:
echo `ps aux | grep -i svn | grep -i listen-host | grep -v grep | awk '{print $2}'`
echo Done


2. make the script executable
sudo chmod u+x /etc/init.d/restartsvn

3. execute the script
sudo /etc/init.d/restartsvn

Thursday, May 21, 2009

Java - how to keep your instance NamingEnumeration object and iterate through it without .next() killing it


Problem: You have a NamingEnumeration and want to keep untouched, while passing it to different methods that need to iterate through it. Error: doing a namingOperation.next() walks the object, and when you reach the end, there's no .moveToFront() method, which allows you to re-use the NamingEnumeration object.

Solution: use Collections.list( namingEnumeration ), which returns an ArrayList. Then, instantiate a new copy of the original ArrayList and then use this copy, with an Iterator, walking each element of the arrayList object.

The example below is of a NamingEnumeration A which is made up of many NamingEnumerations B, which are made up of some NamingEnumerations C. (basically it's an LDAP naming enumeration result after performing a dirContext.search( ... )


See, this won't work:

public static void printAllAttributes( NamingEnumeration originalNamingEnumeration )


// used only to create copy
ArrayList arrayListBackup = Collections.list( originalNamingEnumeration );

// create copy
ArrayList arrayList = new ArrayList( arrayListBackup );
...
because the originalNamingEnumeration gets "exhausted" after Collections.list() is called.
So, your only option is to get the original NamingEnumeration, convert it to an ArrayList:

NamingEnumeration namingEnumeration = dirContext.search( searchBase, searchFilter, searchControls );
ArrayList tempArrayList = Collections.list( namingEnumeration );
and forget about it:

namingEnumeration.close();
namingEnumeration = null;
Then, make as many copies of that tempArrayList, and use those copies:

ArrayList arrayListCopy1 = new ArrayList( tempArrayList );
... do whatever
ArrayList arrayListCopy2 = new ArrayList( tempArrayList );
... do whatever
ArrayList arrayListCopy3 = new ArrayList( tempArrayList );
In my case, I want to keep the search results of an LDAP query, which is stored
in a NamingEnumeration, and then call different methods on the search results,
which iterate on the NamingEnumeration, screwing it up. So, keeping the search results
in a globally defined ArrayList object allows me to use it later. Final search routing looks as such:


public int search( String searchBase, String searchFilter )
{
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
try
{
NamingEnumeration namingEnumeration = dirContext.search( searchBase, searchFilter, searchControls );
ArrayList tempArrayList = Collections.list( namingEnumeration );
namingEnumeration.close();
namingEnumeration = null;

this.lastSearchResultArrayList = new ArrayList( tempArrayList );
tempArrayList = null;
}
catch ( NamingException e )
{
logerror("Error while searching: " + e.toString() );
return -1;
}
return 0;
}

Thursday, May 14, 2009

Java - Rot94 - similar to rot13 - encode text





public class NinetyFiveEncode
{
public NinetyFiveEncode()
{
String testStr = "The rain in Spain falls mainly on the plain. Call me at (555)112-xxxx. {:-) Bye.";
String encoded = NinetyFiveEncode.rot94(testStr);
System.out.println( encoded );
String decoded = NinetyFiveEncode.rot94( encoded );
System.out.println( decoded );
}

/*
* Rot94 by Alan Lupsha (c)2009
*
* Takes a string of characters, and for every character
* between ASCII value 33 and 126 (! to ~), it adds 94 to
* the character value (wraps around if the result character
* is larger than 126)
*
* Any non-printable characters and the space character
* (i.e. any char smaller than 33 and larger than 126) gets
* copied over.
*
* Sample run:
*
* String testStr = "The rain in Spain falls mainly on the plain. Call me at (850)879-xxxx. {:-) Bye.";
* String encoded = NinetyFiveEncode.rot94(testStr);
* System.out.println( encoded );
* String decoded = NinetyFiveEncode.rot94( encoded );
* System.out.println( decoded );
*
* %96 C2:? :? $A2:? 72==D >2:?=J @? E96 A=2:?] r2== >6 2E Wgd_Xgfh\IIII] Li\X qJ6]
* The rain in Spain falls mainly on the plain. Call me at (850)879-xxxx. {:-) Bye.
*/
public static String rot94(String plainText)
{
if (plainText == null) return "";

// encode plainText
StringBuffer encodedMessage = new StringBuffer("");
int abyte;
for (int i = 0; i < abyte =" plainText.charAt(i);">= 33) && (abyte <= 126 ))
abyte = (abyte - '!' + 47) % 94 + '!';

encodedMessage.append( (char)abyte );
}
return encodedMessage.toString();
}


public static void main( String[] args )
{
NinetyFiveEncode ninetyFiveEncode = new NinetyFiveEncode();
}
}


Wednesday, May 13, 2009

How to check the status of your Android phone purchased from Brightstarcorp through Google

1. Go to: http://android.brightstarcorp.com/trackorder.php

If you are logged into your Google account, the page will display the status of your order right away. Ex: "Pending shipment" Else, log in and see your status.


2. Call Brightstarcorp at 877-727-9789 and ask to track your order, and give them your order number which you received in the email right after you purchased your phone. This will likely mean that they'll send out the phone today instead of waiting another 7 days to mail you your phone (even if you already paid for FedEx overnight delivery)