Feature Survey – Intelligent Accessory Controller

If you saw my post about hacking the CAN-Interior bus of a JK, you noticed my comments about building an intelligent accessory switching system. I’m pretty far along with that, and would love to get some feedback from the community on features they’d like to see.

Right now my plan is to build something, release it all with open-source and open-hardware so people can build their own, but there’s been enough interest for people who would like to have one built for themselves that I made the following survey. If you have a moment, I would really appreciate your feedback.

Once the survey is all done, I’ll post the results here too so everyone can see the data.

And if you aren’t sure exactly what I’m talking about – it’s effectively a standard relay box in your engine bay, but instead of just toggle switches, it’s smart and listens to your car’s computers and can activate switches when lights go on/off, high-beams, blinkers, ignition – whatever we can think of.

The link to the survery is here: https://www.surveymonkey.com/s/LKMHTBG

 

JavaScript Evaluation for Erlang Applications

If you are an Erlang developer you are likely familiar with the Riak storage engine, and how the MapReduce feature can evaluate arbitrary JavaScript expressions. Can you use this same code to do your own JavaScript evaluations for your Erlang projects? Yes, and it turns out to be surprisingly easily.

Getting your development environment running erlang_js is the first order of business. I’ve done all of my testing on a Mac OS X system, both Lion (10.7) and Mavericks (10.9). I use Erlang R14B04 for these tests, since that version is what we primarily target at the office.

If you want to manage multiple versions of Erlang on your OS X system, I highly recommend the erlbrew utility as a quick and easy way to maintain multiple versions. We’ve recently made it support R14 builds on OS X Mavericks, so there’s no excuse not to use it!

Assuming you have a working Erlang and OS X command-line development tools active, execute the following to checkout the erlang_js project and build it locally:

git clone git://github.com/basho/erlang_js.git
cd erlang_js; make all test

One of the most compelling uses of a JavaScript engine from another language like Erlang is the ability to pass arbitrarily deep objects as JSON so they can be evaluated. This allows your application to use JavaScript as a general-purpose expression language even if the objects are backed by an Erlang term. This is effectively what you get with Riak when using the MapReduce feature.

As an example, let’s imagine a deeply nested data structure that represents a server configuration. We’d like to execute a JavaScript expression against that data to find the first active network interface. Here’s an example of how you’d do it using erlang_js:

% Start the erlang_js application and driver.
ok = application:start(erlang_js).
{ok, JSDriver} = js_driver:new().
 
% Create a deeply-nested data structure to evaluate
ServerObj = {struct, [
    {<<"id">>,<<"foobar.example.org">>},
    {<<"type">>,<<"linux">>},
    {<<"interfaces">>, [
        {struct, [
            {<<"name">>,<<"eth0">>},
            {<<"ipaddress">>,<<"192.168.1.101">>},
            {<<"enabled">>,true}
        ]},
        {struct, [
            {<<"name">>,<<"eth1">>},
            {<<"ipaddress">>,<<"192.168.1.102">>},
            {<<"enabled">>,true}
        ]},
        {struct, [
            {<<"name">>,<<"bridge0">>},
            {<<"enabled">>,false}
        ]}
    ]}
]}.
 
% Evaluate our object with an arbitrary JavaScript expression
JSFun = <<"function is_any_interface_enabled(Server) { for (var i = 0; i < Server.interfaces.length; i++) { if (Server.interfaces[i].enabled) return true; } return false; }">>.
 
js:call(JSDriver, JSFun, [ServerObj]).

The real trick is building your Erlang data structure properly so that the custom version of mochijson2 can encode the object as JSON. As you see from the examples, use tuples with a struct atom as the first member to specify an object. Arrays are just arrays.

I have noticed that it is very easy to confuse a single instance of the js_driver object and it is hosed until a new one is created, so consider that in how you structure your driver usage.

 

Biking in Big Bend – Old Ore Road

Yesterday I took the mountain bike down Old Ore Road in Big Bend National Park. The park’s website calls this route the premier ride in the park so I just had to try it.

Old Ore Road is a primitive dirt road just over 26 miles in length. It starts off fairly gentle and just like any other gravel and rock road, but around mile 7 things begin to get a little more interesting and a bit more difficult. Taking the road from the north to the south is primarily downhill, but there are at least 5 or 6 challenging climbs even when ridden in that direction. All of these climbs are very rocky and take a fair amount of bike handling skill to complete unscathed.

hrdata-2008-12-20

The southern terminus of Old Ore Road is just a few miles west of Rio Grande Village near the Rio Grande Overlook. This is almost all downhill so it makes for a nice, fast way to finish up the ride.

It took me 3 hours 39 minutes to complete the Old Ore Road section of the route, just under the 4 hours suggested by the park’s website, and another 9 minutes to get to Rio Grande Village. I didn’t stop to smell the roses, so anyone wishing to explore some of the sites along the way should plan on the 4 to 6 hour timeframe given.

I’d also not recommend trying to ride this during the summer months. It was in the 70s when I rode, but the sun was rather intense that day (like most of them). I went through nearly 4 liters of water for this ride, so plan accordingly.

A nice surprise about the road was that it wasn’t completely devoid of other visitors. While I was the only biker I saw that day, I did come across 5 vehicles going either direction on the road. All were friendly and gave me the right of way when I needed it. That’s a good sign for a road you’d really rather not break down on.

This picture gives you a characteristic view of the start of the road. It is typical Chihuahuan desert scenery at first. The rather flat and easy looking road seen here is only that way to lure you into a false sense of security about your life over the next few hours.
PC200074

These cliffs are called the Alto Relex. The pour-off pictured here would be awesome to see when it was actually raining.
PC200080

I’m about 3/4 done with the road and still alive, despite a few high-speed tumbles and utter exhaustion. Who forgot to tell me mountain biking was harder than roadie stuff?
PC200084

Taking my last break at Camp de Leon. Jose de Leon was murdered in 1933. His gravemaker is just a few hundred yards before the campsite marker.
PC200085

If you like mountain biking you’ll like this road. It isn’t a single-track by any means, but it’s still a blast and takes you through a section of the park you wouldn’t otherwise get to see. If you aren’t a mountain biker, then head down there with your favorite 4×4 and drive it.

Jury Duty

Yesterday I reported for petit jury service for the Fort Bend County courts in the county seat of Richmond, Texas. This is the 4th time I’ve been called for jury service in Texas, but the first time at the county level.

The county has grown so much in the past few years that the court system has had to add organizational measures to deal with the reality that multiple courts are spread across buildings and a large number of jurors are needed in any given week. You first report to a jury assembly building where everyone is gathered in one spot and an associate judge and his clerks weed out anyone that cannot serve, with the intention that it is better not to waste the courts time later with a juror who cannot actually serve. Once the weeding out has been completed the clerks’ computer randomly picks people for the various courts. You are called out, put in your proper spot, and then walked over to the appropriate court by a bailiff.

I was juror number 59 out of 60 in the pool of jurors assigned to the 434th Judical District Court presided over by Judge James H. Shoemake. Once we arrived he gave us detailed instructions on what to expect over the rest of the day and introduced to the term voir dire, which is the process of examining the jurors themselves so that both sides of the case can pick the best pool of jurors for the trial. It was a sexual abuse of a minor case so you could feel the discomfort in the room after we were told of the charge. Luckily during the voir dire phase you are not actually told any more details of the case other than what the charge is, possible punishment ranges, and who the defendant is.

The prosecution then began their portion of the juror examination. The style of the assistant district attorney was to ask leading questions to get the jurors to talk. Questions such as: if you were to believe the testimony of the accuser beyond a reasonable doubt and she was the only witness, would you be able to make a decision one way or the other? Of course this led to half the juror pool debating and relating life stories rather than just getting to the point of the matter: yes, I can be impartial, or no, I cannot. This lasted for a little over an hour and then we broke for lunch.

Once we came back it was the defense team’s turn. The head lawyer was an older guy that had been in the Richmond area most of his life and been practicing law there for almost 35 years. His style was completely different: act the typical southern gentlemen and question each juror individually and have friendly banter with every one of them. He went through the first 40 or so jurors before finishing up at around 3pm.

After that we were all sent to another court room to sit and wait for the juror selection process to continue. That took until 4:45pm during which several jurors were called down for further questions. Once we were pulled back into our court by the bailiff the judge announced the juror selection by number. After that, the rest of us were free to go.

In some respects I would not have minded sitting on the jury. It would have been an interesting experience to be on an actual criminal jury and this case was expected to be finished by the end of the week. I’m sure I’ll be given further opportunities in my lifetime to go through it again.

When you get called up, don’t forget to bring a book. There’s a lot of dead time to fill.