Archive

Archive for the ‘Programming’ Category

Built-in debugger of Python

September 27th, 2012 No comments

Recent Python interpreter has built-in debugger function. We can set break-points, stepping operation and examine variables very easily.

To bring up debugger, we just need to specify option ‘-m pdb’ like following.

python -m pdb xxx.py

Debugger commands which I use often are:

Set break-point
 b 100
Set break-point at line 100
Break-point
 b
List break-points
Clear break-point
 cl 1
Clear 1st break point. We can clear all break-points by just execute ‘cl’
Execute
 c
Execute the script until hit break-ppints
Step
 s
Execute one line of the script
Print
 p abc
Print contents of variable ‘abc’

 

Categories: Programming Tags:

SQLite escape character

March 17th, 2012 2 comments

SQLite3 is small DB engine. This is not a client and server type, but it could be embedded DB engine. It is very handy for personal use.

If we query simple English word, we do not need to care about escape characters. But if we need to look up search word with special characters, we need to know how to escape special characters which has special meaning in SQL sentence.

[ LIKE operator ]
SQLite3 LIKE operator is same to standard SQL. We can use wildcards ‘%’ (matches with multiple characters) and ‘_’ (matches with single character). If we need to search word with those wildcards, we need to use ESCAPE clause.

SELECT * FROM hoge WHERE key LIKE '% test^_case %' ESCAPE '^';

Character which is used in ESCAPE clause is also needed to escape.

Consideration of single quote and double quote “:
- We can use double quote character within single quoted text.
- We can use single quote character within double quoted text.
- We need to escape quote character by quote character itself when we need to mix both single and double quote in a text.

SELECT * FROM hoge WHERE key LIKE 'I''m reading the "SNOW WHITE"';

[ GLOB operator ]
GLOB is unique operator of SQLite3. GLOB allows to use small subset of regular expression. LIKE is case insensitive operator, but GLOB is case sensitive operator.

Let me talk about only how to escape special characters here. We need to escape [ ] * ? for GLOB operator. If we need to match those characters, we use [] to wrap them.

SELECT * FROM hoge WHERE key GLOB 'How are you[?] *';

You can wrap ‘[' or ']‘ also. For example, if we need to match text ‘[Y/n]‘, query would be like follows.

SELECT * FROM hoge WHERE key GLOB '[[]Y/n[]]';

Consideration of quote characters is same to LIKE operator.

Categories: Programming Tags:

MIDP issue on Nokia 3030 (Asha 303)

February 1st, 2012 No comments

I got an error on Nokia 3030 when I ran my old MIDP application.

Nokia 3030 is latest Series 40 Touch and Type device and probably equivalent to Asha 303.

It seems to me, this is caused by MIDP runtime bug on Nokia 3030. The error description was ‘String Index Out Of Bounds’. It happened in delete method of TextBox class.

TextBox tb;
tb.delete(0, tb.size());

The exception happened when no string in the TextBox. This code works, if the TextBox has any characters.

I tested tb.delete(0, 0); also. Result was same. If any characters in the TextBox, I did not see any problems. But if the TextBox was empty, I got ‘String Index Out Of Bounds’ exception. I checked Java ME API document, my code is nothing wrong, I think.

To avoid this problem, I altered my code as follow.

if (0 < tb.size()) {
  tb.delete(0, tb.size());
}
Categories: Nokia, Programming Tags:

How to upload a file using Dropbox API iOS v1.0

November 5th, 2011 20 comments

I am going to use Dropbox API to my iOS application. There is no documentation available for Dropbox SDK for iOS. We need to understand how to use it by sample project which is included with SDK, tutorial on the web and SDK header files.

At first I confirmed sample project ‘DBRoulette’ works fine on my environment. Then I started to try ‘tutorial’ on the Dropbox SDK web page. When I try uploadFile API of the tutorial, I got a ‘deprecated’ warning message.

I could understand the new uploadFile API by Changelog and DBRestClient.h. I hope that the tutorial will be revised to use new API in the future.

- (void)uploadFile:(NSString *)filename toPath:(NSString *)path withParentRev:(NSString *)parentRev
    fromPath:(NSString *)sourcePath;

Here is new uploadFile. paraentRev is new parameter. We can put ‘nil’ here. In this case, uploaded file would never over written existing file on the Dropbox server. If same filename exists on the sever, new filename would be modified like ‘test(1).txt’.

If we need to over write existing file on the server, we need to ger parenetRev before issue the uploadFile. Let me show you simple code fragment for this.

Assumes ‘docDir’ has full pathname for the application Document folder and file ‘test.txt’ is already on the Document folder. resClient is initialized as the tutorial also.

- (void)uploadFile1
{
    [[self restClient] loadMetadata:@"/test.txt"];
}

-(void)uploadFile2:(DBMetadata*)meta
{
    NSString *testfile = [docDir stringByAppendingPathComponent:@"test.txt"];
    [[self restClient] uploadFile:@"test.txt" toPath:@"/" withParentRev:meta.rev fromPath:testfile];
}

// DBRestCleintDelegte
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata
{
    [self uploadFile2:metadata];
}

- (void)restClient:(DBRestClient*)client loadMetadataFailedWithError:(NSError*)error
{
    [self uploadFile2:nil];
}

Purpose of the ‘rev’ is managing revvision of the file on the Dropbox. I do not try this yet. But it looks okay for this code to over write current existing file on the Dropbox server.

You can download my test project DBTest.zip. This is a bit old, but it still works, I think.

Categories: iPhone/iPod Touch, Programming Tags:

Got ‘Invalid Binary’ error on the iTunes Connect

October 23rd, 2011 2 comments

I have updated my old iOS application and submitted it from Xcode4.2 archive function. There was no error message on Xcode both ‘Validate’ and ‘Submi’ functions.

iTunes Connect just showed ‘Invalid Binary’ but no detailed error message. I did not receive any e-mails from iTunes Connect neither.

Finally, I added ‘CFBundleIconFile~ipad’ to my Info.plist and solved the invalid binary problem.

My application is universal application and specified ’3.0′ to ‘iOS Deployment Target’. My Info.plist for icon files was like this:

CFBundleIconFile icon.png
CFBundleIconFiles
  Item 0 icon.png
  Item 1 icon@x2.png
  Item 2 icon-72.png

It was working fine before… I added following item.

CFBundleIconFile~ipad icon-72.png
Categories: iPhone/iPod Touch, Programming Tags:

MIDP problems on Nokia E7-00

March 5th, 2011 No comments

I have experienced some problems on MIDP environment of Nokia E7-00 when I use QWERTY keyboard of E7-00.

1) I can not capture key code of ‘Enter’ key.

I can not get key code of  the ‘Enter’ key by keyPressed(int) or keyReleased(int) methods. When I pressed the ‘Enter’ key at Canvas screen, menu items which is assigned to left softkey is popped up.

2) Numeric/special character shift button also generate key code of shift button.

When numeric/special character shift button (at most left down corner) is pressed, key code -50 is returned, it is same to normal shift key. If the MIDP application controls own shift mode, this behavior makes confusion.

3) Control code does not appear sometimes.

For example, Ctrl+c (press control key and ‘a’ key at a time) generates key code of ‘C’ (0×43) sometimes. It is depending on shift mode of the device. When device’s shift mode is in lower case, Ctrl+c generate correct control code 0×03.

Nokia E90, it does not have device’s shift mode. ‘C’ key always generates key code 0×63 and Ctrl+c always generate key code 0×03.

ps. I will report this to Forum Nokia later…

Categories: Nokia, Programming Tags:

Navigation keys on MIDP of Nokia E7-00

March 4th, 2011 No comments

If your MIDP program is using getKeyCode method of Canvas class to retrieve key codes for game action keys, cursor keys (at right lower corner of full keyboard) will not be worked on Nokia E7-00 MIDP environment.

getKeyCode will return key codes of ‘a’, ‘w’, ‘s’ and ‘d’ as ‘LEFT’, ‘UP’, ‘DOWN’ and ‘RIGHT’ keys. For example, getKeyCode(LEFT) will return 0×61.

If you want to use cursor keys, you need to hardcode for each keys. Key code of cursor keys: UP is -1, DOWN is -2, LEFT is -3 and RIGHT is -4.

Categories: Programming Tags:

iPhone/iPad Universal Binary Sample Code

August 21st, 2010 5 comments

Let me provide my template project of universal binary for iPhone and iPad here. This is very simple project, you may be able to read easily. My code would not be 100% correct, but mostly okay to understand how organize universal application, I believe.

[ Rights ]

This is so simple codes, I do not assert copyright. I provide this code without guarantees If you use this code, please take your own risk.

[ Abstract of the project ]

- When the program runs on the iPhone, table view will be showed at beginning. Then tap the item to show content.

- When the program runs on the iPad, split view will be displayed to show both table items and content.

[ Summary ]

This project was created on Xcode 3.2.3 SDK 4.0.1.

Brief steps to build this project as follows.

  • Created iPhone application
    • Created Navigation-based Application
    • Created class and nib file as ‘DetailedViewController’.
    • Created data model class ‘MyEngine’. ‘MyEngine’ is owned by RootViewController.
  • Converted to universal binary
    • Selected target and performed ‘Upgrade current target for iPad’ with ‘One universal application’ option
    • Removed UINavigationController property in UniTest2AppDelegate class and add UIViewController property. Reconnected it from MainWindow.xib
    • Created DetailViewController-iPad class and nib with ‘Targeted for iPad’ option. Note: Class name would become ‘DetailViewController_iPad’ automatically
    • Created RootViewController-iPad class files as sub-class of TableViewController. (class name became RootViewController_iPad)
    • Created MainWindow-iPad.xib and added Split View Controller
Categories: iPhone/iPod Touch, Programming Tags:

Invalid application-identifier Entitlement

July 9th, 2010 No comments

I got a Invalid application-identifier Entitlement error from iTunes Store after upgrading iOS4.

In my case, I just erased ‘Entitlement.plist’ from my project. I created ‘Entitlement.plist’ when I tested this application in AdHoc environment. I do not use AdHoc right now, so I just erased it.

Categories: iPhone/iPod Touch, Programming Tags:

How to convert your MIDP application for the BlackBerry

April 25th, 2010 No comments

If you have MIDP application’s jar file and jad file, they can be converted to BlackBerry installable file (.cod).

  • Install appropriate JDE from http://java.sun.com/.
  • Install BlackBerry JDE Component Package from BlackBerry Java Development Environment page.
  • Setup PATH environment to ‘bin’ sub-directory of JDE installation folder.

Run following command on Windows command prompt to create ‘cod’ file.

rapc import=%JDE%\lib\net_rim_api.jar codename=midp_appli -midlet jad=midp_appli.jad midp_appli.jar

Please replace %JDE% with JDE installation folder or move net_rim_api.jar to current folder.

You also need to create ‘alx’ file. Sample alx file contents as follow.

<loader version="1.0">
<application id="midp_appli">
<name>midp_appli</name>
<description>midp_appli</description>
<version>1.0</version>
<vendor>Pigtail Software</vendor>
<copyright>Copyright (C) 2010 by Pigtail Software</copyright>
<fileset Java="1.0">
<files>KKJConv.cod</files>
</fileset>
</application>
</loader>
Categories: BlackBerry, Programming Tags: