Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR Incorporated.

Katrin and Jim

Month List

JSON Parser in AS3

by Jim Jan 31, 2012 9:22 PM

In preparation for creating a JSON parser that could parse directly to model objects, I created this generic parser. I’m not going to use it, because it’s painfully slow (30 seconds to parse vs. a fraction of a second for the built-in parser.) So it goes on the blog  :-P

It’s somewhat simplified from the full algorithm, but it handles basic cases and could be up to the standard with a little more work.

package util
{
   import flash.utils.*;
   
   public class JSONParser
   {
      private var _data : String;
     
      private var _index : int = 0;
     
      public function JSONParser(data : String)
      {
         _data = data;
      }
     
      // get one character and advance
      private function take() : String
      {        
         return _data.charAt(_index++);
      }

      private function assert(condition : Boolean) : void
      {
         if (!condition)
            throw new Error("Unexpected character at position " + _index.toString());
      }
     
      // assign values to properties until we reach a matching end bracket
      private function assignProperties(target : Object) : void
      {
         // we've just entered an object, should be getting a field name first...
         var field : String;
         
         while (true)
         {
            field = "";
           
            assert(take() == "\"");    // field should start with quote
            var char : String = take();
            while(char != "\"")
            {
               field += char;
               char = take();
            }
           
            assert(take() == ":");
           
            target[field] = getValue();
           
            // having got the value, next char should be a comma or
            // the end bracket we're looking for
            char = take();
            if (char == "}")
               break;
            assert(char == ",");
         }
      }
     
      // Next thing in line is the value of a field; return that
      private function getValue() : Object
      {
         // might be a simple type, an object, or an array...
         var char : String = take();

         if (char == "\"")
            return readToQuote();

         if (char == "{")
         {
            // this value is itself an object
            var value : Object = new Object();
            assignProperties(value);
            return value;
         }
         else if(char == "[")
         {
            // We've got an array of objects
           
            var ar : Array = new Array();
            var element : Object;
            char = ",";          // fake to get in loop
            while (char == ",")
            {
               element = getValue();
               ar.push(element);
               char = take();
            }
            assert(char == "]")     // should have been end of the array
            return ar;
         }
         else
            assert(false);
         return null;
      }
   
      // read a string literal until we get to the next quote (eats the end quote)
      private function readToQuote() : String
      {
         var end : int = _data.indexOf("\"", _index);
         var s : String = _data.substring(_index, end);
         _index = end + 1;
         return s;
      }
     
      public function parse() : Object
      {
         var char : String;
         var root : Object;
         
         assert(take() == "{");
         
         root = new Object();
         
         assignProperties(root);
         
         return root;
      }
   }
}

2011 EOS Receiver Hitch

by jim Jan 24, 2012 8:31 PM

A few months ago I got a new VW Eos. I might have purchased the last manual transmission EOS in the U.S. - certainly in the southeast. It’s a shame they discontinued that option in the 2012 U.S. market.

There isn't a whole lot of information out there about bike racks on the American EOS, so I thought I would share my experience and some pictures, for anyone else that's wondering about this.

I got a Draw-Tite Sportframe receiver - this is rated at 200lb tongue weight and 2000lb towing.
http://www.etrailer.com/Trailer-Hitc...eid=2011208575.

For the rack I chose a Swagman XTC-2.

Some things about the install:
I had to jack up the passenger side a bit to get the receiver in place.

On my car, the passenger side bolt spacing is apparently non-standard. I couldn't put the exhaust hanger bracket bolts back into place. I called eTrailer, and they called Draw-Tite, and the spacing on the receiver is correct, at exactly the specified 4 inches. I guess there's some variability between cars, as to the exact spacing of the exhaust brackets. I expanded the rear passenger side bolt hole by about 1/4 inch with a dremel and grinder bit, to make everything fit.

I suggest checking this spacing before fishing the bolts into their holes with the provided wire tool. It’s not real hard to get the bolts into place, but it’s a real pain getting them back out again.

The receiver pushes up the rear fairing by about 3/4 inch. It's not really noticeable, because it's under the car, and it might be by design to keep it from vibrating.

The main bar of the receiver touches my trunk floor - in fact it was "in the way" by about 1/8 or 1/4 inch. I couldn't push the bolt flanges flush against the frame, and had to just torque the bolts down. Again I'm chalking that up to some variability in the car.

Some of the exhaust heat shield does need to be trimmed back, as the installation instructions say. The aluminum can be cut with a sturdy utility knife.

With the middle bar of the rack folded down, there's plenty of room for the top to open.

The bike closest to the car doesn't have a lot of pedal clearance, but the rack is very sturdy and I don't think it will flex enough for the pedal to hit the trunk. I'm going to put an sock over that anyway; I could bang it when putting the bike on the rack.

All in all, I'm very happy with the bike setup. The rack is sturdy, and easier to deal with than the roof rack I had on my Jetta.

Tags:

Tinkering