Monday, September 22, 2008

Installing the Erlang Textmate bundle

Came across this script recently that bascially checked out and installed an Erlang TextMate bundle. If you're wanting to install an Erlang bundle into TextMate, this is how you do it.

  1. In TextMate, go to Bundles >> Bundle Editor >> Show Bundle Editor
  2. If you do not currently have "Erlang" as an option in the list of Bundles to the left, go ahead and create a place holder one. To do so, click the "+" sign down below and select "New Bundle". This script you're about to run will create "Erlang" so I'd recommend naming it something like "erlang" or "erlang-tmp".
  3. In this new bundle, add a new command and call it "reload" or "erl-bund-checkout" or whatever works for you. For the "Save" option select "Nothing". For the Input option, select "None" and for the Output option select "Show as tool tip". Then copy and paste in this code into the "Command(s):" text-box:
    #!/bin/sh

    LC_CTYPE=en_US.UTF-8
    SVN=`which svn`

    echo Changing to Bundles directory...
    mkdir -p /Library/Application\ Support/TextMate/Bundles
    cd /Library/Application\ Support/TextMate/Bundles

    if [ -d /Library/Application\ Support/TextMate/Bundles/Erlang.tmbundle ]; then
    echo Erlang bundle already exists - updating...
    $SVN up Erlang.tmbundle
    else
    echo Checking out Erlang bundle...
    $SVN --username anon --password anon co http://macromates.com/svn/Bundles/trunk/Bundles/Erlang.tmbundle/
    fi

    echo Reloading bundles in TextMate...
    osascript -e 'tell app "TextMate" to reload bundles'


  4. That's it!. Now you can run that command by selecting it from the "Bundles" menu and after you do, you'll see a tooltip showing you what was checked now. You will also see the new "Erlang" Language option in the Bundles menu and as a Language option at the bottom of the TextMate window.

Saturday, September 20, 2008

18 sites good web developers must know about

The best web developers are always looking to not only hone their craft, but also for ways to stay updated on what's happening on the cutting edge. With our time stretched so thin as it is, we don't often have time to scour the web for new sites or other up and comers who have something new to offer or something interesting to say. That is where this list comes in. If you're a web developer of any kind and you love what you do, you should at least know about these sites. If you know of a site that you believe should be on this list, feel free to leave a comment telling me all about it. The list of sites that all good web developers must know about (in no meaningful order) are as follows:

  1. Hacker news - For those who don't know, this is a reddit-type news site from the Y Combinator folks. Here you'll find everything from arguments over the state of Lisp to startup advice.
  2. Programming.reddit.com - Reddit's programming section. Similar to Hacker News but often more related to actual programming.
  3. Ajaxian - Ajaxian is a good way to stay on top of developments in the javascript world and the various javascript libraries currently in existence. If anyone of them made any interesting progress, you would hear about it here.
  4. Stack Overflow - Don't you hate sites that hide their useful content behind subscription fees and ads? Unlike other programming help type sites, Stack Overflow is actually quite useful. People ask questions and (most of the time) knowledgeable people answer them.
  5. InfoQ - Decent articles and good interviews with more focus on the enterprise dev community.
  6. Github - It's almost like a social network for developers. You can watch other peoples branches, fork their project and make it your own, donate to projects and a more. Since open source projects get hosted for free, Github is a no brainer for those who use Git as their SCM solution.
  7. Vitamin - Usually a good resource for a broad range of web development related content.
  8. The Daily WTF - What ever you do, make sure you're never doing anything ridiculed on this site.
  9. Lambda the Ultimate - This blog isn't specific to a one programming language or topic over another but it covers a broad range of programming languages and developments, issue and best practices related to them. The forums are also good to peruse.
  10. Confreaks - With this site being more specific to the Ruby industry, this was meant to bring light to sites that offer the same service but for whatever languages/industry you're more interested in. (some other notable sites in this category are Google Video and Omnisio)
  11. Webmonkey - Resuscitated after being killed off a few years ago, Webmonkey is a good place to go for more technical tutorials, a decent blog and quite a few cheat sheets.
  12. Google's Testing Blog - Because we should all be doing it...testing that is.
  13. Google's Code Blog - Good source of good content from a big company full of smart people.
  14. Nettuts - A lot of decent content covering a broad range of topics. From PHP to iPhone developing (nothing to specific there of course, thanks to the nda), they'll occasionally throws interviews into the mix.
  15. DZone - A more focused and more cluttered digg-like site. A good way to find new sources of decent content.
  16. Coding Horror - Entertaining blog that's update pretty consistently. Jeff Atwood (the writer) is one of the two founders (Joel Spolsky is the other) of Stack Overflow (mentioned above).
  17. Math-Blog and Ars-Mathmatica - Because it never hurts to know a little math.
  18. TechCrunch - A good way to find out what's going on with the business side of the internet. If you're thinking of starting your own company, it's always good to check TechCrunch (and CrunchBase) to see if you have any competition and to see how they compare.
Did i miss anything?

Wednesday, September 17, 2008

Running Edge Merb and Datamapper

Merb and Datamapper are the new hotness. We all know it. To be able to currently use them to their fullest potential, you may want to run both on edge to make sure you're running with the latest fixes and features. The problem with that is that merb and datamapper are splintered into quite a few gems. Enough to make installing each one by hand kind of a pain. To alleviate this page, there are a few sake tasks you can grab for both Merb and Datmapper to make the process of running on edge a little easier. These are the steps that worked for me:




  1. Install Sake


    sudo gem install sake

    First, you'll need to actually install the Sake gem. If you don't know what sake is, check out this post on err.the_blog. Sake tasks are basically system-available rake tasks.




  2. Install the Merb sake tasks


    sudo sake -i http://merbivore.com/merb-dev.sake

    Now you can install the merb sake tasks. We'll use these tasks later to actually install Merb and it's minions.




  3. install the Datamapper sake tasks


    sudo sake -i http://datamapper.org/dm-dev.sake

    And we can't forget about the Datamapper sake tasks.




  4. make a place to download these gems


    sudo mkdir /opt/merb_edge

    sudo cd  /opt/merb_edge && sake merb:clone

    sudo cd /opt/dm && sake dm:clone


    I opted to store them in my /opt folder but feel free to store them wherever you'd like. This will download the various edge gems for each project to your machine.




  5. now install them both!


    sudo sake merb:install:all

    cd dm

    sake dm:install


    These tasks will actually run through and install the various gems we just downloaded. Watch the commands fly by and take comfort in the fact that you didn't have to do this manually.



  6. and that's it! You're now running edge Merb and Datamapper


Sunday, September 14, 2008

The Ultimate introduction to Merb

Hello Merb

Why Merb?

Merb is a Mode-View-Controller (MVC) web-based framework that takes a slightly different different approach to web development compared to that other Ruby web framework, Ruby On Rails. With Merb you can choose your ORM (DataMapper, Sequel and ActiveRecord), template engine (Haml or eRuby).

From Install to "Hello World"

  1. Install Merb and it's dependencies

    To install Merb, all you need to run is

    sudo gem install merb --include-dependencies

  2. Generate your Merb application

    To generate a your Merb app's folder (in this case, we'll call our app "merbtest"), all you need to run is

    merb-gen app merbtest
    This will generate all of the base files and folders for your Merb app.

  3. Fire your app up

    Technically, at this point you can fire your app by just running

    merb
    from your app's root. By default, you'll be able to access your app at http://localhost:4000. You will get the default "Welcome to Merb" page which also tells us, amongst other things, how to get rid of this page (This page also happens to be the 404 page. You can view it in the app/views/exceptions folder).

  4. Setup your routes

    Your route configuration will take place in the config/router.rb file. Like Rails, you get the default route of ":controller/:action/:id" which is fine unless you have a number of "resource" routes and you want to prevent GET requests from hitting your create and destroy methods (or any other method you want to be only accessible via POST). For the purpose of this introduction to Merb, let's set a specific route for our controller we have yet to create. Comment out the r.default_routes and add this route:

     r.match('/hello').to(:controller => 'hello', :action => 'show') 
    . This will map any requests sent to localhost:4000/hello to the hello controller's show method. I guess we should go create that controller.

  5. Creating Controllers

    To create the "Hello" controller, run

    merb-gen controller hello --testing-framework rspec 
    Telling the generator what testing framework you're using lets merb generate the related test files which in our case would be a spec file for our controller and helper we just created. Run
    merb-gen controller
    if you'd like to see the other optional flags.

    Now that we have a controller, all we need to do is define our show method and create the associated view template. Add this to your Hello controller



    def show
    @hello = 'hi'
    render
    end
    and this to your app/views/hello/show.html.erb file:
     say <%= @hello >  
    and that's it.


  6. Setting up your ORM

    As far as ORM's go, I've been wanting to try Sequel, so let's run with that. to install it, run:


    sudo gem install merb_sequel
    and in your config/init.rb add or uncomment

    use_orm :sequel

    Now we have Sequel ready and willing. Run merb in your app root to have Sequel create a sample database.yml in your config folder you can copy from. Your database.yml file will need to look something like this:


    :development: &defaults
    :adapter: mysql
    :database: merbtest_development
    :username: root
    :password:
    :host: localhost

    :test:
    <<: *defaults :database: merbtest_test
    :production:
    <<: *defaults :database: merbtest_production

  7. To actually populate the database we'll need a model and an actual migration to set our table up. Let's start with the model. Run


    merb-gen model book
    And now we have our model and model spec file. To generate our first migration just run

    merb-gen migration add_books_table --orm sequel
    Or, at least it should create the migration for you. When I wrote this, I wasn't getting any migration files created. If you don't get any migration files, create it! Either way, your schema/migrations/001_add_books_table.rb file should have the following:

    class AddBooksTable < Sequel::Migration
    def up
    create_table :books do
    primary_key :id
    varchar :title, :author
    timestamp :created_at
    text :description
    end
    end

    def down
    execute 'DROP TABLE books'
    end
    end

    To actually run the migration, all you need to do is run

    rake sequel:db:migrate
    I'll leave the actual populating of the database with actual data as an exercise for the reader :)

Merb Resources
Like what you see and you want to learn more? Here are a few useful Merb links and resources that will help you get further:

Official Merb site: http://www.merbivore.com/
Official Merb Documentation: http://merbivore.com/documentation.html
Official Merb Discussion Group: http://groups.google.com/group/merb
Merb IRC rm: #merb on irc.freenode.net
Merb Source:
merb-core: git clone git://github.com/wycats/merb-core.git
merb-more: git clone git://github.com/wycats/merb-more.git
Merb Community News/Tutorials: http://merbunity.com/
Merb tutorials, screencasts and news: Merbcast
Popular Merb ORMs
Alternative (to ERB) template engine: