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…
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.
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
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>
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 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).
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
Posted by jason on Feb 19, 2010 in
Uncategorized
Just found a cool form tool I’m going to try out for Rails:
http://github.com/justinfrench/formtastic
He built the output to be based on a presentation given by Aaron Gustafson
http://github.com/justinfrench/formtastic
I’ve been doing web development for a LONG time so it’s easy to fall into the trap of thinking I know everything there is to know about something as basic as forms. I’ve learned some really good stuff by Aaron Gustafson’s presentation that I’m going to immediately incorporate into my applications.
Posted by jason on Feb 13, 2010 in
Uncategorized
I discovered a few interesting things while preparing for my quarterly taxes. I don’t have to pay them until April 15th. Also, I don’t base it on the total taxes I will owe. I only have to pre pay 1/4 of last year’s total federal tax. So I can ignore the medicare and social security if I want to owe a ton of money at the end of the year. I think what I’ll actually do is save the difference between what I will owe and what I have to pre pay into a savings account. That way at the end of the year, I won’t have to scramble to pay a huge tax bill.
What I can tell so far, there are four major financial differences between being an employee and being a self employed individual. These four are health care, retirement, taxes (social security/medicare), and time. I’m speaking from the perspective of someone who bills by the hour.
Health care is really dependent upon what your employer provides. I can get similar coverage to my old job for roughly the same as what my former employer was providing. I wasn’t getting fantastic health coverage before though. Some of the plans with low deductibles are quite expensive to get on your own. I’m settling on a plan with a $10,000 family max out of pocket plan for around $350/mo for my family of five through Blue Cross. On the plus side, it is an HSA. So I can contribute to this account tax free money. If I don’t use it on health care, it stays in the account.
Retirement is interesting. As an employee, you are limited to a maximum contribution of $16,500. With a SEP, the max you can contribute is 20% of business income up to $45,000. With a solo-401k, you can contribute more than 20% but still with a limit of $45,000. I wouldn’t reach these maximum contributions in either case, but it is a nice benefit if you are earning lots of money.
A third area is taxes. I knew that the employer paid the other half of the employment tax. I never really thought about the implications of it. I didn’t see the actual dollar amount, and it was never reported on any of my W2s. Employees pay this tax in the form of reduced wages so it is a hidden tax. Employees only see 7.65% taken out for social security and medicare. Self-Employed individuals pay 15.3%. In order to compare your wages as an employee vs your income as a self employed individual, you need to make adjustments. What this means practically is that you either need to work an extra 3 hours per a 40/hr week at the same pay rate as an employee, or you need to increase your rate by $0.83 for every $10 you were getting paid as an employee.
The fourth area is time. As a self employed individual, time does indeed equal money. If I’m not working, I’m not getting paid. What this means practically is that holidays have a different feel to me. I am not able to work or bill during a holiday. It also means that when I take vacations, I am not getting paid. It means that if a client doesn’t need me for any reason, I’m not getting paid. If I’m actively seeking out new contracts, I’m not getting paid for this time. You need to factor in this down time into your bill rate otherwise, you will find yourself making a lot less than you were previously. The upside to this time factor is that if you are a hard worker, you can work a lot more than 40/hrs a week and can increase your income that way.
The biggest change for me in being self employed is that I love what I do. I get to work on different and interesting projects. This is strange, but I no longer am sad it’s monday or happy it’s friday. This really doesn’t have anything to do with working for myself. It is entirely dependent on liking what I do. I am pretty sure I could be just as happy working as an employee if the work was interesting. I am getting to work on the Blackberry, the iPhone, Windows Mobile. I am using Java and C#. The Blackberry project is especially fulfilling. Because of the Blackberry, the sales team are getting many more opportunities to sell. I will have directly contributed to increasing the revenue of this company. I love it!
Posted by jason on Feb 13, 2010 in
iPhone
The iPhone has some really cool features for web apps.
One feature that I particularly like is called Web Clips. These are pages that can be installed on your home screen. You can specify an icon for use on the home page just like you would for a native app. If you don’t supply one, then it uses a screen capture of your page. You can also supply a splash screen png that will display while your web page is loading. You can hide the address bar to make it look even more like a native app. There is one small gotcha with this though. If you click on any link inside your webpage, it will open up Safari and close your nice page. The trick then is to make the entire application a one page app. You accomplish this through the use of AJAX.
Another feature that is very cool is new to HTML 5. You can specify a cache manifest file that tells the iPhone which files to cache locally. The cool thing about this is that if you have an application that is static, you can run the app while the iPhone is in airplane mode. This is very cool. You can even specify fallback files that are used when the app is offline. When I tested this out, the application was VERY snappy. Currently only Firefox 3 and Safari 4 support this.
A final feature that I have not explored very much is client side storage. This is also a new HTML 5 feature. All the newest browsers except Chrome support this feature. This is a necessary feature if you want to have some sort of database driven offline capable application for the mobile device.
Posted by jason on Feb 12, 2010 in
Mac,
Ruby
I ran across these very handy commands to simulate a connection of only 4kbps. This is helpful when developing mobile applications in particular because some cell connections are horrible.
sudo ipfw pipe 1 config bw 4KByte/s
sudo ipfw add 100 pipe 1 tcp from any to me 3000
There are several interesting parts to these commands.
The 4KByte/s which can be whatever speed you want. This is the bandwidth, measured in [K|M]{bit/s|Byte/s}.
The other interesting part is 3000. This is the port that will be slowed. Port 3000 is the default port on which Ruby on Rails listens. If you are doing Java, you would probably want to use 8080.
The 100 is the rule number. Useful when it comes time to delete this rule.
To clear out this pipe, simply type the following when finished:
sudo ipfw delete 100
To clear all custom rules, you could type:
sudo ipfw flush
Posted by jason on Feb 5, 2010 in
Windows Mobile
I ran into Smart Phone not supporting another control. It doesn’t support button controls. The Smart Phone has a menu at the bottom that behaves as a button.
I seem to have troubles finding this article when I need it, so here is a link to help me figure out the user interface options I have for the SmartPhone:
http://msdn.microsoft.com/en-us/library/aa446513.aspx#smartphoneuserinterface_topic3