Kristian Kristensen’s Blog


Sencha Touch Cookbook Published

Posted in Book,Code,Misc,Sencha Touch by Kristian Kristensen on the February 18th, 2012

During the fall of 2011 I was a technical reviewer of the now published book on Sencha Touch by Packt Publishing. The books goes through a number of different scenarios for building apps with Sencha Touch.

Sencha Touch Cookbook

Reviewing a book has been an interesting experience. The process is fairly simple. You receive a number of chapters on a fixed schedule. You then have to comment on it, suggest improvements, fact check what’s written as well as make sure the code is reasonable. This then has to be sent back to the editor.
The bonus of being a reviewer is that you get your name in the book. So if you go to the Amazon Look Inside feature and flip through the first few pages you’ll find a little blurb about me.

You can find and buy the book online at Packt Publishing or on Amazon.

  • If you like my writing you should subscribe to my RSS feed.

    Creating Podio Voicemail Using Tropo, Podio and PHP

    Posted in Code,Misc,Podio,Tropo by Kristian Kristensen on the June 3rd, 2011

    On Wednesday June 1st I went to the Podio World Tour NYC App Camp. I didn’t really plan on making anything, I mainly showed up to check it out and say hello to the Podio peeps. However, I got into a small chat with @fabianmu and @froda about how to augment Podio, so you could call a phone number and have a message be posted into Podio. I thought: that’s pretty easy! I’ll just whip up Tropo and add some PHP to glue it all together and I’ll be golden. Basically yes, however it took a bit longer than the time I had that evening. This post explains what I did and how it works.

    Scenario

    You have a phone number that anyone can call. Once connected the user is asked to leave a voicemail for you. The recording is transcribed to text and both the recorded audio file and the text is uploaded to special app on Podio. That way you have a central voice mailbox for your company/organization integrated into your Podio space.

    Podio Setup

    Here’s how it looks in Podio.

    When a new message has been placed in the voice mailbox, it’ll be included in the Activity Stream of the space. In the top navigation bar we see the “Calls”-app which holds all of the individual calls.

    Podio - Activity Stream

    Clicking a single item reveals the following picture. Here we see all of the details of the call including a transcription of the voice mail.
    Podio - Single Item

    The “Calls”-app is simple and was configured using the Podio App Builder. It just has a single text field for the transcription, as well as the default title. The audio file is attached using the standard attachment feature.
    Podio - New Call

    Tropo Setup

    In this scenario Podio works as a receiver of information and hence we’ll use the API to add this information. In order to record the I used Tropo which is a service like Twilio. It allows you to create voice and text message communication solutions and have your own code executed when certain things happen. Here we want something to happen when a user calls us up over the phone. The following image shows the configuration of my Podio Tropo app.

    Podio - Tropo

    I utilize the Hosted option on Tropo, and have assigned a local US number to it. This means that whenever someone calls this number, the code in the hosted file Podio.rb will be executed. That file contains the following code.

    say "Welcome to the Podio Voice Mail."
    
    callerID = $currentCall.callerID
    sessionId = $currentCall.sessionId
    
    record "Please leave a voicemail for us. When you are finished recording, press the pound key.", {
        :beep => true,
        :maxTime => 60,
        :terminator => '#',
        :recordURI => "http://server.com/hook.php?callerId=" + callerID + "&sessionId=" + sessionId,
        :transcriptionOutURI => "http://server.com/hook.php?callerId=" + callerID + "&sessionId=" + sessionId,
        :transcriptionID => sessionId
        }
    say "Thank you!"
    hangup
    
    • First we greet the user.
    • Then we extract some information about the call, caller id is the number the user is calling from, session id is an internal id we can use as an identifier.
    • We ask the user to leave a voicemail for us, and press # when done. When he/she has done this we ask Tropo to post the recording to a server and passing along some information in the query string. We also request transcription to be done, and the result of that should be posted to the specified URL. Again we utilize the query string to pass some information.
    • Then we thank the user and finally hangup.

    Custom PHP Glue

    The receiving code running on a server is where we glue the output of Tropo together with Podio. I had some trouble getting PEAR to work when I first hacked on it. However, googling around helped me get it up and running. The trick to install the required PEAR packages for the Podio PHP helper was to run

    pear install HTTP_Request2-beta
    

    Also I had to modify my “open_basedir” to allow PHP to include files from the PEAR directory. Once that was done, the Podio PHP library worked like a charm.

    The PHP script that receives data from Tropo and uploads it to Podio has a number of elements to it. First we setup the required information to access Podio:

    <?php
    require_once('podio-php/PodioAPI.php');
    
    $client_id = 'YOUR_CLIENT_ID';
    $client_secret = 'YOUR_API_SECRET';
    
    $oauth = PodioOAuth::instance();
    $baseAPI = PodioBaseAPI::instance($client_id, $client_secret);
    
    $baseAPI->setLogHandler('file', 'podio_log.log', 'podio');
    
    //log base info
    $baseAPI->log(serialize($_GET));
    
    $file_name = 'audio-' . $_GET['sessionId'] . '.wav';
    $target_path = '/var/www/' . $file_name;
    

    We set up the basic API Client information. You can create this by going to the API Keys page on your profile. Also we setup a log file to make it easier to see what’s going on. We setup the file name and the target path, which will be where the audio file will be stored locally. We use the session identifier as part of the name to be able to retrieve it later, when the transcription result comes in.

    To save the audio file received from Tropo the following code goes into effect:

    if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
      if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) {
              $baseAPI->log("$target_path [{$_FILES['filename']['size']} bytes] was saved");
      } else {
             $baseAPI->log("$target_path could not be saved.");
      }
    }
    

    Here we utilize the variables set up previously.

    Once the transcription result is posted to our PHP code, we execute the following.

    // Obtain access token
    $username = 'YOUR_USER_ID';
    $password = 'YOUR_PASSWORD';
    $oauth->getAccessToken('password', array('username' => $username, 'password' => $password));
    
    $api = new PodioAPI();
    
    $transcription_input = @file_get_contents('php://input');
        $obj = json_decode($transcription_input);
    
        $baseAPI->log('Transcription input: ' . $transcription_input);
    
    $file = $api->api->upload($target_path, $file_name);
    

    First we log in to the Podio API and get an object reference to it. Then we read the posted JSON transcription result from Tropo into a temporary variable and JSON decode it. We upload the audio file posted previously and hold on to the reference returned from Podio.

    Next is the actual code that posts the item into the “Calls”-app in Podio. @fabianmu’s shodio project was of great help in figuring out how to construct the field and value arrays.

    $app_id = YOUR_APP_ID;
    
    //create fields array
    $newItem = array();
    $newItem['appId'] = $app_id;
    $newItem['external_id'] = $_GET['sessionId'];
    $newItem['tags'] = array();
    
    //Title field
    $newField = array();
    $newField['field_id'] = 1817081;
    $newField['values'][]['value'] = 'New voicemail from ' . $_GET['callerId'];
    $newItem['fields'][] = $newField;
    
    //Transcription field
    $newField = array();
    $newField['field_id'] = 1817083;
    $newField['values'][]['value'] = $transcription_input;
    $newItem['fields'][] = $newField;
    
    $item = $api->item->create($app_id, $newItem['fields'], array((int)$file['result']['file_id']), $newItem['tags'], $newItem['external_id']);
    
    $baseAPI->log("new item posted to podio: " . serialize($item));
    

    We basically construct the required fields, putting in “New voice mail from $CALLER_ID” and adding the transcribed result to the transcription field. Then we create a new item for our app identified by $appId, associate the file we uploaded earlier to the item and put in the session identifier from Tropo as the external_id. To verify that something happens, we log out the returned item from Podio.

    Conclusion

    Tinkering with Podio’s API was really fun. As always there was a bit of a learning curve in getting the API helpers up and running. Getting the right versions of PEAR and related libraries, and making sure that everything connects together took most of the time. Also figuring out where and how Tropo posts the audio file and the transcription result, took a bit of tinkering.
    It’s amazing how quickly you can built something with these new API’s and services out there. Voice enabling an app in less than a 100 lines of code is pretty neat.

  • If you like my writing you should subscribe to my RSS feed.

    Using a Column Alias in a Firebird Where Clause

    Posted in Code,Misc by Kristian Kristensen on the March 24th, 2011

    Here’s an odd thing that tripped me up a bit as I was writing a piece of SQL for Firebird (my ignorance even had me blabbering out on Twitter). I wanted to do some manipulation on a column in a SELECT and then filter on this computed column. I thought I could just give the column an alias, and then use this in the WHERE clause. Something like this:

    SELECT substring(p.Name from 5 for 2) as mycol, p.Name FROM "People" p WHERE mycol = 'Kr'
    

    This doesn’t work though. Parsing fails saying that the column ‘mycol’ doesn’t exist or isn’t known. What you can do is to repeat the computed column like this:

    SELECT substring(p.Name from 5 for 2) as mycol, p.Name FROM "People" p WHERE substring(p.Name from 5 for 2) = 'Kr'
    

    Interestingly enough the column alias does work in the ORDER clause of a SELECT:

    SELECT substring(p.Name from 5 for 2) as mycol, p.Name FROM "People" p ORDER BY mycol
    

    Asking my friend Jakob Andersen he says it has to do with the order in which the expressions are parsed. Makes sense. This also explains why the same behavior occurs if you try to create the same expressions in SQL Server. The other option for solving the above in Firebird is to use an inline view.

  • If you like my writing you should subscribe to my RSS feed.

    Comparing Two Nullable Values In a Workflow Using Visual Basic

    Posted in Code,Misc,WF4 by Kristian Kristensen on the March 17th, 2011

    I needed to compare two Nullable date values in a workflow service. The way it was organized was as a parameter to a method call (using the InvokeMethod Activity), namely the Sort call on a collection of POCOs. The parameter is of type Comparison with T being MyPOCO, and it’s value was something that had to compare two Nullable dates.

    At first the dates couldn’t be null, and hence there wasn’t a problem. I’d just use CompareTo:

    Function(d1, d2) d1.MyDate.CompareTo(d2.MyDate)
    

    Once the values are Nullable though it’s a different game. I had an exception because now values in my collection could have null on the MyDate property.

    System.InvalidOperationException: Failed to compare two elements in the array.
    —> System.InvalidOperationException: Nullable object must have a value.

    My solution was to rewrite the function delegate I pass in, and use Nullable.Compare:

    Function(d1, d2) Nullable.Compare(d1.MyDate, d2.MyDate)
    
  • If you like my writing you should subscribe to my RSS feed.

    My Talk From JAOO/GOTOcon Is Up On Channel9

    Posted in Code,IronPython,IronRuby,Misc by Kristian Kristensen on the October 16th, 2010

    As I said in my previous blog entry my talk at GOTOcon (previously JAOO) was recorded by Microsoft with the intent of putting it up on Channel9. After some processing and uploading it is now up online.

    Link to Channel9: Kristian Kristensen – Iron* – An Introduction to Getting Dynamic on .NET

    From Channel9 you can download the video in a variety of formats.

    I’ve embedded the video below using the Channel9 SilverLight player:

    Get Microsoft Silverlight

    Let me know if you have any questions, comments or suggestions.

  • If you like my writing you should subscribe to my RSS feed.

    IronLanguages and the DLR Podcast with Me

    Posted in IronPython,IronRuby,Misc,Podcast by Kristian Kristensen on the July 16th, 2010

    Some time ago I recorded a podcast with Daniel from DPE in Microsoft Denmark on IronLanguages (IronRuby and IronPython) and the DLR. It’s in Danish and is now up online. You can listen to it here:

    If you prefer to download it and listen to it offline there’s a direct link to an MP3 here.

    Link to Daniel’s original post.

  • If you like my writing you should subscribe to my RSS feed.

    Collection of Random Laws Worth Thinking About

    Posted in Misc by Kristian Kristensen on the June 22nd, 2008

    I’ve had a couple of links lying around in my blog reader. I’d planned to blog about each of them, perhaps coupling them. Since they’ve been there for quite a few weeks and I still haven’t made a post, I guess I should just list and jot a few comments down for each.

    Greenspun’s Tenth rule Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
    Cite: wikipedia

     

    I believe I’ve picked this up via Reg Braithwaite and his regular writings on programming languages and all things software dev. Dunning-Kruger effect The Dunning-Kruger effect is the phenomenon wherein people who have little knowledge (or skill) tend to think that they know more (or have more skill) than they do, while others who have much more knowledge tend to think that they know less.
    Cite: wikipedia

    Probably via Reg Braithwaite as well. It’s a pretty interesting hypothesis, and fits well with the sayings “The more you learn, the more you realize what you don’t know” and “Ignorance is bliss”. It also fits with a previous pots of mine The Mythical 5%, where I reference Bruce Eckel and Joel Spolsky. Sapir–Whorf hypothesis postulates a systematic relationship between the grammatical categories of the language a person speaks and how that person both understands the world and behaves in it.
    Cite: wikipedia

    I heard this a RubyFools where Matz referenced the theory during his key note. I’ve actually been thinking about this before, and wondered if there was any science behind it. My initial thoughts on this were also related to programming languages, but since PL’s and natural languages share many similarities it’s interesting to extend it. In speaking with my father about it he also noted whether or not it is a coincidence that so many philosophers are German. Does the German language with its strict strucutre and grammar promote a special way of thinking that tailors well to philosophy. An example of a German philospher could be Immanuel Kant.

    Also I remember from my first year of university they wanted to teach us SML instead of a more mainstream language such as C and Pascal. One of their motivations was that by teaching students such a language first they would develop a different style of thinking compared to their peers who might have pre-university experience in C or another language. So does the first language you pick influence the way you think about programming for the rest of your life? And does self learning it impose a certain “dirty” way of doing things compared to being taught academically?

    Either way, there you go a few thoughts to think about on a Sunday. Please feel free to comment below.

  • If you like my writing you should subscribe to my RSS feed.

    Comments Off

    Now Featuring MCPD Web Developer

    Posted in MACH,MCTS,Microsoft,Misc by Kristian Kristensen on the April 7th, 2008

    Last Friday (4th of April) I took the MCPD Web Developer exam. It went well with a very small margin. I scored 700 points, which is the exact required number of points needed to pass a Microsoft certification. This means I’m now an MCPD in Enterprise Application Development and Web Development. Very cool!

    I also think it marks the need to ponder about my current certification status. Since I started at Microsoft in December I’ve taken 6 developer certifications. With respect to the multi-exam certifications this is probably as high as one can reasonably get. The MCPD is the largest or most inclusive developer certification in the MS Certification program if you disregard the Microsoft Certified Architect (MCA) program. The later requires a lot of things including meeting before a board and discussing a case. Suffice to say you’re not going to nail that one after 4 months on the job!

    I think my next certification steps will be to take the Microsoft Solutions Framework (MSF) exam. After that it’s the infrastructure and server certifications I’ll focus on as part of the NG program.

    In two weeks I’m going to Redmond, WA to attend Microsoft Services University (MSSU); a 2,5 weeks course that all new employees in Microsoft Services is attending. After that I’ll have a short 5 day break/vacation where I’ll visit family, and before I go home I have a Biztalk course in Irvine, CA. So a lot of traveling! I’ll be in the US for a month shy of a couple of days.

  • If you like my writing you should subscribe to my RSS feed.

    Attending Ruby Fools

    Posted in Misc by Kristian Kristensen on the March 30th, 2008

    I’ll be attending Ruby Fools in Copenhagen this Tuesday and Wednesday. Add a comment if you’re going and want to meet up.

    I’ve also created an event on Facebook for Ruby Fools. Feel free to join if you’re attending.

  • If you like my writing you should subscribe to my RSS feed.

    MCPD Enterprise Application Development

    Posted in MACH,MCTS,Microsoft,Misc by Kristian Kristensen on the March 30th, 2008

    It’s been pretty quiet around here, but now I have something to write about. In my last post I wrote about passing the MCTS Distributed exam, and that this meant I was on track for the MCPD Enterprise Application Development exam. Well, this Friday I took the exam and passed with 860 points. So I’m now officially an MCPD. This page with statistics of the number of MCP’s worldwide states that there are 3424 persons that holds this certification. The numbers are from January 2008. Somehow that doesn’t seem like a lot of people.

    Anyway, I followed the recipe that seems to work for me. Read the Self-Paced Training Kit book and do practice exams. I read MCPD Self-Paced Training Kit (Exam 70-549): Designing and Developing Enterprise Applications Using the Microsoft .NET Framework cover to cover, and did practice tests like MeasureUp.
    For some strange reason I didn’t get a score report after my exam, so I can’t comment on how well I performed on different areas of the exam. However, I can comment a bit on the types of questions I was asked. Most of the questions involves a fair bit of text, stating requirements for a specific solution. The solution is then proposed and you need to answer if the solution fulfills the requirements and if not why not. It’s still multiple choice, but a tad more difficult than your standard techie questions. Mainly because they’re looking for a specific solution. And the answer is not always how you would go about doing it.
    In summary after taking this exam I don’t find it particularly difficult if you’ve studied some kind of computer science or software engineering. A lot of this stuff is pretty basic, and easily approachable.

    With the MCPD out of the way I don’t know what my next certification goals should be. Maybe I should focus on SQL Server or some Biztalk stuff. Maybe focus a bit on the Infrastructure and Server exams, which I’ll have to go for later this year anyway. I’ll keep the blog posted.

  • If you like my writing you should subscribe to my RSS feed.

    Next Page »