Wink Saville’s Blog

February 24, 2008

Ajax – responses must have Content-Length

Filed under: Ajax, firefox — wink @ 2:30 pm

When responding to an AJAX request, actually when responding to any HTTP/1.1 request that is going to be kept alive you need to have a Content-Length header field even if the the content length is 0.

February 23, 2008

Java – sources in jar’s

Filed under: java — wink @ 7:33 pm

While debugging Ajax support for AMC I learned that to debug class files that java libraries (aka. jar files) all you need to do is include the java files in the jar files.

February 22, 2008

Firefox/Apache – debug server side php code

Filed under: Apache, firefox — wink @ 11:10 am

To apache debug server-side scripts the typical solution is to usr print statements back to the browser. But that won’t work for AJAX as there isn’t any place to view the output.

The other method is to log to a file

$fp = fopen(’debug.php’, ‘ab’);
fwrite($fp, “debug data …”);
// Then eventually close
fclose($fp);

Filed under: firefox — wink @ 11:03 am

Debugging Firefox:

*) DOM Inspector:

By default on Ubuntu the firefox DOM inspector isn’t enabled and when reading “Programmin Firefox” it is one of the recommended tools

But it isn’t enabled by default, apparently this is the case for Windows also where you need to do a custom install to get it. For Ubuntu I installed it via synaptic as firefox-dom-inspector I also added firefox-dbg and firefox-dev. Interesting, it wasn’t available right away and I needed to reboot the system, although there may be other ways.

*) Java script parsing bugs

At the moment, 20070602, I don’t see parsing errors for java script files I create?

*) Java script runtime debugging:

Method one: run FF from the command line with the -console option: wink@ic2d1:~$ firefox -console & and then use “dump” commands to print strings to the console.

Method two: use Venkman debugger. Again, wasn’t available by default, I used Toos->Add-on and navigated to “Web and developer tools” and searched for debugger, the Venkman debugger was the first choice. Seleting this and the “Install Now” button installed it.

*) Venkman debugger:

To get Venkman to debug my overlay I had to enable browser files: Goto menu item “Debug/Exclude Browser Files” and be sure it is not checked. The list of files will then expand and my script “sl.js” was visible. A break point could then be set.

Firefox – Adding preferences

Filed under: firefox — wink @ 10:54 am

Adding preferences isn’t too hard. I followed the instructions here. I had several problems of my own making plus one in the example code. The example code problem was:

var gMyPrefs = new PrefsWrapper(”extensions.myextension.”);

PrefsWrapper needed a number “1″ appended:

var gMyPrefs = new PrefsWrapper1(”extensions.myextension.”);

The other minor problem was “myextension” and “yourextension” needs to be “sparkrocket”.

The problems of my own making were a miss-understanding of javascript. At first I added the example code at the global scope but nothing would happen. After a little while of adding debug I figured out I needed to not have the example code at the global scope, but it needed to be in sr_initialize. I could then execute the code from prefsutils.js.

Also, the prompt service described here is similar but different from “prompt()” builtin function which also prompts for input but I couldn’t find the docs for it so I used the prompt service.

Finally, after adding the setUnicharPref I couldn’t unset it, at first I thought it would replace the defaults/preferences/extensions.js value for user.name. But no, that is just the default, the value is actually stored in ~/.mozilla/firefox/fbgu8siq.default/prefs.js and can be modified by going to the url “about:config”.

Firefox – building an extension

Filed under: firefox — wink @ 10:34 am

Here’s an update to this post 7/6/2008:

Use this link from firefox and in particular Setup the Development Environment.

—-

I used this link as a model for creating an extension which put a button on FF’s address bar: Building an extension

I more or less followed those instructions: Firefox user interface is written as a .xul file, pronounced “zool”. As explained in Building an extension in the “Chrome URI’s” section you can even execute the browser ui in the browser. Place “chrome://browser/content/browser.xul” in the browser address bar.

To add a new user interface element you create an overlay and basicly dynamically modify the browser.xul file. An overlay is an .xul file which defines a location where the new interface element is to be located and then what it is to do. Finding the location to insert isn’t difficult, the main UI document on my Ubuntu system it is located at at /usr/share/firefox/chrome/browser/content/browser/browser.xul

In the example they modified the status line which is can be found in browser.xul by searching for “statusbar”. Since I wanted to modify the address url I looked around and found that there is a texbox with the id=”urlbar”. So the prgs/fx/sl/chrome/content/sample.xul file contains the following:

<textbox id=”urlbar”>
<button insertafter=”page-proxy-dec” id=”my-button” label=”sl”
oncommand=”alert(’You pressed me!’); return false;”/>
</texbox>

Which adds a button with the label “sl” to the address bar and when pressed displays an allert with “You pressed me!”. So the following steps will get you the same thing:

1) Created my “extension” in ~/prgs/fx/sl which have the following 3 files:

chrome.manifest
install.rdf
chrome/content/sl.xul

2) The content of the files are:

wink@ic2d1:~/prgs/fx/sl$ cat chrome.manifest
content sl chrome/content/
overlay chrome://browser/content/browser.xul chrome://sl/content/sl.xul

 

wink@ic2d1:~/prgs/fx/sl$ cat install.rdf
<?xml version=”1.0″?>
<RDF xmlns=”http://www.w3.org/1999/02/22-rdf-syntax-ns#”
xmlns:em=”http://www.mozilla.org/2004/em-rdf#”>

<Description about=”urn:mozilla:install-manifest”>
<em:id>sl@saville.com</em:id>
<em:version>1.0</em:version>
<em:type>2</em:type>

<!– Target Application this extension can install into,
with minimum and maximum supported versions. –>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.5</em:minVersion>
<em:maxVersion>2.0.0.*</em:maxVersion>
</Description>
</em:targetApplication>

<!– Front End MetaData –>
<em:name>sl</em:name>
<em:description>Shared link<em:description>
<em:creator>Wink Saville</em:creator>
<em:homepageURL>http://www.saville.com/</em:homepageURL>
</Description>
</RDF>

wink@ic2d1:~/prgs/fx/sl$ cat chrome/content/sl.xul
<?xml version=”1.0″?>
<overlay id=”sample”
xmlns=”http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul”>
<textbox id=”urlbar”>
<button id=”my-button” label=”sl”
oncommand=”alert(’You pressed me!’); return false;”/>
</texbox>
</overlay>

3) To install the extension added sample@foo.net to the extensions directory:

wink@ic2d1:~/prgs/fx/sl$ cat ~/.mozilla/firefox/fbgu8siq.default/extensions/sl@saville.com
/home/wink/prgs/fx/sl

 

This is just the path to my extension

 

4) To actually get the url of the current page, this looks like the definitive source. and it says the best is window.content.location.href. I also tried document.getElementById(’urlbar’).value which also looks to have worked.

February 17, 2008

git – applying patches

Filed under: linux, scm — wink @ 3:49 pm

Today learned some things about git and applying patches. First when applying my trec/ace/kshmem patches to 2.6.25-rc2 they wouldn’t apply because now there only an x86 architecture (arch/x86) instead of two architectures i386 and x86_64. That was to be expected actually and there’s going to be some hand work in doing that.

To do this hand work I really need to see what my current patches look like and there isn’t quite enough context in the patch file to do that, at least for me. So I cloned the current linux-2.6 tree into a new directory linux-2.6-x and did a checkout of 2.6.21-rc6 which is what my patches should apply against.

Well almost, there was still some need for a little tweaking; First git am will take my series of patches which were generated using git format-patch and apply them extracting from the email the commit message and the patch. It then creates a commit. But if there is a problem in a series only those that applied cleanly will be committed.

The first patch that fails won’t be applied at all, for example:

error: patch failed: mm/vmalloc.c:469
error: mm/vmalloc.c: patch does not apply
Patch failed at 0002.
When you have resolved this problem run "git-am --resolved".
If you would prefer to skip this patch, instead run "git-am --skip".

At this point I was scratching my head Patch failed at 0002 and when its resolved I can say so, but how to resolve it if its not been applied to the working tree. The solution is to use “git apply”:

git apply --reject --whitespace=fix my-patches/ace2-2.6.21-rc6/0002.patch

By using “git apply” with the –reject it will apply the patch leaving bad files with “xxx.rej” in my case mm/Kconfig.rej was the culprit. I resolved the problem with mm/Kconfig. Next I tried “git am –resolved”:

wink@ic2d1:$ git am --resolved
Applying ACE implementation, conifguration and makefile
No changes - did you forget to use 'git add'?
When you have resolved this problem run "git-am --resolved".
If you would prefer to skip this patch, instead run "git-am --skip"

More head scratching, “did you forget to use ‘git add’?” …. hm Ok so I then used “git gui” to add the files (BUT DID NOT DO A COMMIT) and then did “git am –resolved”:

wink@ic2d1:$ git am --resolved
Applying ACE implementation, conifguration and makefile
Applying ACE modifications to actually use ACE
.dotest/patch:32: trailing whitespace.
warning: 1 line adds whitespace errors.
Applying ACE simple test program
.dotest/patch:130: space before tab in indent.
result ? "true" : "false", i);
.dotest/patch:138: space before tab in indent.
result ? "true" : "false", i);
.dotest/patch:146: space before tab in indent.
result ? "true" : "false", i);
.dotest/patch:233: trailing whitespace.
warning: 4 lines add whitespace errors.

That did it, so no commit was necessary, the “git am –resolved” did the commit and then continued with the other patches. Lean something new everyday!

February 12, 2008

Eclipse – ant and build.xml

Filed under: Android, Ant, Eclipse, java — wink @ 1:31 pm

This week I converted async-msgcomp to use ant for building rather than the internal Eclipse builders because it was the only way I could figure out to get jar files automatically built. After some trial an error I came up with common-build.xml which are common tasks for all sub-project and resides at the root of my build tree. I also created android-build.xml which is in the android sub-directory and is the common Ant tasks for Android. Then within each sub-project is a build.xml, for instance java/debug/build.xml and android/debug/build.xml as well as a global build.xml file in my root. For full disclosure; common-build.xml was based on the build.xml file emitted by:

File -> Export -> General -> Ant Buildfiles

And android-build.xml is based on the build.xml file emitted by running:

android-sdk/tools/activityCreator.py

The build.xml files are then used by executing ant in the appropriate sub directory. By executing ant in the root all of the sub-projects are built. Eclipse is also capable of building using Ant but you have setup the properties for each sub-project, which I’ll try to outline below. Sometimes Eclipse has trouble and either won’t execute saying they are still errors or it won’t execute because the classpath isn’t set properly.

One solution that has helped is to delete all projects and re-import them. Two other important items is that the Run parameters must be setup properly in <Run/Open Run Dialog> must be set properly and Build parameters for must be good.

Anyway, here is an example of setting the project properties so that external Ant files are used for compiling, in the example below I’m setup the sub-project “debug”. We assume there is a build.xml file in the sub-project.

Project -> Properties -> Builders -> new:

Main.Name: = debug-build.xml
Main.Buildfile: = Browse Worksapce => debug/build.xml
Main.Base Directory: = Browse Workspace => debug
Targets.After a “Clean”: = <default target selected>
Targets.Manual Build: = <default target selected>
Targets.Auto Build: = <default target selected>
Targets.During a “Clean”: = clean

Project -> Properties -> Builders = select only debug-build.xml deselect all others
Project -> Propertiers -> java Build Path -> Libraries = Add appropriate Libraries
Project -> Propertiers -> java Build Path -> Order and Export = the Libraries
Project -> Propertiers -> Project References -> Project references for debug: = select appropriate projects

In the Project -> Properties -> Builders where we select only debug-build.xml and deselect all others includes the following if it is an Android sub-project:

Android Resource Manager
Android Pre Compiler
Java Builder
Android Package Builder

If it is “pure java” project than you just deselect Java Builder.

February 11, 2008

Android – Eclipse “Could not find xxxx.apk”

Filed under: Android, Eclipse — wink @ 10:45 am

Today started off poorly, I decided to create ews (eclipse workspace) directory and then put the workspaces in that sub-directory. I started with an empty workspace as I have my sources separate from the workspace and then added in debug. I was able to compile fine but when I tried to run the android application I got:

[2008-02-11 10:36:03 - mc-android] Android Launch!
[2008-02-11 10:36:03 - mc-android] Could not find /bin/mc-android.apk!

Of course there was an mc-android.apk but it’s not in “/bin” (off the root) its at “bin” relative to the sub-project. Anyway, the solution appears to be to remove the project and import it again.

February 3, 2008

git-svn: A workflow

Filed under: Uncategorized — wink @ 1:09 pm

I’ve open sourced some code of mine at googlecode.com, http://async-msgcomp.googlecode.com which uses subversion, but at home I’m using git. Turns out that git supports a bi-directional mechanism for working locally in git but easily using svn as a remote repository.

In my workflow I also have a local server with remote git repository and I’d like to keep all three in sync. My basic workflow is to have the master branch in my local repo represent the trunk of the svn repository. Then make a local git branch for work-in-progress (WIP) and when satisfied all is well I merge the changes from my local branch to master and then dcommit to the svn repo. Furthermore, I will periodically push my local repo to local server as a backup. This means my code is on two computers at home plus at a remote site in svn. Thus I feel very secure as the code is in 3 places.

Assuming we start with a svn repo the workflow is:

*) Clone svn repo to a git working repo named amc, the -s means this is a standard trunk/brances/tags svn repo

lcl~/$: git svn clone -s https://async-msgcomp.googlecode.com/svn amc

*) Create a remote repo named amc.git on srv.

lcl ~/ $ cd amc
lcl ~/amc $: ssh wink@srv
srv ~/ $ cd <path-to-git-repos>
srv ~/git.repos $ mkdir amc.git
srv ~/git.repos $ cd amc.git
srv ~/git.repos/amc.git $ git – - bare init – - shared
srv ~/git.repos/amc.git $ exit
lcl ~/amc $

*) Connect the working repo to srv and push the contents assume we’re in amc

lcl ~/amc $ git remote add origin git://srv/amc.git
lcl ~/amc $ git push – - all

*) Create branch.master.remote and branch.master.merge configuration so git pull defaults to fetching from remote origin and merging with lcl maste

lcl ~/amc $ git config branch.master.remote origin
lcl ~/amc $ git config branch.master.merge refs/heads/master

We now have data on 3 different computers. The general workflow now is to make changes to the code in a branch on lcl, do a git svn rebase, merge changes from lcl branch as into lcl master then do a git svn dcommit to push the changes to svn and git push –all to push changes to srv. Here is an example:

lcl ~/amc $ git checkout -b test1 master
lcl ~/amc $ <edit/compile/test>
lcl ~/amc $ git commit -a
lcl ~/amc $ <repeat edit/compile/test/commits>
lcl ~/amc $ git push

So we created a new branch did some edit/compile/test/commit iterations with some git pushes to srv as desired. Now we’re ready to push the changes to svn. So we checkout master, rebase to get any changes from svn locally then merge test1 and dcommit.

lcl ~/amc $ git checkout master
lcl ~/amc $ git svn rebase
lcl ~/amc $ git merge test1
lcl ~/amc $ <resolve conflicts and test>
lcl ~/amc $ git svn dcommit
lcl ~/amc $ git push – - all

At this point all three repos are synchronized.

Now assume you lost your lcl repo amc. You can partially recover by checking out the srv repo amc.git but the lcl repo won’t be “connected” to svn. To reconnect we need to manipulate amc/.git/config and update .git/remotes. This information comes curtusey of Steve Walter answering a question I had on git-svn segfaulting and is here but with some modifications because I’ve cloned with -s. So the following will reconnect:

lcl ~/ $ git clone git://srv/amc.git amc
lcl ~/ $ cd amc
lcl ~/amc $ git svn init -s http://async-msgcomp.googlecode.com/svn
lcl ~/amc $ rm -rf .git/svn
lcl ~/amc $ cp .git/refs/remotes/origin/master .git/refs/remotes/trunk
lcl ~/amc $ git svn fetch
Migrating from a git-svn v1 layout…
Data from a previous version of git-svn exists, but
.git/svn
(required for this version (1.5.3.8) of git-svn) does not. exist
Done migrating from a git-svn v1 layout
Rebuilding .git/svn/trunk/.rev_db.35bfc53a-2d43-0410-a069-7fc8ebf1512b …
r52 = 2336c1c70e92d572f5a1b248249b4f857142bc51
r51 = 8ce31b64294bdb063c64c50b9358533ac8746af4

r2 = 2638419edfbf545d79437650b0772bdd4905035b
r1 = c33b6e02fc70b0792069099e49112cb1b6cf94c4
Done rebuilding .git/svn/trunk/.rev_db.35bfc53a-2d43-0410-a069-7fc8ebf1512b
lcl ~/amc $

Now amc is reconnected to svn and srv and you’ve recovered. Steve points out that its possible to also recover the svn repo from the git repo but neither he nor I have tried.

Powered by WordPress