• The Perfect Margarita

    I have finally found the perfect margarita recipe and I just had to share it:

    1 1/2 oz Patron Silver.

    1 1/2 oz Grand Marnier

    Combine those in a mixer with ice and then cut a lime in half and squeeze all the juice from half of the lime into the mixer. Put a dash of salt in the mixer. Shake it for about 20 seconds then pour. Delicious.

    Sweet and Sour and Sweetened Lime Juice is horrible and don't let it anywhere near your drink, otherwise you will end up with one of those horrible things they serve at most restaurants.

    -James

    (0) comments
  • The Lounge Survey

    To help get a better idea of who visits the sites, blogs, and podcasts that make up The Lounge I have launched a simple survey. To motivate people to take the survey we are going to select two random entries to win all 41 of the Manning In Action books, I know that is a prize I would love (except what to do with the Java books?).

    Go take the survey now.

    The survey includes some marketing questions as well as technology questions, when the survey is closed I will make the technology answers public.

    -James

    (0) comments
  • Daily Thoughts - April 15th 2009

    I noticed Sean Cribbs was starting to post a daily blog post about what he worked on and learned that day, I thought it would be an interesting exercise so I am going to try it for the rest of this week and see how it goes.

    Markdown - I have been using RadiantCMS as the engine for the ZerkMedia site as well as the Alt.Net Podcast but I have been just writing HTML for the posts. I have been writing HTML for over a decade but I thought it was finally time to give Markdown a try. It's fairly straightforward and definitely makes posting much easier, although it will take a little getting used to.

    Animated GIFs in Photoshop - I am getting ready to launch a new survey for The Lounge but I needed an ad to do it. I remember doing animated GIFs years ago using little windows utilities, but I finally decided to learn to do it the right way with Photoshop. Turns out it is ridiculously easy using the Animation window (I followed this simple tutorial).

    JavaScript Fun - I have been using setInterval for my ad engine for sometime but today I figured out a nice trick that will help me reduce the amount of Javascript I use... you can pass any expression to setInterval, not just a function name. So I can pass parameters to the function called in setInterval (just remember that if you use variables they have to still be in scope and available). setInterval(myfunction('a','b','c'), 100). I also learned that you can't set a script as the innerHTML of an element and expect it to be run, you need to add it as a child element.

    -James

    (0) comments
  • An Erlang Sequence Server

    **Thanks to Chandrashekhar who in the comments pointed out I could use mnesia:dirty_update_counter to do pretty much the same thing, I didn't know about this function but it looks perfect**

    For a project I am working on I need to have a sequence number assigned to each record in an mnesia table. This is fairly simple in most databases but mnesia doesn't provide this option. The reason I need this number isn't just to be used as a unique identifier, if that was all I need there are other techniques that would make more sense in erlang like using a combination of the node() id and a timestamp: {node(), now()}.

    I need the sequential number so I can perform reporting on the table and keep track of the last record I processed, so I needed the number to be sequential and easy to query on. (I wanted to avoid date parsing)

    So I decided to build a very simple little gen_server, and since it is very self-contained, I decided to release it out on github. Hopefully someone else will find it useful and if nothing else its a good example of working with mnesia and writing a gen_server. (at least I hope its a good example, please let me know if there is something I could improve)

    Using the server is dead simple:

    Sequence = sequence_server:get_sequence(impression)
    

    When you call get_sequence you pass it either a string or an atom and based on that value the server will return the next Id. If this is the first time you are passing in the atom or string then it will create a new record for that value and return 1.

    Here is the meat of the server:

    F = fun() ->
      Return = mnesia:read(sequence, Id, write),
      case Return of
      [S] ->
        Seq = S#sequence.sequence,
        New = S#sequence{sequence = Seq + 1},
        mnesia:write(New),
        Seq;
      [] ->
        SequenceRecord = #sequence{id = Id, sequence = 2},
        mnesia:write(SequenceRecord),
        1
      end
    end,
    {atomic, Seq} = mnesia:transaction(F),
    

    The first line reads from the Mnesia table and gets a write lock. The first part of the case statement is if a record is found for this atom or string value in that case it increments the value, writes it back to the table, and returns it. The second part of the case statement is if there is no record, in which case it creates a new record and returns the number 1.

    You can check out the full source code here.

    -James

    (0) comments
  • Interviewing Scott Porad of I Can Has Cheezburger

    I recently had a chance to interview Scott Porad the CTO (Cheezburger Technology Officer) at I Can Has Cheezburger for a site called CodersLife. In the podcast I talk with Scott about the technologies they use to build one of the funniest sites on the web. We talk about ASP.NET, PHP, application architecture, the cost of using Microsoft tools and technologies, hiring at a startup, startup strategy, and much more.

    Its definitely worth a listen (of course I am biased).

    -James

    (0) comments
  • Talking with Jeremy Miller about Alt.Net

    One of the things I have always liked about the Alt.Net podcast was that it didn't get caught up in the meta arguments about what is Alt.Net and what should Alt.Net be. So of course I managed to ruin that in the first couple episodes since taking over, I do think this is a very good conversation to have and I think it sets forth a new definition and goal for Alt.Net that is focused on being positive.

    You can check out the episode here.

    Jeremy also wrote a great post about it here.

    -James

    (0) comments
  • 3 talks you should watch

    Below are some of the talks that I really enjoyed over the last couple of years, these are all language agnostic and focus on general development practices and techniques. So take some time and watch these great talks:

    What Makes Code Beautiful - Marcel Molina

    This is a great talk that I saw at RubyConf 2007. Some of the interactive pieces in the beginning don't come across as well in the video, but it is well worth it to get through that part. Marcel compares the historical definitions of beauty and how they can be applied to code.

    Aristotle and the art of software development - Jonathan Dahl

    I really enjoyed this talk, the main take away for me was that programming rules and morals are so similar. Once we think of them in this way it makes alot more sense on how we should approach them.

    Writing Code that Doesn't Suck - Yehuda Katz

    This was a great talk that covered the need to focus on your external interfaces, especially when it comes to your tests.

    -James

    (2) comments
  • Erlang: List Comprehensions

    One of the most challenging things about learning a new language isn't just learning how to do something, but more importantly learning the best way to do something. "Best" in this context is of course very subjective, but for me it not only means correctness but also readability, brevity, and following what is the normal convention for writing code in that language. Erlang has lots of ways to do things. I am working on a small solution where I am pulling messages back from Amazon SQS and processing them in Erlang. Here is a piece of code I initially wrote to handle looping through the list of messages and processing each of them:

     process_messages(H|T, SQS) ->
       process_message(H, SQS),
       process_messages(T, SQS.
     
     process_messages([], SQS) ->
       ok.
     
     process_message(Message, SQS) ->
       %%process message here.
    

    I was showing Mark this code and it struck him as strange, the process_messages function is just going through every item in the list and passing it to the process_message function, so a perfect case for map. So I rewrote the code using the lists:map function:

     process_messages(List, SQS) ->
       lists:map(fun(X) -> process_message(X, SQS) end, List).
     
     process_message(Message, SQS) ->
       %%process message here.
    

    This is much nicer and reads better, I could even inline this code if I wanted to but I like the descriptiveness of having a function named process_messages. But, this can be even more descriptive using a list comprehension:

     process_messages(List, SQS) ->
       [process_message(X, SQS) || X <- List].
     
     process_message(Message, SQS) ->
       %%process message here.
    

    An even simpler line of code and once you get comfortable reading list comprehensions it makes much more sense.

    (found a nice Erlang Brush for Syntax Highlighter over here)

    (0) comments
  • Learning Erlang

    Last year I saw Kevin Smith do a presentation at the local raleigh.rb group on this fascinating little language called Erlang. Erlang is a functional language that is dynamically typed. Its true power is that it makes concurrency, one of the most difficult programming problems, extremely easy. One statement that really says it all to me is this:

    In Erlang spawning a new process is as easy and cheap as creating an object in an object oriented language.

    The presentation peaked my interest and I dabbled with Erlang when I had time last year. I went to a couple of the local Erlang hack nights, I started reading the Programming Erlang book, and I checked out the prag prog screencasts (also by Kevin Smith).

    Last week I went to a great 2-day training class on Erlang put on by Kevin down in Carborro at the co-working facility there. This class impressed me for a couple of reasons:

    1) I feel like I finally understand Erlang and I can actually start a project using it.

    2) I normally hate training classes, but this one was actually very effective. It put the focus on writing erlang code in labs, but the labs were just a problem and you had to figure out how to solve it. They weren't the classic step by step labs that are just mindless instruction following, you really had to stretch your knowledge of the language and what you had learned to complete these labs. I enjoyed it so much that I am actually considering trying to put together a training course and becoming a trainer is one of the things I never wanted to do.

    With all this knowledge I have started an interesting little project with Erlang. I am attempting to re-write the reporting section of Adzerk (the software that runs Ruby Row and The Lounge) using Erlang. I have been meaning to separate the reporting piece from the rest of the application (especially from a database perspective) for sometime and this gives me a great excuse. Erlang will make it easy for me to make my reporting system near time, advertisers and publishers will be able to see impressions and clicks seconds after they happen instead of the day after like how it currently works. (I know you could accomplish this in just about any technology, but Erlang makes it easier to do this and to scale in the ways I want to).

    So if you are looking for a new language to pick up this year I would encourage you to try out Erlang. I plan on using it more and more and will be posting interesting tools or tricks I find to this blog.

    -James

    (0) comments
  • New Publishers joining The Small Publishers Room

    This was originally posted over on the Zerk Media blog but I wanted to cross-post it here since I think everyone should be subscribed to these blogs.

    Over the last month or so a number of new publishers have joined the Small Publishers Room. With some of our members moving to The Silverlight Room there was room to take on additional publishers. Here are the new additions:

    Corey Haines is currently a freelance developer and journeyman, traveling around to pair-program with other developers.

    Dave Bost is a Developer Evangelist with Microsoft and co-host of the Thirsty Developer Podcast.

    Mark Harrison is a Solutions Architect at Microsoft UK - and a pre-sales Technical Product Specialist for Office Platform with a key focus on customer solutions for Content Management, Collaboration, Portal and Search.

    John Sheehan is a .NET developer based in St. Paul, MN who specializes in building web applications with ASP.NET MVC, C#, jQuery and SubSonic.

    I am thrilled to have these influential developers and bloggers join The Lounge.

    -James

    (0) comments