0

Homebrew

Posted by jason on Jul 30, 2010 in Uncategorized

I am currently trying out a new package management system called Homebrew.  I am not really sure how it’s any better than MacPorts yet.  I think the only thing I know is that you aren’t forced to download multiple versions of a package if you don’t need to.

http://mxcl.github.com/homebrew/

 
0

Ruby on Rails Plugins

Posted by jason on Jul 30, 2010 in Ruby

Not sure if this is worth doing or not since these ruby plugins change so frequently, but here are a list of plugins that I find interesting as a java guy coming up to speed in ruby on rails.

Referential Integrity

script/plugin install http://svn.hasmanythrough.com/public/plugins/validates_existence/

From “Learning Rails” by O’Reilly.  Page 149

Scaffolding

ActiveScaffold.com

Geo Coding

http://geokit.rubyforge.org/

Image Processing

attachment_fu

ImageScience

http://seattlerb.rubyforge.org/ImageScience.html

 
0

Background Applications on the BlackBerry

Posted by jason on Jul 30, 2010 in BlackBerry, Mobile Devices

Useful articles about background applications on the blackberry.

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/796557/800738/800901/How_To_-_Setup_an_alternate_entry_point_for_my_application.html?nodeid=800820

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800639/How_to_-_Make_a_running_UI_application_go_to_the_background_and_resume_in_the_foreground.html?nodeid=800545&vernum=0

http://docs.blackberry.com/en/developers/deliverables/6625/Dimensions_for_screens_images_and_icons_476251_11.jsp

http://rim.lithium.com/rim/board/message?board.id=java_dev&message.id=2519

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=392

 
0

Blackberry JME has very limited threads

Posted by jason on Jul 30, 2010 in BlackBerry, Mobile Devices

I had written a CRON scheduler for the blackberry for one of my clients.  This CRON scheduler was failing seemingly randomly where the thread that checks the schedules would just die.  In order to make sure a task is launched exactly when it should, I would spin off a thread and execute that code.  You can see where this is going right?  It worked just fine under my development tests.  When it went to QA, it would fail.  After tracing it down, it was failing on the line:

thread.start();

After finding the exact line of code where it was crashing, I surrounded this line of code with a try/catch on Throwable with this code:

System.out.println(“Error: ” + exc.getClass().toString() + ” = ” + exc.getMessage());

The output from this was:

Error: class net.rim.vm.TooManyThreadsError = null

Which of course led me to my problem.  Now there is no mention of a limitation in the Blackberry documentation telling me how many threads I can have.  In hind sight, I should have know given that even in desktop apps you should use threads sparingly.  These threads I created were supposed to be very short lived.  They spin up, do their action and then go away.  In my testing that’s exactly what was happening but I wasn’t stressing the system with lots of tasks.  Consequently under real-world use, trying to start that last thread was killing the thread that created it.

I can’t simply use the ThreadPool class provided in java.util.concurrent because that is not available in J2ME/JME.  I just created my own based on an article written by IBM about Thread pools and work queues.  I had to use Vector instead of a linked list (didn’t feel like writing my own but I should because removing an element from a vector is expensive and I have to do it every time I pop an element out).  Worked like a champ!

 
0

iPhone web caching sqlite3

Posted by jason on Mar 15, 2010 in iPhone

If you are using the iPhone simulator to test your web application, you can query sqlite3 cache tables by going to the following directory:

~/Library/Application Support/iPhone Simulator/User/Library/Caches/com.apple.WebAppCache

Command to open the cache database:

sqlite3 ApplicationCache.db

Once inside, you can use the following command to view the tables:

sqlite> .tables

This is very helpful in troubleshooting caching issues.

 
0

UPDATE: Windows Mobile 6 Smart Phone Signed Cab displaying “Program is from an unknown publisher”

Posted by jason on Mar 2, 2010 in Windows Mobile

Previously, I wrote about signing cab files for Windows Mobile 6.  The application was initially created for Windows Mobile 5 Pocket PC devices.  We got it working on Windows Mobile 6 Pocket PC.

Recently, I was tasked with creating an installer application to get around some of the browser inconsistencies they’ve been experiencing with the various Smart Phones.  They have an installer app that has an executable and an XML file that the executable reads for it’s configuration.  Pocket PC allows you to download the XML file and the executable file and everything just worked.  The Smart Phones do not behave this way.  I created an app that downloads both the EXE and the XML file to the My Documents directory and launches the EXE.  Works great.

My problems started when I tried to cab up the whole thing and install it from a mobile device.  I signed each file inside the cab as well as the cab itself.  I kept getting prompted by the device asking me if I want to trust this unknown publisher?  At first, I thought maybe I had screwed up the signing.  Turns out that no, I did sign it correctly… for windows clients.  The Windows Mobile platform uses a different technology than Authenticode.

On this MSDN article about how to Sign your Windows Mobile Application, it states very clearly: ”Authenticode signatures for other Windows platforms, such as Windows Client or Windows Server, use a different technology than Windows Mobile code signing and are not recognized as valid normal or privileged mode signatures.”  What I don’t yet understand is that it states Windows Mobile (not Smart Phone) uses a different technology, yet we used Authenticode to make the prompts go away for the Pocket PCs we were testing on (Windows Mobile 5 and 6).

The Windows Mobile code signing seems very expensive.  From what I can tell it costs $350 for 10 signings.  There is an additional fee for each signing after that.  What this means is that you better be darn sure your application is finished before signing your application.  I’ve read that you have to submit your signed cab to Verisign who then signs your cab file with their certificate.  I am beginning to hate the Windows Mobile platform and might actively root for their demise…

 
0

Taking screen shots with Mac OSX

Posted by jason on Feb 25, 2010 in Mac

I seem to always forget these short cuts even though i use them frequently. With windows, it is simply “print screen” button to capture the desktop and alt-”print screen” to capture the active window.  This puts the image in the clip board.

The apple commands for capturing the screen aren’t as intuitive as the Windows version.

To capture the desktop, Command-Shift-3

To capture a portion of the screen, Command-Shift-4.

To capture a specific windows, Command-Shift-4 followed by space bar.

The Mac version will create PNG files on the desktop with these commands.  If you hold down the control key while pressing these combinations, it will put the image in the clipboard.

 
0

MacPorts mysql with GUI tools

Posted by jason on Feb 25, 2010 in MySQL

A friend had some problems installing MySql with MacPorts and asked me if I had problems installing it.  Our problems were totally unrelated but thinking back, I remembered I had problem with MySQL Query Browser.  I couldn’t get it to connect even though I could connect via the command line.  It turned out to just have the wrong path for the socket file.

Click the triangle next to the “More Options” label on the connection string an change the “Connect Using Socket” field to the path of your socket file.

To determine where your socket file is, type:

netstat -ln | grep mysql

 
0

HTML Dom in Ruby with Nokogiri

Posted by jason on Feb 24, 2010 in Ruby

I recently needed to do a screen scrape of a website.  The page I’m trying to parse is marked as an “XHTML 1.0 Transitional”.  XHTML?  Should be easy.  Parse the doc, use XPath and I’ll be done.

If you search “xml parser ruby”, the first result you will get is REXML.   I’ve read comparisons that point out that libxml is several of orders of magnitude faster.  My first attempt used REXML.  I failed miserably in this attempt because the web page I was parsing was not actually valid XHTML.  After I learned it was broken, I ran it through W3C’s validation service and discovered the site had over 100 errors.  XML Parsing is out.

That led me to a search for HTML Dom ruby which led me to hpricot.  I actually didn’t even try this parser because Andrew Kavanaugh pointed me to Nokogiri.  Nokogiri is interesting because it provides two different ways to find the elements you are interested in.  It lets you find an element using XPath or CSS selectors.  Lately, I’ve been doing a lot of CSS selectors so I went that route.  The document I was searching through had something like the following HTML:

...
<div class="section">
<h4>Section 1</h4>
<p>
  <sup class="requirement">1</sup>Requirement 1 descriptive sentence.
  <sup class="requirement">2</sup>Requirement 2 descriptive sentence.
  <sup class="footnote"><a href="#footnote1">footnote 1</a></sup>
    &nbsp;&nbsp;&nbsp;
    More descriptive text.
  <sup class="requirement">3</sup>Requirement 3 descriptive sentence.</div>
</p>
</div>

I needed to translate this into a format I could insert into my database.  I don’t care about footnotes, or spacing or anything other than the raw text.  I need it to look something like:

Section 1.1, Requirement 1 descriptive sentence.
Section 1.2, Requirement 2 descriptive sentence. More descriptive text.
Section 1.3, Requirement 3 descriptive sentence.

I used the following code to get the section number I was after:

@section = doc.at('div.section h4').inner_html

I then used the following code to get the subsection number and the text associated with it:

doc.css('div.section sup.requirement').each do |element|
  # Get the requirement subsection number
  @requirement = element.to_s.strip

  # Since we are interested in all the text between each of the subs
  # We need to get every text node until we run into the start of the next
  # sub class='requirement' node
  @node = element.next
  @text = ""
  while @node != nil && (@node['class'] != 'requirement') do
    if (@node.text?) then
      @text = @text + " " + @node.to_s.strip
    end
    @text = @text.strip
    @node = @node.next
  end
  puts  @section + "." + num.inner_html + ", " + @text
end

Man I love these “whatever.each do |element|” style blocks.  Very powerful.  When I ran this for the first time, I encountered an oddity I didn’t quite understand.  Even though I was calling strip to eliminate the white space, I was getting a row that looked like:

Section 1.2, Requirement 2 descriptive sentence.    More descriptive text.

It turns out that when calling to_s on a node, it converts &nbsp; into something that is whitespace but not stripped out by the normal strip function.  I modified the strip function of the String class and all worked well.

class String
  alias_method :strip_old, :strip
  def strip
    self.gsub(/^[\302\240|\s]*|[\302\240|\s]*$/, '')
  end

  def strip!
    before = self.reverse.reverse
    self.gsub!(/^[\302\240|\s]*|[\302\240|\s]*$/, '')
    before == self ? nil : self
  end
end

In the past, this would have been something I’d have just thrown together in Java.  If I ever need to do something like this again in Java, I’m going to try out this HTML parser called Cobra.  It even handles javascript calls in the page (like document.write).

 
0

RVM (Ruby Version Manager)

Posted by jason on Feb 20, 2010 in Uncategorized

Motivation

The Rails 2.x has felt… hacky to me.  When I’ve looked at some of the code that has been generated, I’ve been turned off by the inline javascript I’ve seen.  I want the code that my framework creates to be extremely clean and standards oriented.  Inline javascript just doesn’t cut it for me.  Another thing that has bugged me is the disregard for other points of view.  In “Agile Web Development with Rails” book I read, the authors decided to denigrate the importance of having a very clean ORM layer because Rails didn’t have it.  It has felt that the Rails core team didn’t really care about correctness, they seemed hacky.  The merb team seemed to care about correctness in implementation which is why they were creating a lightweight, flexible foundation.  Because of this, Rails 3.0 excites me.

I’ve decided to do all my Rails development using 3.0.  I have no plans on releasing my software any time soon, and I really want to use the new bundler and the new routing features.  In order to do this, I want to be able to run multiple versions of Ruby on my machine.  My good friend Andrew Kavanaugh pointed me to RVM (Ruby Version Manager).

RVM Installation

I had no trouble following the directions to install RVM.  It installed without errors.  I encountered an error when I went to install a different Ruby version.  Inside the configure.error.log file, I had this line: “configure: error: C compiler cannot create executables”  Inside the configure.log file, I had “checking whether the C compiler works… no.”   When I upgraded to Snow Leopard, I didn’t upgrade my dev tools.  Once I installed Xcode 3.2.1, I had no problems installing my ruby versions.

RVM Usage

Install a new version of Ruby:

rvm install 1.9.2

List installed versions of Ruby:

rvm list

Change version of Ruby

rvm 1.9.2
rvm system

Change default

rvm 1.9.1 --default
rvm system --default

Copyright © 2010 programming with passion All rights reserved. Theme by Laptop Geek.