Monday, August 13, 2012

Simple HTTP server using Python


1) Change to your www directory, a location of your files, include at least index.html:

$ cd /Users/uki/Python/web/SimpleHTTPServer/www 

2) Start server at port you want:

$ python -m SimpleHTTPServer 8080


3) Open: http://localhost:8080/

4) Monitor requests:


uki:www uki$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 ...
1.0.0.127.in-addr.arpa - - [13/Aug/2012 20:21:00] "GET / HTTP/1.1" 200 -
1.0.0.127.in-addr.arpa - - [13/Aug/2012 20:21:00] code 404, message File not found
1.0.0.127.in-addr.arpa - - [13/Aug/2012 20:21:00] "GET /favicon.ico HTTP/1.1" 404 -
1.0.0.127.in-addr.arpa - - [13/Aug/2012 20:21:12] "GET / HTTP/1.1" 200 -
1.0.0.127.in-addr.arpa - - [13/Aug/2012 20:21:12] code 404, message File not found
1.0.0.127.in-addr.arpa - - [13/Aug/2012 20:21:12] "GET /favicon.ico HTTP/1.1" 404 -

Transparent Button with an Icon


To create a button that is wide enough to press, but transparent, with the icon inside:     


 <ImageButton
                android:id="@+id/save"
                android:layout_width="100dip"
                android:layout_height="wrap_content"
                android:background="@null"
                android:contentDescription="@string/save_text"
                android:src="@drawable/save" />

Friday, August 10, 2012

svn: Commit failed


svn: Commit failed (details follow):
svn: Directory '/trunk/XYZ' is out of date

Solution:

Delete the project including the source files and check it out again.

Conversion to Dalvik format failed with error 1


UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/androidquery/AbstractAQuery;

[2012-08-09 22:41:36 - Yachts and Tall Ships] Dx 1 error; aborting
[2012-08-09 22:41:36 - Yachts and Tall Ships] Conversion to Dalvik format failed with error 1

Solution:

Once again, I looked thru all sub projects (library projects) and noticed that I have android-query-0.22.10.jar included twice in two library project libs folders.

I moved the jar to what we call lib_common/libs and referenced that jar from there everywhere I needed.

Do not include the same class name in different library projects, use a single common project were you keep your commonly used jars.


Wednesday, August 8, 2012

Format JSON in free TextWrangler

Here is an easy way to get formatted JSON in FREE TextWrangler:

Create text (Python) file:
~/Library/Application\ Support/TextWrangler/Text\ Filters/Format\ JSON.py




#!/usr/local/bin/python
import fileinput
import json
if __name__ == "__main__":
  text = ''
  for line in fileinput.input():
    text = text + ' ' + line.strip()    
  jsonObj = json.loads(text)  
  print json.dumps(jsonObj, sort_keys=True, indent=2) 



or shorter:


#!/usr/local/bin/python
import fileinput
import json
print json.dumps( json.loads(''.join([line.strip() for line in fileinput.input()])), sort_keys=True, indent=2)




Save it and use it!