Scoped Thoughts http://felipero.com Felipe Rodrigues's blog posterous.com Wed, 29 Jul 2009 09:32:00 -0700 Setting-up clojure, clojure-mode and slime with Common-Lisp on Emacs http://felipero.com/1446961 http://felipero.com/1446961

I've been working a lot with lisp lately. I was basicaly using scheme to follow the SICP course described here.
Yesterday I started to read Programming Clojure from Stuart Halloway
So, as an emacs user the first thing I did was look for a clojure-mode. Found one at http://clojure.codestuffs.com/. In fact found more than just a mode, found a slime/swank for clojure. I decided to install it.

First thing to do was install ELPA (http://tromey.com/elpa/install.html), by evaluating (it means pasting the code and press C-j) this code in my *scratch*:

1
2
3
4
5
6
7
8
(let ((buffer (url-retrieve-synchronously
"http://tromey.com/elpa/package-install.el")))
  (save-excursion
    (set-buffer buffer)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (eval-region (point) (point-max))
    (kill-buffer (current-buffer))))

Then I only had to list the packages with
M-x package-list-packages
and then:
M-x package-install
This last command will ask you the name of the package. Type clojure-mode.
After that, the clojure-mode will be installed. The next step is to install the slime/swank for clojure. Once the clojure-mode is installed, it is pretty easy to do:
M-x clojure-install
The installer will ask you where you want to install clojure. I choose /opt/clojure.
Now let's hack our personal emacs configuraiton to enable sbcl (Common Lisp) in our slime.

First, If you didn't choose the default location for clojure (like my case), you will have to add the following line in your .emacs file:

1
2
3
4
5
6
7
8
9
;;; THIS CODE MUST BE UNDER THE ELPA CODE ADDE WHEN YOU INSTALLED ELPA

;; Clojure configuration
(clojure-slime-config "/opt/clojure")

;; Slime configuration
(require 'slime)
;; Adding sbcl to slime
(add-to-list 'slime-lisp-implementations '(sbcl ("sbcl")))

And that's it. When you need to use sbcl (Common-Lisp) you must run:
M-x slime
when you need to run clojure do:
M-- M-x slime
This will make slime ask you what lisp you want to start (tab for auto-completion). If you type clojure it will open the Clojure's REPL, if you type sbcl it will open Common-Lisp REPL.

To finish I don't like to type java -cp clojure.jar clojure.main to start clojure or even to run some script. So I used the clojure-extra found at http://clojure.codestuffs.com/
Added this file to my $PATH variable and created the file .clojure.conf in my home directory, like that:

1
2
3
4
5
6
7
8
9
10
11
12
# Clojure jar file
clj=/opt/clojure/clojure/clojure.jar

# Directory where libaries/jar files can be found
clj_ext=~/.clojure

###
# Various java options:
###

# Memory settings
clj_opts="${clj_opts} -Xms128m -Xmx512m"

You can customize and add things as you wish to your classpath by editing this file.
Done, now you just type clojure and the Clojure's REPL will show up. Have a happy hack.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/94883/Avatar.jpg http://posterous.com/users/jYW0f3uwnv Felipe Rodrigues felipero Felipe Rodrigues
Tue, 21 Jul 2009 15:35:16 -0700 A simple date_select matcher for cucumber with webrat on rails http://felipero.com/a-simple-dateselect-matcher-for-cucumber-with http://felipero.com/a-simple-dateselect-matcher-for-cucumber-with
Media_httpcukesinfoimagescukelogopng_eiypgoeydjjduca

I was working on my project when I decided to check if a date_select was returning with the same value when the model had errors.
My surprise was that webrat have nothing like that on the webrat_steps.rb, so I decided to scratch my itch.

That is pretty simple and could even be improved, but works fine. On your steps definition file add the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
Then /^the selected date for "([^"]*)" should be "([^"]*)"$/ do |field, date|
  field = field.tr('[', '_')
  field = field.tr(']', '_')
  year_field = field + '1i'
  month_field = field + '2i'
  day_field = field + '3i'

  date = Date.parse(date)

  field_with_id(year_field).element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{date.year}/
  field_with_id(month_field).element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{date.strftime('%B')}/
  field_with_id(day_field).element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{date.day}/
end

Done! Now you can use that on you @.feature@ files just like that:

1
2
3
4
5
6
7
Scenario: Add an invalid new task
    Given I am on the tasks page
    When I select "December 25, 2010" as the date
    And I press "add"
    Then I should see "1 error prohibited this task from being saved"
    And I should see "Desc can't be blank"
    And the selected date for "task[due]" should be "December 25, 2010"

Good luck with your specifications!

Media_httpimg294imageshackusimg2949791cucumberhuntjpg_onduibxqdcwcfpe

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/94883/Avatar.jpg http://posterous.com/users/jYW0f3uwnv Felipe Rodrigues felipero Felipe Rodrigues
Mon, 20 Jul 2009 12:15:00 -0700 Ruby 1.9.1, MySQL and Rails on Ubuntu 9.0.4 http://felipero.com/ruby-191-mysql-and-rails-on-ubuntu-904 http://felipero.com/ruby-191-mysql-and-rails-on-ubuntu-904

With the release of Rails 2.3.3 I decided to upgrade my rails projects. Not enough, I decided to upgrade to Ruby 1.9 as well.
So, here is my first impressions:

Ubuntu packages don't have a stable version of Ruby 1.9. They are still offering 1.9.0 and I heard 1.9.1 is much better and stable.
The solution was compile and install from the source.
so, just:
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz
Then just:
tar xzf ruby-1.9.1-p243.tar.gz
and
cd ruby-1.9.1-p243
and
./configure
and
make
and
sudo make install
If everything went fine, you can just remove the src folder where did extracted you tar.gz. This will replace your ruby commando, pointing to ruby 1.9.1. To check that, please, verify with ruby -v
Now you just need to install some gems to make your new ruby world rock. First, install Rails:
sudo gem install rails
 Then, install your database adapters gems:
sudo gem install sqlite3-ruby pg
For mysql, try this: (Wasn't working when I wrote this post)
sudo gem install mysql
If don't work, then you will have to build it from source. Project page at http://www.tmtm.org/en/mysql/ruby
So
wget 'http://rubyforge.org/frs/download.php/51087/mysql-ruby-2.8.1.tar.gz'
then untar the file with
tar xzf mysql-ruby-2.8.1.tar.gz
access the directory you just extracted and do
ruby extconf.rb --with-mysql-config
and
make
Before finish, you can run a test to make sure it works. (You will need to install the test-unit gem):
ruby ./test.rb -- localhost your_user its_password the_database
If everything works as expected, just issue
sudo make install
And that's it. Hope it works well for you and you can enjoy the performance of Ruby 1.9.1

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/94883/Avatar.jpg http://posterous.com/users/jYW0f3uwnv Felipe Rodrigues felipero Felipe Rodrigues
Sat, 18 Jul 2009 10:06:00 -0700 Structure and Interpretation of Computer Programs at YouTube http://felipero.com/structure-and-interpretation-of-computer-prog-1 http://felipero.com/structure-and-interpretation-of-computer-prog-1 Here goes a great series of class available at YouTube. It is a Berkley course based on the great book Structure and Interpretation of Computer Programs.
I came in greate time, since I'm studying Clojure.

 By the way, don't forget to check the other 19 classes on the right bar of this youtube video.

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/94883/Avatar.jpg http://posterous.com/users/jYW0f3uwnv Felipe Rodrigues felipero Felipe Rodrigues
Sat, 18 Jul 2009 08:51:00 -0700 Rails Magazine: A lovely initiative http://felipero.com/rails-magazine-a-lovely-initiative http://felipero.com/rails-magazine-a-lovely-initiative

I've in contact with rails community more frequently lately since I started a new rails project. Before that I was in some Groovy/Grails and Java projects.

Grails and Rails are so similar and both can do basically the same thing. Of course there are situations where one of them will be a best fit for some project.
Besides the technical differences are not so big, the concept of how do things in the framework are not so big either.

The big difference comes in form of community. The rails community is bigger and better than Grails. I don't want in any aspect to degrade the Grails community. They are just like any open source community. But rails community is just different. There are some idealism and they  honor  that in each blog post or each initiative.

A great example is the Rails Magazine. They have a great magazine with actual articles and still offers the PDF version for free (check http://railsmagazine.com/).
Now, Groovy/Grails has a great magazine as well (http://groovymag.com/) but these are not free. The difference in this case is that for Groovy Magazine you have to pay USD $4,99 for the PDF version.

What others differences you see from these communities? What you have to say in favor of Groovy/Grails community?

PS: Please, note that I'm not saying that GroovyMag is wrong in charge. They have this right. I just want to highlight how free and idealist is the Rails community using this example.

Railsmagazine128x128

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/94883/Avatar.jpg http://posterous.com/users/jYW0f3uwnv Felipe Rodrigues felipero Felipe Rodrigues
Thu, 16 Jul 2009 19:12:12 -0700 How about posterous? http://felipero.com/how-about-posterous http://felipero.com/how-about-posterous

I'm not sure yet if I'm confortable with posterous. Looks a interesting idea, but I think I would have to forget about my custom design. At least for now. So, what are the diferences from use posterous and blogger or word press? I still have to figure out.

This unconfort is probably caused by my need to control everything (techincal). I'm looking for a Blog engine, but somehow, the so used engines, ready to use are not the same as somehting I created or at least that I installed. That's why I'm thinking on Mephisto.

Anyway, I'll probably let you all know where I'll publish my notes.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/94883/Avatar.jpg http://posterous.com/users/jYW0f3uwnv Felipe Rodrigues felipero Felipe Rodrigues