Ruby

How to use cookies with Goliath middleware

This is a great article that I just posted to my companies website!  Check it out!

http://www.polyglotprogramminginc.com/cookies-with-goliath-middleware/

[...]
Published on Thu, 02 Aug 2012 01:36
0 comments

Creating a simple Adhearsion app with XMPP in Adhearsion 1.2

 

Ahearsion has many features including the ability to integrate with XMPP to send messages via jabber.  Unfortunately the documentation did not get the attention that we wanted to give it in this version so here is a tutorial on how to get XMPP working with Adhearsion.  Our app will create a Adhearsion app that will send a message to various users whenever a new call connects and disconnects from our rudimentary application that will be joining two calls together. This tutorial assumes that you are familiar with the basics of Adhearsion and are able to create a basic adhearsion app that uses an Asterisk server.

 

pre-requisites

You will need an Ruby dev environment,  a Asterisk server and a Jabber server.  For this example I am going to use a Ubuntu box and install ejabberd via

 

“apt-get install ejabberd”  

 

Once you have that installed you will need to create a  few users.

 

ejabberdctl register adhearsion <ip address of server> <some password>
ejabberdctl register client1 <ip address of server> <some password>
ejabberdctl register client2 <ip address of server> <some password> 

 

When we connect everything up we are going to be communicating between the various users via direct messages.  It is also possible to use a MUC (what might more commonly be called a chat room),  but that will not be covered in this tutorial.

 

Asterisk has a number of settings.  For this example my files are set up as follows.

 

extensions.conf

 

[default]
exten => 101,1,Dial(SIP/client1)
exten => 102,1,Dial(SIP/client2) 
exten => localhost,1,Dial(SIP/localhost)
exten => blink,1,Dial(SIP/blink)
exten => _.,1,AGI(agi://localhost/adhearsion)
exten => _.,n,Hangup

[from-sipp]
exten => _.,1,AGI(agi://localhost/adhearsion)
exten => _.,n,Hangup

  
sip.conf

 

[general]
tos=none
dtmfmode=info
allow=alaw
allow=ulaw

[127.0.0.1](!)
type=friend
callerid=112
host=dynamic
canreinvite=no
context=from-sipp
dtmfmode=rfc2833
qualify=2000

[client1](127.0.0.1)
[client2](127.0.0.1)
[blink](127.0.0.1)
[localhost](127.0.0.1)
 

Without going into a long explanation these are setting up accounts and extensions for users called client1,  client2,  blink,  and localhost.  You should be able to use your favorite sip client to connect to your asterisk server after you start it up with any of these 4 users.

 

Now we will create our basic Adhearsion app.

 

ahn create jabber_app

 

edit the config/startup.rb file.

 

In it you will find a XMPP section.  Uncomment the settings and set them to match your local xmpp server.

 

  config.enable_xmpp :jid => 'adhearsion@<ip addres of ejabberd server>',
                      :password =>  <secret>,
                      :server => <ip address of ejabberd server>,
                      :port => 5222

 

outside of the “Adhearsion::Configuration.configure do |config|” you will also want to add the following in the same file.  These are global variables that we will be using in out dialplan,  and are not required for XMPP support.

 

$agents = {:client1 => :free, :client2 => :free}
$extensions = {:client1 => 101, :client2 => 102}

 

For this demo we are going to be registering with ejabberd as the adhearsion user from the Adhearsion application.

 

You will also need to add the blather gem to your gemfile

 

gem ‘blather’ 

 

and install it

 

bundle install

 

Adhearsion XMPP support uses a gem called blather.  There is some documentation on how to use it at their site,  but at the time of this writing I could not find any documentation describing what I was trying to do. 

 

When you enable XMPP support Adhearsion includes Blather for you.  Now make sure that your ejabberd server is running.  Lets test things out to make sure that everything is running correctly.  First we are going to set up a jabber client to make sure that our server is working correctly.  In Adium that is as simple as setting up one account with client1 and another as adhearsion using

 

Jabber ID:  ‘adhearsion@<ejabberd server ip address>’
Password:  ‘you account password’

 

Using one up for adhearsion and client1.  Once you have done that send a test message from adhearsion to client1@<jabberd server ip address> .  If everything is working correctly you will see the message pop up under the client1 account.

 

Now go to a command prompt and from your adhearsion app directory and start up the adhearsion console via

 

ahn start console .

 

For our app we will only be sending outbound messages,  so lets create a Blather message object and populate it.  At the console prompt type the following.

 

msg = Blather::Stanza::Message.new
msg.body = “Friday hugs from Adhearsion”
msg.to = “client1@<ejabberd server ip address>”
msg.from = “whoever you want”

 

Now you can send it via the adhearsion reference to your open chat connection client via

 

XMPP::Connection.client.write msg

 

If everything is working correctly you should see a message pop up from Adhearsion to your client1 account in your chat client.

 

Now for the final pieces to finish out our application.

 

Add the following code to your dialplan.rb file

 

from_sipp {
  agent = $agents.index :free
  if agent
    $agents[agent] = :on_call
    extension = $extensions[agent]
    message = Blather::Stanza::Message.new
    message.to = "#{agent}@#{$xmpp_ip_address}"
    message.body = $agents[agent]
 
    XMPP::Connection.client.write message
    dial 'SIP/blink'
    $agents[agent] = :free
    message.body = $agents[agent]
    XMPP::Connection.client.write message
  end
}

 

now make sure that you have accounts set up in your sip client for client1,  client2,  localhost,  and blink.  If you dial localhost you should see a message pop up from adhearsion to one of the free clients and also have a call dial out to the client.  When you pick up the call from the client the two calls will be joined.  Once one of the parties hangs up a message will be sent indicating that the call has been ended,  the call will be hung up and the client will be set to a free state. 

 

There is a lot of other stuff that can be done with this,  but this should be enough to get you started using XMPP in Adhearsion.

[...]
Published on Wed, 04 Apr 2012 04:23
0 comments

git-flow and Agile

For a long time this has been something that has really bothered me.  git-flow was first introduced in this article http://nvie.com/posts/a-successful-git-branching-model/.  A lot of projects have adopted this workflow.  It is a great standard mechanism for managing a project when you need to work with lots of features,  different release branches etc.. 

 

The problem is that I have had trouble really seeing where the level of complication added to a project by git-flow has really added value to the project that is Agile.  Now before we go any further let me add a caveat.  I come from a background of favoring a continuous deployment model with anything I develop.  While some may disagree with me,  this is the model that I think most projects should adopt.  This is where you really get your bang for the buck with Agile.  But even if you are not doing continuous deployment,  if you are doing TDD and CI git-flow still feels like overkill.  It seems to run contrary to the reasons that we use TDD and CI.

 

So why do I feel this way?

 

First,  lets look at the basics of TDD.  We follow this because we are aiming at having all functionality of the application covered with passing unit tests that are frequently checked in.  While there are certain circumstances where you might have a new feature or piece of functionality that will require major surgery to fix that requires going off into another branch this should be the exception not the rule….

 

Second,  if you are creating all of these branches for each new feature then it really feels like you just lost the benefit of CI even if you are doing CI on every branch.  Now you either have to set something up,  or create infrastructure to put a CI build on every branch,  but more importantly,  where is your continuous integration with your main branches such as dev and master when every feature is in another private branch?  To me this is a smell.  But that is assuming that you push your feature branches up to a main server.  The page that introduces the git-flow says that feature branches usually only exists on a developers repo and not origin.  At that point we have majorly undermined the purpose of using CI.

 

Third,  continuous deployment,  and in my view the spirit of Agile,  say that changes should be checked in often and be shippable (even if a story is not complete) at any point in the development cycle.  The entire philosophy behind git-flow goes against that. 

 

For some projects git-flow is probably a great tool,  but to me I am having trouble seeing how it would add any value to most projects that are following a sprint schedule or doing Kanban.  In fact I would argue that if you are doing TDD,  using CI,  and practicing some form of continuous deployment and feel that git-flow will solve your problems you should take a step back and look at how you are using those tools.  Maybe there is a scenario where these would make sense….but I would sooner think that the need for using git-flow on an Agile project is more of a project smell that indicates that something else is broken.  I would love to hear what you think,  so please feel free to comment.

[...]
Published on Tue, 14 Feb 2012 03:39
0 comments

Talking about Adhearsion around the world

So it has been over 9 months since I have done any blogging.  The main reason has been that I have been extremely busy working on a new project called Adhearsion with a really cool company called MojoLingo.  This has given me the opportunity go to conferences to talk about the project.  In the past six months alone I have been to 6 conferences including The Ruby Hoedown,  Adhearsionconf,  Startech Chile,  RubyConf Argentina,  RubyConf Uruguay and Rubyfuza. Mojolingo encourages me to get out to talk about Adhearsion and keep my skills current.  This is in sharp contrast to my previous three years of working for large companies where I was lucky to attend one conference in a six month period usually having to fight to get time off and paying for it myself.

 

So how do the conferences stack up? 

 

The Ruby HoeDown - If you live in the Southeast it is the best value going.  It is a very inexpensive conference with some very high quality speakers.  The after parties are good,  and a lot of hacking happens there.  If you go and want to stay connected to the net for hacking I would recommend that you bring a 3g or 4g device to tether to.

 

Adhearsionconf - I am biased here,  but this is a great conference.  Last year we had about 30 people show up.  The quality of the attendees was great and it was also in one of the best cities for tech....San Francisco.  If you work with Adhearsion it is worth the trip for both the content of the conference,  rock solid net connectivity,  one of the best cities for tech...and plenty of sight seeing activities if you want to tour around.

 

Startechconf Chile - Last year was the first year for this conference that had somewhere between 800 and 1000 people.  I have to say that I was very impressed.  There was nothing quite like getting up on stage in front of 800 developers to do a lightning talk.  As with many large conferences Internet connectivity was a little touch and go,  but being a first year conference I'm sure that will improve in subsequent years.  The talks from Startech are all across the board and cover multiple languages and technologies over three tracks.  It's a shame that this conference was on the same dates as Rubyconf Brazil because it would have been nice to catch both.  There is a rumor afoot that there is going to be a Rubyconf Chile sometime this year or next which should be interesting.

 

Rubyconf Argentina - This was scheduled two days after RubyConf Brazil and StartechConf.  It was perfect for using one big trip to hit multiple conferences.  The quality of the presenters was excellent,  the food was good and the venue was really cool.  From looking out in the audience it looked like there were about 350 people over one track.  As with many conferences Internet connectivity was touch and go,  but overall it was a great experience.

 

Rubyconf Uruguay - This is a very well funded conference that was held two days after Rubyconf Argentina.  They even gave comp tickets to people who's talks were not accepted.  This was held at the Entel conference center which ensured that the Internet was amazingly fast.  The other thing that I really liked was that the conference center had desks at many of the seats in the stadium and plenty of power outlets.  The talk quality was really good.  With what appeared to be about 150+ people spread out over one track it was the smallest of the three conferences that I went to in South America.  One of my favorite pieces of the Rubyconf Uruguay was the ferry ride to and from Argentina where I had a chance to hang out and trade tricks and tips with Sean Cribbs and Arron Patterson.

 

Rubyfuza - This has thus far been my favorite of the Ruby conferences.  It is much smaller than the other ones,  but the quality of the presentations was really good.  The thing that I really liked was that it was small with just under 100 people attending.  This allowed you to really get a feel for the group.  It also had the highest quality food of any conference that I have been to and some fantastic cappuchinos.  Unlike some of the conferences where there the drinkups where sponsored,  but not the meals,  meals for both nights were paid for by sponsors and the drinks were your responsibility (something I prefer).    They also followed it up with a code retreat with Corey Haynes which was awesome!  Between the Code Retreat and that main conference I met some really great people both from the International speaker community and from South Africa.  The South African presenters were at a level where they could and should present and conferences in the US and Europe. 

 

On benefit to the conferences in South America and South Africa is the time of the year they are held at.  The South American series was held in November which means that you will have long days and warm weather which for me was ideal.  With that being said South Africa really takes the cake.  Rubyfuza is held in the beginning of February which is an ideal time to visit Cape Town and South Africa is stunning.  I say that even-though this was my third time travelling to this part of the world.  The mountains in Cape Town are beautiful,  you have the beach,  Table Mountain,  Robben Island numerous wineries,  Chapman’s Peak and some absolutely wonderful restaurants.  Rubyfuza also happens within a week of Scaleconf which is a web scaling conference in Cape Town.  If you shop around for your ticket you will also find that it will cost about the same to fly from the US to South Africa as it does to travel to South America.  In my mind this makes it the perfect way to combine two awesome conferences and a holiday.  If everything works out next year I am going to try to go down to Cape Town for a month so that I can work from there,  enjoy the weather and attend the next version of this awesome conference.

[...]
Published on Tue, 14 Feb 2012 02:30
0 comments

Sproutcore tips and tricks

The information on the sproutcore tutorials is a great start for creating an application,  but once you veer off that path you get into uncharted territory.  Here are some things that I ran across while creating an app that connects to a RESTFUL web service.

  • When your creating a view,  to get data into an object you need to use bindings.
  • Values are set via the controller
  • if you bind to arrangedObjects you will need to set the content attribute for that controller
  • when you are using loadRecords you need to have a unique key value.  If you don't have a data field named guid you either need to change the default key in the model you are importing into to.  
  • If you have a compound data structure being returned from a restful call you do not need to persist the entire object.  You only need to ensure that the the data is enumerable.
  • For me I needed to set the results returned from a restful call in the callback function in order to avoid timing issues with the data being set.

 

ie for a flot graph you would have the following in your main_page.js file.

 

graph: Flot.GraphView.design({

    layout: { left: 0, top: 0, height: 400, right: 0 } ,

                  dataBinding: 'MyApp.myController.arrangedObjects',

            optionsBinding: 'MyApp.myController.options'


  })

 

 In your datasource 

 

 

MyApp.MyDataSource = SC.DataSource.extend(


 {


    // ..........................................................

    // QUERY SUPPORT

    //


    fetch: function(store, query) {


        // TODO: Add handlers to fetch data for specific queries.

        // call store.dataSourceDidFetchQuery(query) when done.


        if (query === MyApp.MY_QUERY) {

            SC.Request.getUrl('/some_request/all').header({'Accept': 'application/json'}).json()

                    .notify(this, 'didFetchStuff', store, query)

                    .send();

            console.log("got response");

            return YES;

        }


        return NO;

    },


    didFetchStuff: function(response, store, query) {


    data = response.get('body');

    if (SC.ok(response)) {

    store.loadRecords(MyApp.MyModel, data.some_nested_structure.isEnumerable ?       data.some_nested_structure: [data.some_nested_structure]);

    // I am binding to a flot object so it would look like this.





    my_flot_data = SC.Object.create({label: 'My wonderful data',  data : my_objects}); 

    // this will set the value for arrangedObjects that you bound to that controller in your flot display objects under the dataBinding attribute

 







    MyApp.myController.set('content', some_data);

 

   } else store.dataSourceDidErrorQuery(query, response);


}

});




 

 

[...]
Published on Tue, 19 Apr 2011 20:13
0 comments

A Great Quote

If you're writing code and you're not testing it, the code is wrong. I don't 
care if it does the right thing, and people need to understand this. If it 
works by accident, you're still wrong. 


Bryan Liles - Ruby Hoedown 2008

[...]
Published on Sat, 05 Feb 2011 20:01
0 comments

Overcoming the Stockholm Syndrome for Agility

Back in December Chad Fowler posted on dead end jobs and the Stockholm Syndrome. The Stockholm Syndrome is "a name given to the condition wherein hostages develop positive feelings toward their captors despite being held in negative, unfavorable and even life-threatening conditions. Victims of Stockholm Syndrome will even inexplicably stay with their captors even when given the chance at freedom." Chad goes on to examine how this can happen in the workplace. You can read the entire article here.

http://chadfowler.com/2010/12/30/dead-end-jobs-are-you-suffering-from-stockholm-syndrome

 

Recently a colleague shared  a Dilbert comic that drove home something that I had been saying for a while.

Though the Dilbert comic is funny the sad thing is that the threat of "not being a top 20% performer" or "do this or we will fire you" is something that affects way too many sotfware engineers in various organizations. Far too many of these engineers are the lower 80% of pool*. The top 20%-50% know what they are worth, get frustrated and leave. While Agile is supposed to provide a safe environment where empowered engineers can say "no", this is not really the case in these shops that are attempting to be Agile. 

 

Right now the engineers who are empowered are the ones who know what they are worth in the open market and are not afraid to say "no". They are not afraid to say "no" to long hours on a project that was severely understaffed and given an unrealistic timeline. They say "no" to missing a scheduled vacation, professional conference, being asked to take time away form activities that keep them current/focused/productive to participate in the latest project fire drill. They say "no" to hacking together code because they take pride in their work and feel that professionalism means that you hold yourself to a certain standard of software quality**. They reject arguments that you must idiot proof designs for engineers with a low skill level (net negative producing programmers). These threats are meaningless to them because they know what is happening in the industry, and know that these threats, and the harsh words that they receive from management for doing the right thing have as much credibility as a drug addict lashing out at their counselor. For these individuals, if management follows through with the threat of firing them they will have another job, probably with a pay raise within two weeks.

 

Agile is all about people over process. CMM, due to it's inefficient nature has a larger tolerance for the lower performers. Agile on the other hand doesn't function unless you have 60%-70% top performers. When you put together a team of these top performers, get out of their way and let them loose it is amazing to see the innovation and velocity that comes from these teams. I have seen it first hand.

 

But many of the failings of Agile efforts go beyond engineers and are often are rooted in having non technical people running a technical projects. It is a recipe for failure. If you are running a software project, selling it or whatever and you do not understand the process of developing software and do not have a deep understanding of what works, what doesn't work and the current industry best practices then there is a high likelihood that your effort will either fail or produce sub-standard results ***.

 

One of the best frames of reference I have for this is the start up community. There are lots of business-type people who have ideas for companies that are strict technical plays. There is just one problem, they have no idea about tech. Every time I see that, I can predict the outcome of that startup. The other anti-pattern is when you have a technical team but take Angel money from someone who has no idea about tech start ups. These companies have a much higher failure rate because grossly under-qualified individuals are empowered to drive insane decisions that, in many ways are not unlike the requests/demands we get for fixed scope/fixed budget projects using antiquated/inappropriate technologies that generate lots of content for sites such as the daily WTF. The sad thing is that they create a lose-lose situation for both parties. 

 

As we move into the next decade and beyond society has a large number of problems ranging from demographics to addressing our future energy needs.  Many of these problems are going to require automation and software to solve.  This is why every industry expert is pridicting that demand is going to continue to be higher than the supply for the next 20 years.  The winners are going to be the ones who are able to effectively attract and use this scarce and valuable resource to solve these problems. When workers end up developing The Stockholm Syndrome it hurts the employees and the company. But more importantly it hurts society and man kind because that is one less engineer that is working on solving real problems that to improve the life of everyone.

 

* Look for a posting in the near future on Net Negative Producing Programmers and how they kill Agile projects.

** Bob Martin (uncle Bob) has some great articles on software craftsmanship here http://www.artima.com/weblogs/index.jsp?blogger=unclebob

*** The most dangerous are those who think they understand it but don't.

[...]
Published on Fri, 04 Feb 2011 19:42
0 comments

Tech, The Next 20 years

If you are in the tech industry today it is pretty easy to see who the up and coming companies are and who is in decline. All that you have to do is look at the work environment for their IT professionals. Are they attracting top technical talent? Do they foster that talent and do they do what it takes to keep them, or do MBA's that lack a deep understanding of tech run the show? Do they allow their technical people the latitude to do the right thing or do they constrain them with outdated processes and endless rules down to a two+ page dress code? Yes, this sounds like a lot of corporate environments, but I have also seen my share of startups that have done the same thing......most of which have not had any real success. My favorite examples of this were the tech start up that had a dress code and the one that recently was looking for a senior Ruby On Rails developer with a max salary of 50K with no equity.

 

Tech is on fire right now. Google and Facebook are fighting for the best talent, and everyone else is trying to keep up. With the announcement of Google giving across the board raises and bonus's so people will not leave, combined with the money that is currently going to startups many are speculating that we are in a bubble situation. Anecdotally, I get unsolicited calls on a daily basis from recruiters for Java and Ruby positions.

 

Are those who are claiming that there is a bubble right? Partially.

 

To understand this you need to understand the nature of programming and programmer productivity. Unlike factory work, different programmers have vastly different levels of productivity. The general consensus is that a rock star programmer is about 10 times more productive than a bad (net negative producing) programmer and an average one is about five times as productive. Yet if you look at the salary differentials they do not come close to reflecting the productivity of the engineer.

 

If we were to use developer productivity as a gauge for IT salaries then our lowest producing programmers would be making 30K, mid range ones would be making 150K and the best ones would be making 300K. Minus the guys who have been involved in successful startups that cashed out on stock options this hasn't happened. If you compare the net revenue gain for a company that is effectively utilizing the skills of a top software engineer as compared to that from a cosmetic surgeon, music star, professional athlete, or hedge fund manager IT labor today is a bargain!

 

But developer productivity is missing the point without demand for the systems they create. IT both saves companies money by automating tasks and creates new business opportunities. Look at the amount of time that has been saved via services such as Google Search and Wikipedia or the increased efficiency that the inventory management systems at Walmart has that is able to accurately predict when products will be needed at stores. Given the current unemployment rate many may think that it is displacing those workers. In the short term that may be true, but for the next twenty years demographics are going to be taking workers out of the economy at a pace that we have never seen in the US. Without the aid of this technology we will not be able to provide the same level of services we enjoy today. IT amongst other tech intensive disciplines will be critical in filling that gap.


Companies like Google have figured this out. Their number one asset are the people they hire. Sure they have a lot of IP, but at the end of the day that IP is worthless without talented engineers who can continue to improve and creatively destroy it to drive innovation. That is the nature of tech, and the nature of many of the main line businesses today.

 

So what does this mean.

 

  1. If you are an IT professional, you stay current and you are really good, you have a VERY bright future. If you are a average one you will do ok and if you are a net negative producing programmer you will probably be able to eek by in the third tier IT shops.

  2. One of the dumbest moves you can ever make as an IT professional is to sign a non compete if it is in a state like Georgia or Massachusetts. By signing that one document you could be losing hundreds of thousands of dollars.

  3. If you are running a company you are gong to need to ask yourself where you want to be. If you think you are a tech company and are not paying top salaries (either via equity or straight money etc.) all that I can say is, good luck. Personally I think you deserve to and will fail. If your main business is not tech then you are going to need to ask yourself if that really is the case. Walmart is not a tech company, yet they have some of the most sophisticated computer systems in the world. The advanced tech that powers their supply chain is a critical piece of their competitive advantage.

[...]
Published on Fri, 19 Nov 2010 22:59
0 comments

The GA bar is against Amendment 1

The president elect of the GA bar is against amendment one.  Looks like things could get interesting when the first test cases roll around.

http://gafreedomtowork.blogspot.com/

[...]
Published on Thu, 18 Nov 2010 02:45
0 comments

Vote No to Amendment 1 in Georgia

Georgia is trying to pass an amendment that will strip a workers ability to work for another employer.  The sad thing is that it will actually make the state less competitive and will really limit a persons ability to move from one job to another.  Educate yourself on this issue and if you are in Georgia think long and hard about voting yes to this thing.

Here is what others are saying about it.

http://techdrawl.com/News-Post/Fresh-Voices/KillHB173-T-Minus-22-Days

http://www.startupchicks.net/content/vote-no-amendment-1

http://blog.weatherby.net/2010/10/georgians-should-vote-no.html

[...]
Published on Sat, 30 Oct 2010 04:33
1 comment

RSS