Twitter Bot Proof of Concept – Twitter4r

Posted in Ruby, Twitter on January 13th, 2009 by Alan Hietala – Be the first to comment

While at #geeklunch today the subject came up about spreading events via twitter but without having to follow absolutely everyone that might want to post an event. I proposed a solution of creating a mini twitter bot that would retweet anything that was sent to it via direct message from anyone on its white list. I’ve thrown together a little proof of concept and it works nicely. Took some digging as the Twitter4R documentation leaves something to be desired but it works quite nicely.

require('rubygems')
gem('twitter4r', '0.3.0')
require('twitter')
require('time')
 
#array of authorized users
@authUsers = ["alanhietala"]
login = "xxxxxx";
password = "xxxxxx";
#method to check if a user is authorized to post
def isAuthorized?(user)
 return @authUsers.include?(user);
end
 
 
 
# start main script
 
#make the connection to the bots account
 
twitter = Twitter::Client.new(:login => login, :password => password);
 
 
# get the private messages of the bot 
messages = twitter.messages(:received);
 
messages.each {|message|
  #TODO: process the message for commands
 
  #check if the sender is authorized to send messages
  if(isAuthorized?(message.sender.screen_name))
    #retweet the senders message
    status = Twitter::Status.create(
       :text => "RT "+ message.text,
       :client => twitter);
 
 
  end
 
 
  #delete the message from the server because its been processed
  twitter.message(:delete, message.id);
 
}

I’ll hack away at this some more and throw it into cron on a server some time later this week. Feel free to take this code and hack it to death.

CSS Classes as a Javascript Interface

Posted in Javascript on January 11th, 2009 by Alan Hietala – Be the first to comment

In many frameworks, display code is separated from business logic. An MVC pattern is one of the many ways to accomplish this. When writing javascript featuring heavy UX changes such as in a sidebar it is very helpful to split up the data/state code from the pure animation code.

To accomplish this we use the CSS class as the interface between the two. This has the added benefit of letting two different developers work on those aspects separately with a minimum of integration issues in the end. Additionally this gives us the ability to reuse our ajax calls in different contexts.

In the following example we have a simple ajax enabled sidebar that loads data when a section is opened. The “interface” is the structure of the sidebar defined beforehand in xhtml.

 <div class="sidebar">
        <div class="sidebaritemheader">
        </div>
       <div class="sidebaritem">
        </div>
        <div class="sidebaritemheader">
        </div>
       <div class="sidebaritem">
        </div>
</div>

This simple layout defines the interface that the animation and data aspects of the javascript will use. Each part needs simply attach their events to the appropriate element and javascript will fire them when needed. This example uses JQuery but you can use your javascript framework of choice, or even do everything from scratch should you me a masochist.

     /**
      * Animation javascript funtion
      */
     function animate(){
       //animation code here
     }
    // populates the sidebar data into the given container which is a jquery object
    function populateSidebarData(xmlResult,sender){
        //generate sidebar data items xhtml 
          //fill this out yourself         
 
        //calculate the insert container from the sender object
         var sidebarItems = $(".sidebar").find("sidebaritem");
         var index = $(".sidebar").find(".sidebaritemheader").index(sender);
         var container = sidebarItems.eq(index);
 
        //insert it into the container
       container.innerHTML = sidebarInsert;
    }
 
   //getData method
function getData(populateMethod,sender){
   .ajax(.....
    //in the success section
        ,success
              populateMethod(xmlResult,sender);
    }
}
   //main onload method
    $(document).ready(function(){
 
         $("sidebaritemheader").click(animate);
         $("sidebaritemheader").click(function(){
              getData(populateSidebarData,$(this));
 
          });
    });

as you can see the animation code and the data code are nicely separated and could even be tackled by 2 different developers if the complexity demands it. With this decoupling achieved you can be sure that any changes to the data code are not going to have repercussions in the animation code which I’m sure you’ll agree is a very good thing.

If you want to decouple this even farther, you can tell your designer to use a completely separate set of css classes for the visual markup and to not touch the data related ones. This ensures that your designer cannot inadvertently break the other ajax on the page.

Palm Yet Another Mobile Platform, or is it?

Posted in Mobile on January 9th, 2009 by Alan Hietala – Be the first to comment

When I first heard that palm was releasing another mobile platform I was rather skeptical. Mobile developers have a glut of platforms to build on, and to reach the majority of devices need to write for most of them. You can see why adding yet another mobile platform into the mix might be problematic.

My fears were abated though when I saw how simple, elegant and easy to develop for, the new palm devices are going to be. The entire environment seems to be built on webkit so all of the applications are built using standard xhtml, javascript and CSS. It is no surprise the new OS is called WebOS.

Palm Pre Official Video Tour from Gizmodo on Vimeo.

Does this sound familiar because it should. Firefox exensions are built in the exact same way. This method is nice becuase it lets a designer mock something up in xhtml and it is immediately useable by the phone delveloper. This is a huge benefit to rapidly building applications. The interesting thing is that many of the great firefox extensions may be fairly easily ported over to palm. This is purely speculation on my part but not outside the realm of possibility.

I am definitely looking forward to this device it looks like it will hold its weight agianst the likes of Android, iPhone, Windows Mobile, Symbian et al. Matias Duarte and his team has done a great job in terms of usability, there are a lot of things I here that I wish were on all devices now. Good showing Palm.

Blog Resurection

Posted in Uncategorized on January 2nd, 2009 by Alan Hietala – Be the first to comment

I’ve resurected my blog that had been sitting stagnent for a while. I’ve moved it to my own hosting and switched over to WordPress. I hope to post a lot more frequently. Hope you enjoy.

Test of Microformatter

Posted in Uncategorized on December 12th, 2008 by Alan Hietala – Be the first to comment

this is a test of our awesome office

PlanetEye Office

119 Spadina Ave, Toronto, ON, CA

43.64687, -79.39547

API’s, IDE’s an Idea

Posted in Uncategorized on December 1st, 2008 by Alan Hietala – Be the first to comment

I’ve been dealing with some API’s lately some better designed than others. One thing struck me while I was coding away. wouldn’t it be neat if your IDE could show you what methods were usable based on a set of preconditions for those methods?

Here is an example of what I mean. Method 1 requires nothing but the object to be initialized. method 2 requires authentication and therefore either the object to be initialized with the correct information or have an authentication property set. If these conditions aren’t met the intelisense would show the method as not having all of its preconditions met and you would know that something else needs to be filled out in order for your code to execute properly.

Granted, if the API is built properly an exception would be thrown that would let you know what was wrong, but alas not all code is created equal.

one good way would be to support this type of metadata in the comments much like how javadoc etc is generated. It could take the form of // pre:this.constructor(string, int)||this.someproperty = set

meaning that this method requires the constructor to have been called in its string, int overload, or that someproperty is set.

This would help big time in a compiled language as no compile would be necessary to catch oversights. It would also help with code genereation as a developer could simply select the precondition they want to fill out and have it show up in the code nicely.

This would also have a nice side effect of developers having incentive to write comments something that are often too few and too far between.

Software Testing and Bias

Posted in Uncategorized on December 12th, 2007 by Alan Hietala – Be the first to comment

I was reading a brief article over on Lifehack.org about Confirmation bias. Essentially it boils down to the fact that people are more likely to seek out confirmation that what they have done is correct. In doing so they may overlook tests that don’t fit the solution that they have in mind.

The article gives the example of sets of 3 numbers that satisfy an unknown set of conditions. When people are presented with one known correct answer of [2,4,6] they assume that the pattern is [2x, 2(x+1), 2(x+2)] and don’t bother to supply sets of numbers that fall outside this assumption. Through doing this they may miss a key aspect of the unknown set of conditions and assume that what they have derived is correct. If the pattern that gives a correct solution is any even number, all of the tests that are derived around the initial incorrect assumption will pass, but the true nature of the conditions that yield a correct set is still not properly explored. In this situation only a small subset of correct responses are assumed to be correct.

In software testing this type of bias can lead to test cases that only test the obvious output and input. Most bugs appear when input outside the norm is passed in and A good tester will not only test for a correct result from well formed data, but a correct result for garbage data as well.

Another form of bias that the article talks about is clustering bias. When a person is presented with a number and then asked to answer a numerical related question such as how many countries are there that end is stan, they will cluster their responses around the number they were given previously.

In software testing this type of bias can lead to test cases that are similar enough that they don’t test anything else of real value. All of the test cases need a very specific aspect of the code that they should test. If your tests for different functions are cut and paste jobs from other functions chances are you’re going to miss something.

The testing mindset is one of assume the code is wrong, what would prove with reasonable certainty (we’re not writing proofs for shuttle navigation software here) that your own assumption is incorrect. Falling into one of these biases when writing test code will render your tests next to useless as the likelihood that something important gets missed will increase dramatically.

Spaces, My Favourite Leopard Feature

Posted in Uncategorized on December 10th, 2007 by Alan Hietala – Be the first to comment

I’ve been using leopard since launch and I have to say that spaces is fantastic. I find with a multi monitor setup spaces truly shines. With only one monitor I find there isn’t enough real estate to display applications that are related to a specific task, but with 2 or more, spaces shines.

Currently I have Parallels running on one monitor and a web browser in the other. Spaces was made for parallels, running a virtual OS full screen lets me easily switch to my other applications running in another space, without having to pop out of the full-screen mode of parallels. The other benefit of this setup is that your dock is visible in one monitor while parallels is full-screen in the other.

Once all of your applications are set up in their appropriate space, switching between tasks is simple. ctrl 1 brings up my email and iTunes, ctrl-2 my IM, ctrl-3 is reserved for random applications that I don’t have a space for, and ctrl-4 is my Parallels work space.

I’ve found I’ve been able to stay focused on a task without being distracted as much which is a great additional boost in productivity.

If you’re running Parallels I suggest highly that you upgrade to Leopard, spaces makes it well worth it.

HTTC The Raid Coalition That Could

Posted in Uncategorized on December 6th, 2007 by Alan Hietala – Be the first to comment

I haven’t been playing World of Warcraft in 8 months or so but the organization that I started Horde To The Core is going strong. Comprised of people from many guilds across the Durotan server it is one entity that has survived through the worst a low pop server can throw at it.
i
I think part of the reason it is still so successful is that from day one I was actively ensuring that each role could be covered by multiple people. Yes, I could have let my ego get in the way and ensure that I was the “Main Tank” all the time but this does little to grow the survivability of the organization.

By encouraging others to try their hand at leading the raids, I was never in a situation where a raid could not go on because one or two key people weren’t there.

The major thing I have learned from this is that it is essential that you let the natural leaders that are a part of your team have a chance to shine. They are incredibly valuable but if I didn’t leave my ego at the door they would have never been able to carry on leading raids and making HTTC even better after I stopped playing.

The sense of community that HTTC creates is like no other. Without fostering that community HTTC would have crashed and burned. By balancing praise and constructive criticism everyone feels like they are having fun but also contributing and learning at the same time.

All of these angles have come together to make HTTC one of the most successful raiding organizations on Durotan.

Whether in a game or managing a software team, These lessons apply to all as they are about keeping people happy and productive.