Life Update

Updated the blog to run 3.3.1 - lot of cobwebs around these parts. Hopefully I can be more proactive in blogging about things going on at work, and perhaps starting to write about what I'm up to personally (not that I have much of that right now). Maybe my Google stats will jump over the 0.3 hits I average! Dare to dream!

cURL stripping newlines from your CSV or other file?

I'm in the process of writing a REST endpoint for uploading CSVs to Crossbar as part of our communications platform at 2600hz. Not wanting to invoke the full REST client interface, I generally use cURL to send the HTTP requests. Today, however, I had quite the time figuring out why my CSV files were being stripped of their newline characters. The initial invocation:

    $> curl http://localhost:8000/v1/path/to/upload -H "Content-Type: text/csv" -X POST -d @file.csv

Walking through the code, from where I was processing the CSV down to the webserver handling the connection itself, looking for who was stripping the newlines, I determined it was coming in sans-newlines and decided to check out cURL's man pages for what might be amiss. I quickly found that the -d option was treating the file as ascii, and although the docs don't explicitly say so, it appears this option will strip the newlines. The resolution is to use the –data-binary flag so cURL doesn't touch the file before sending it to the server.

Cron and infinite loops do not mix

More "expert" code time! From the "expert":

Please put this script in a cron to run every minute

    while true; do
      rsync -a server:remote_dir local_dir
      sleep $freq

local\_dir is going to be really, really, really up to date after a few minutes…the server crash will be epic. Perhaps we should write a script to find and kill these rogue processes and run it every minute too, but stagger it with the other cron…

You get paid for this?

Spotted in some high-priced "expert"'s code:

    switch ($retcode)
        case -1:
        case -3:
            if ($retcode==-1)
                log("SOME_CODE", "SOME MSG");
                log("SOME_OTHER_CODE", "SOME OTHER MSG");

Resolving Dialyzer "Function foo/n has no local return" errors

Dialyzer is a great static analysis tool for Erlang and has helped me catch many bugs related to what types I thought I was passing to a function versus what actually gets passed. Some of the errors Dialyzer emits are rather cryptic at first (as seems commonplace in the Erlang language/environment in general) but after you understand the causes of the errors, the fix is easily recognized. My most common error is Dialyzer inferring a different return type that what I put in my -spec, followed by Dialyzer telling me the same function has no local return. An example:

    foo.erl:125: The specification for foo:init/1 states that the function might also return {'ok',tuple()} but the inferred return is none()
    foo.erl:126: Function init/1 has no local return

The init/1 function (for a gen\_server, btw):

    -spec(init/1 :: (Args :: list()) -> tuple(ok, tuple())).
    init(_) ->
      {ok, #state{}}.

And the state record definition:

    -record(state, {
      var_1 = {} :: tuple(string(), tuple())
      ,var_2 = [] :: list(tuple(string(), tuple()))

Spot the error? In the record definition, var\_1 is initialized to an empty tuple and var\_2 is initialized to an empty list, yet the spec typing for the record does not take that into account. The corrected version:

    -record(state, {
      var_1 = {} :: tuple(string(), tuple()) | {}
      ,var_2 = [] :: list(tuple(string(), tuple())) | []

And now Dialyzer stops emitting the spec error and the no local return error.

IT Expo

Just returned from IT Expo West last night. Three days of learning, hob-nobbing, and talking myself hoarse about the awesomeness that is 2600hz. We got a decent writeup posted on TMC's site, met quite a few people, collected beaucoup business cards, and generally had a fun time hanging with the team. Super tired but ready to keep building the best hosted PBX software platform! Bonus: See Darren's awesome (yet mildly awkward) video interview! Also, VoIP service providers looking to offset calling costs for their business clients can look at PromoCalling as a way to compete with Google and Skype's free calling plans.

Still Kicking

I am still alive and well; just busy. I did write a blog entry for my company, 2600hz. More to come…eventually.