Apr 272013
 

Since 2009 I have sold my photography and designs on my Zazzle store. Recently, I decided to rebrand the store and somewhat integrate it with my blog. If you are interested, please check it out either by using the new “Store” tab above or by clicking here.

Much of what I sell comes from my interest in nature photography and also martial arts. I’ll spare you a Flash widget, and instead just include a few photos below:




I appreciate the support, even if you only want to take a quick peek.

Apr 182013
 

As many have noticed, Flash on Linux was recently upgraded to version 11.2.202.280. This update breaks the ability to use Amazon Instant Video.

The best solution I found is at AskUbuntu. However, there were a few steps missing (such as purging the plugin cache), so I made an edit to add those steps. So, if you are having problems with the new Flash update, check out that link.

Feb 262013
 

I was having a hard time finding an HTML parser for my latest C++ project, so I decided to write up a quick summary of what I ended up using.

My #1 requirement for a parser was that it had to provide some mechanism of searching for elements. There are a couple of parsers available that only provide SAX-style parsing, which is very inconvenient for all but the simplest of parsing tasks. An ideal API would provide searching using XPath expressions, or something similar.

The only decent sources of information I found were these three questions from Stack Overflow: Library Recommendation: C++ HTML ParserParse html using C, and XML Parser for C. Below is a summary of what I considered along with my take on each:

  • QWebElement - Part of the Qt framework. Although it provides a rich API, I couldn’t figure out how to compile any Qt code outside of Qt Creator (I’m using Code::Blocks.)
  • htmlcxx – Standalone, tiny library. I got some code up and running with this library very fast. However, I quickly realized how limited it is (e.g. poor attribute accessors, no way to search for elements.) Limited documentation.
  • Tidy – The classic HTML cleaner/repairer has a built-in SAX-style parser. Simple to use, but like htmlcxx, limited in what it can do.
  • Tidy + libxml++ – Tidy can transform HTML into XML, so all that’s needed is a good XML parser. This was the solution I ended up using.

My final solution was to use Tidy to clean up the markup and convert it into XML. Then, I use libxml++ (a C++ wrapper for libxml) to traverse the DOM. libxml++ supports searching for elements with XPath, so I was happy.

Here’s some sample code demonstrating Tidy and libxml++.

 

Step 1: Using Tidy to clean HTML and convert it to XML:

#include <tidy/tidy.h>
#include <tidy/buffio.h>

std::string CleanHTML(const std::string &html){
    // Initialize a Tidy document
    TidyDoc tidyDoc = tidyCreate();
    TidyBuffer tidyOutputBuffer = {0};

    // Configure Tidy
    // The flags tell Tidy to output XML and disable showing warnings
    bool configSuccess = tidyOptSetBool(tidyDoc, TidyXmlOut, yes)
        && tidyOptSetBool(tidyDoc, TidyQuiet, yes)
        && tidyOptSetBool(tidyDoc, TidyNumEntities, yes)
        && tidyOptSetBool(tidyDoc, TidyShowWarnings, no);

    int tidyResponseCode = -1;

    // Parse input
    if (configSuccess)
        tidyResponseCode = tidyParseString(tidyDoc, html.c_str());

    // Process HTML
    if (tidyResponseCode >= 0)
        tidyResponseCode = tidyCleanAndRepair(tidyDoc);

    // Output the HTML to our buffer
    if (tidyResponseCode >= 0)
        tidyResponseCode = tidySaveBuffer(tidyDoc, &tidyOutputBuffer);

    // Any errors from Tidy?
    if (tidyResponseCode < 0)
        throw ("Tidy encountered an error while parsing an HTML response. Tidy response code: " + tidyResponseCode);

    // Grab the result from the buffer and then free Tidy's memory
    std::string tidyResult = (char*)tidyOutputBuffer.bp;
    tidyBufFree(&tidyOutputBuffer);
    tidyRelease(tidyDoc);

    return tidyResult;
}

 

Step 2: Parse the XML with libxml++:
The following code parses the HTML contained in ‘response’ (passing it to CleanHTML first.) Then, we search for the element with id ‘some_id’. After outputting how many elements match that criteria (should be 1), we output the line in the XML at which the element occurs. For the sake of saving space I omit error checking.

#include <libxml++/libxml++.h>

xmlpp::DomParser doc;

// 'response' contains your HTML
doc.parse_memory(CleanHTML(response));

xmlpp::Document* document = doc.get_document();
xmlpp::Element* root = document->get_root_node();

xmlpp::NodeSet elemns = root->find("descendant-or-self::*[@id = 'some_id']");
std::cout << elemns.size() << std::endl;
std::cout << elemns[0]->get_line() << std::endl;

 

More info

To compile the example code, I use the g++ flags: `pkg-config --cflags glibmm-2.4 libxml++-2.6 --libs` -ltidy. As the flags suggest, you’ll need the glibmm library in addition to Tidy and libxml++ (and their dependencies.)

See the libxml++ class references: http://developer.gnome.org/libxml++/stable/annotated.html

Jan 142013
 

Happy belated new year! Wow, I’ve been slacking on this blog. Anyway, I wanted to give a quick update on what I’ve been doing over the past month and what I’ll be doing in 2013.

So long Windows!

I’ve switched to Linux! Linux Mint, to be exact. I made the switch during my Christmas break, and after a few weeks of getting adjusted, I don’t think I can ever switch back to Windows again. While I still have a small Windows partition for games (Battlefield 3, anyone?), my day-to-day activities are now carried out exclusively on Linux. There were a few factors that caused me to switch:

  • Python development (which I feel myself gravitating more towards) sucks on Windows
  • I was tired of reinstalling Windows every few years
  • Linux is more secure (of course)

What does this mean for my blog/projects? Well, I think I’ll be spending less time with C#, unfortunately. I’ve installed MonoDevelop and Mono, which I’m looking forward to working with, but the draw of Python may end up being too great. I don’t think I’ll ever give up C#, however.

Less C#, more Python

As I said, I’ll be spending more time with Python. I’m hoping to come up with some good Python posts.

Raspberry Pi!

Over break I acquired my first Raspberry Pi (model B). Currently, its sole purpose is a No-IP client, but I have big plans for it. Sensor gateway, anyone? More on that some other time.

C++

I’ve been using C++ on a very basic level for the last year or two (with Arduino and a few other projects,) but this year I’ll be investigating it much more.

Titanium

And finally, I have a few improvements in mind for VirtualScroller, my Titanium module for implementing memory-efficient infinite (and finite) scrolling. In addition, I’ll probably be playing around with some networking stuff on Titanium.


Well, that’s what I’ve got lined up for now, although I’m sure I’ll get side-tracked during the course of the year and end up working on completely different stuff in addition to what I’ve listed. Either way, 2013 should be fun.

Dec 102012
 

I’ve posted BaseMemberPromotingProxy.dll to the downloads section of the BaseMemberPromotingProxy BitBucket. Now you don’t have to compile the source yourself to use it – just grab the DLL and you’re all set!

Also, to anyone that has been compiling (or modifying) the source, note that I made a few commits that correct a stupid spelling mistake. In some places, BaseMemberPromotingProxy was incorrectly spelled BaseMemberyPromotingProxy.

Enjoy, and remember:

There is no “y” in “member” – Me

 

Dec 042012
 

If you’re trying to debug an app (or website) on Android that is using HTTPS, then this short guide might be for you. I’ll show you how to set up Fiddler and Connectify Me so that you can view your device’s encrypted communications.

Requirements

  • Computer with internet access and WiFi
  • Android device that supports WiFi proxies (Honeycomb or later – older devices might require a proxy app, though I can’t guarantee it will work)

 

Instructions

  1. Install Connectify Hotspot (the free version works fine) and start your hotspot. Side note: Don’t pick a stupid password for your hotspot; you probably don’t want world+dog hopping on your connection.
  2. Connect your Android device to your hotspot (via WiFi settings) and ensure you can access the internet using the connection.
  3. Install Fiddler (but don’t open it yet.)
  4. Install this certificate maker plugin. It replaces the default certificate plugin in Fiddler so that the certificates will be compatible with Android.
  5. Open Fiddler and follow these configuration steps:
    1. Go to Tools | Fiddler Options… | General tab. Uncheck “Show a message when HTTP protocol violations are encountered”
    2. Switch to the HTTPS tab. Check “Capture HTTPS CONNECTS” and then “Decrypt HTTPS traffic”. Click Yes twice on the two dialogs that pops up.
    3. Click the “Export Root Certificate to Desktop” button.
    4. Switch to the Connections tab and check “Allow remote computers to connect”. Click Ok on the dialog.
    5. Take note of the port listed next to “Fiddler listens on port:”. We’ll need it soon.
    6. Close the options dialog.
  6. Exit Fiddler and then reopen it.
  7. On this website, upload the certificate that was exported to your desktop. Then, on your Android device, navigate to the URL the page produces to install the certificate.
  8. Determine the IP address of your computer (using ipconfig at the command line) on the ad-hoc WiFi connection that Connectify Hotspot has created.
  9. Using the instructions on this page (halfway down), configure the WiFi connection on your phone to use the following proxy information:
    1. IP address: What you found in step 9.
    2. Port: From step 5.e.

 

Test it out

Let’s see if everything works. Make sure Fiddler is open on your screen. On your Android device, browse to a random page. You should see the connections on the left-hand side of the Fiddler screen. If all of our HTTPS configurations worked, you should also see HTTPS communications decoded and dumped as well.

It’s possible that not all HTTPS communications will be shown, since some apps might reject the Fiddler root certificate. There’s nothing that can be done about that, unfortunately.

Note that Fiddler will also have changed the proxy settings for your entire computer. Connections from your desktop browser, email clients, etc. will be shown side-by-side with those from your Android device.

Cleanup

When you’re done, you’ll want to do a few things to revert your Android device and computer back to how they were.

  1. Undo the proxy configurations on your Android device.
  2. Uncheck the “Allow remote computers to connect” option in the Fiddler settings
  3. Uninstall Fiddler’s root certificates from both your computer (Google for instructions) and Android device (under settings | Security)
Nov 042012
 

If you’re trying to set up caching with Code Contracts (and SQL Server CE) but getting errors, then this is the post for you.

On a fresh install of Code Contracts, enabling caching might spawn this error:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

This error is telling us that we need SQL Server CE (Compact edition) version 3.5.1, but it lies! What we really need is version 3.5.2.

To fix this error, download and install this (yes, on a 64-bit machine you do need to install both the 32 and 64-bit versions). It’s going to ask you where to extract the files, not where you want to install SQL Server itself; I just chose the desktop.

If you are getting errors such as:

... Schema specified is not valid. Errors:
... error 0175: The specified store provider cannot be found in the configuration, or is not valid

this means you installed the wrong version of SQL Server CE (such as version 3.5.1). To fix this, first uninstall any 3.5.x versions of SQL Server CE, and then download and install what I linked to above.

Oct 132012
 

jQuery UI 1.9 is finally here! What does that mean for dialogWrapper? Well, it would seem like the answer to that question is: nothing. A redesign of the dialog API is not present in version 1.9, and it doesn’t look like it will happen until the 2.0 release, according to the official site.

The planned changes for the 2.0 release are something to get excited about now, however. Some of the changes discussed add some nice functionality and improve the overall design of the API. Heads up: so far, it doesn’t sound like the 2.0 release will make dialogWrapper irrelevant.