:mhfs


Git tag management

Today I needed to manage some git tags for the first time and want to share how to do it.

Create a tag:

git tag "v0.0.1"

Push the tag to GitHub:

git push origin --tags

In case you need to remove the tag:

# delete local tag
git tag -d "0.0.1"

# delete remote tag
git push origin :refs/tags/0.0.1

Cheers!


Setting Ubuntu wireless network via terminal

I have an old laptop that I use as a home server. I wanted to move it away from my workstation and that also means moving it away from the internet router. In other words, I had to setup the wireless connection without any visual assistent.

Turns out it wasn’t that difficult. For a WPA2/AES wireless connection place this into your /etc/network/interfaces file.

auto wlan0
iface wlan0 inet static
  address 192.168.1.10
  gateway 192.168.1.1
  dns-nameservers 192.168.1.1
  netmask 255.255.255.0
  wpa-ssid <NETWORK_NAME>
  wpa-ap-scan 2
  wpa-proto RSN
  wpa-pairwise AES
  wpa-group AES
  wpa-key-mgmt WPA-PSK
  wpa-psk <ASCII_ACCESS_KEY>

If you want DHCP instead of a static address go with this.

auto wlan0
iface wlan0 inet dhcp
  wpa-ssid <NETWORK_NAME>
  wpa-ap-scan 2
  wpa-proto RSN
  wpa-pairwise AES
  wpa-group AES
  wpa-key-mgmt WPA-PSK
  wpa-psk <ASCII_ACCESS_KEY>

Then just run sudo /etc/init.d/networking restart and you should be good.

Note: This assumes you have your wireless card working with its kernel module on. You can check it out with lspci and lsmod.

Cheers!


Slides from my talk at semcomp13

Here are the slides (in portuguese) from my talk at semcomp13 at USP São Carlos yesterday.

You can download the PDF here or view it directly on Scribd.

Thanks to all who attended and feel free to contact me for anything. It’s always a pleasure to talk.

Cheers!

Update: fixed the direct download link.


Make up excuses to learn

I love to study and play with new stuff. I really enjoy this but there’s something that bothers me. My studies rarely result in something useful.

Some weeks ago I was watching one of Giles Bowkett’s screencasts and got caught by a goal he imposed himself some years ago: create a new app every month. Although that seemed a little too much for my available time, the thought itself kept coming back to my mind.

A few days later I was in trouble to sleep and started thinking about something to do with those hours. I knew I’d like to play with Sinatra and explore Selenium usage via Capybara but I decided I wouldn’t do it without concrete outcomes.

I ended up starting the development of a CPF and CNPJ generator which, even though there are dozens out there in the internet and is not very creative, is being useful for me when testing my apps.

Habit changes are tough to achieve and demand constant effort, but I’m totally into it.

Study, play around stuff, but apply it to something you or someone else will use. A real world example will guide your studies and usually takes your first contact with a technology much closer to what truly working with it would feel. And pushing a new app to the wild is always fun.

It’s not new. A lot of people talk about it. Very few people do it.

In case you’re interested, you can view the source code on GitHub.

More apps coming soon.

Cheers!


At Viaweb we had one programmer who was a sort of monster of productivity. I remember watching what he did one long day and estimating that he had added several hundred thousand dollars to the market value of the company. A great programmer, on a roll, could create a million dollars worth of wealth in a couple weeks. A mediocre programmer over the same period will generate zero or even negative wealth (e.g. by introducing bugs).
Paul Graham

If Apple were to grow the iPod into a cell phone with a web browser, Microsoft would be in big trouble.
Paul Graham, 2004

Ruby 1.9.2 + RVM + RubyDebug

UPDATE: This post is outdated. It should all work out of the box now.

I have been investing some time in Rails3 and Ruby 1.9. Unfortunately that also means facing a lot of beta and release candidate gems.

One that I was specially missing was ruby-debug. Looking around I found ruby-debug19 but the Mac OS installation instructions are focused on MacPorts. After some research I was able to adapt the steps to my RVM based ruby install.

First, get rid of possible ruby-debug related gems:

$ gem unsintall columnize linecache linecache19 ruby-debug-base ruby-debug-base19
  ruby-debug ruby-debug19 ruby-debug-ide ruby_core_source

Then you’ll have to figure out where is your ruby source code. Adapt it to your username and ruby version. It’ll be something like /Users/<username>/.rvm/src/<ruby-version>. For me it’s /Users/mhfs/.rvm/src/ruby-1.9.2-preview3. Adapt to your own username and ruby version.

And finally, let’s install ruby-debug19.

$ gem install ruby-debug19 -- --with-ruby-include=/Users/mhfs/.rvm/src/ruby-1.9.2-preview3

You should now be fine. Let me know if didn’t work.

I’d like to congratulate and thank Mark Moseley for the port of ruby-debug to 1.9.

Cheers!


Truly making Rails3 use JQuery

Being myself a JQuery fan, I always make the change from Prototype to JQuery in the rails projects I start.

The addition of the --skip-prototype option to the rails command was certainly a huge progress, but (you’ll probably call me a purist) not being able to use javascript_include_tag :defaults with JQuery used to annoy me.

Not anymore. Reading Rails Inside I figured out there’s a way of teaching Rails what your defaults are.

Just create an initializer with the following content:

module ActionView::Helpers::AssetTagHelper
  remove_const :JAVASCRIPT_DEFAULT_SOURCES
  JAVASCRIPT_DEFAULT_SOURCES = %w(jquery.js rails.js)

  reset_javascript_include_default
end

And now your call to javascript_include_tag :defaults will include JQuery instead of Prototype.

Cheers!


Windows like Home and End keys on the Mac

When I bought an external keyboard to use with my macbook, I had 2 expectations. Stop burning my fingers in the freaking hot aluminum (I live in a hot city) and have Home/End/Delete keys.

My fingers were fine but the Home/End keys didn’t work as I expected. I wanted the same behavior I used to have in Windows, moving the cursor to the begin/end of each line.

After some research I discovered a small trick to achieve that. You can create a file named DefaultKeyBinding.dict under ~/Library/KeyBindings/ with the following content:

  {
      "\UF729"  = "moveToBeginningOfLine:";
      "$\UF729" = "moveToBeginningOfLineAndModifySelection:";
      "\UF72B"  = "moveToEndOfLine:";
      "$\UF72B" = "moveToEndOfLineAndModifySelection:";
  }  

Restart the application and you should be fine.

Cheers!


RMagick and Snow Leopard

RMagick is a RubyGem that wraps ImageMagick’s features.

I never used it by myself but the project I’m working on uses a gem who depends on it.

I installed it twice. In the day I started working in the project and in my dev env rebuild last weekend. Both times it was a PITA. For different reasons.

The first time it was a conflict with a library MacPorts installed which I had to remove. Obviously after a lot of wasted hours.

This time it was a little bit harder to figure out. I installed ImageMagick via Homebrew and then installed RMagick via gem install. The installation went well and I wrongly assumed everything was fine, but when I tried script/server I got a frozen process. No error messages.

After a lot of research I discovered that even though RMagick 2.12.2 (latest available gem) compile against ImageMagick 6.5.6 (the version Homebrew installs) it only works with ImageMagick >= 6.5.8. My work around was a customized Homebrew formula for 6.5.9.

So, after the story, let’s make things happen.

Download the custom formula here.

Someone told me brew install -i <formula> would work, but it didn’t, so copy the file to /usr/local/Library/Formula/ and then:

$ brew install imagemagick_rmagick --with-ghostscript
$ gem install rmagick

That should make you ok.

Ruby 1.8.6 note: it seems ruby 1.8.6 has an issue with RMagick and Snow Leopard. You can see all the hardcore details here. It’s safer to go with 1.8.7.

Homebrew note: I created an issue asking for a ImageMagick formula update. The custom formula won’t be required soon.


Rebuilding my development environment

Some time ago I had to compile some libraries for a project I’m working on and that made me realize my machine was all messed up.

It had ruby and mysql manually compiled into /usr/local, imagemagick installed via a package, postgres installed via macports (arghh) and some other stuff that I don’t even recall compiled via different install scripts. I was also trapped to a single ruby version.

One may say it’s not a big deal but to a control freak like me, that’s more of a mess than I can leave with.

I guess my lack of familiarity with a Mac took me to that point and I finally decided to put some effort on rebuilding my environment.

I’m not the step-by-step kind of guy, so I’ll just present the tools that I now rely on and made the difference to me.

Homebrew is a recipe based package installer that’s becoming very popular. It’s great and the formula library is growing fast. It beautifully organizes everything into /usr/local and have a great symlinks approach. Very easy to install and uninstall stuff. Some basic dependency resolution is also present. It quickly gave me wget, mysql, postgres and imagemagick. Take a look on the list of recipes.

RVM or Ruby Version Manager is a sweet gem which allows you to have multiple versions of Ruby installed in the same machine and easily switch among them. Gem sets is a cool feature it offers which allows you to jail that app which purpose seems to be using all the gems out there.

One more cool side effect of using Homebrew and RVM is that I no longer need to use sudo all the time.

Hope it works well for other people like it’s working for me.

Cheers!


Get to know Heroku

If you’re looking for a hosting solution for your Rails app I have a suggestion. Try out Heroku.

It’s a git based deploy solution really easy to get running and with a decent free plan for small apps.

Once you start getting more traffic/data you can dynamically scale resources.

My blog is running on a free Heroku plan for a couple of months now and I have no complaints. I have some difficulties when deploying it but their support were great even for the free plan. And it was my fault on the .gems file anyway.

Now that I feel comfortable having tested it with my blog I’ll start migrating/deploying some other apps to it.

And keep an eye on the AddOns. They’re getting better everyday.

Cheers!


Apple Brazil Fail

Apple recently launched their online store in Brazil and I immediately ordered a full keyboard to use with my hot-as-hell-macbook.

The order was placed and processed on Oct 6th. The delivery was initially supposed to happen in 3 to 7 business days. From Oct 9th to Oct 15th.

Yesterday, Oct 7th, I received another email telling me they were sorry to inform my order would be shipped only on Oct 23th and could take up to Oct 30th to get to my home.

So I ask:

Incredibly, It seems they still didn’t learn the lesson.

Very frustrating first experience. Specially considering all my expectation. I mean, it’s Apple.

Where’s Tim Cook, the master of distribution and logistics?

Cheers!

Update: after all the mess with my order they ended up delivering the keyboard today, Oct 14th.


Craziness

Every year in Brazil 60000 people don’t receive appropriate Radiotherapy treatment due to lack of equipment.

Specialists estimates the country needs a 100 new machines.

And people celebrate Rio 2016.

Cheers!


Finally some good Police work

In my humble opinion there was a major public security happening in Rio de Janeiro last week.

An asshole tried to rob a drug store and found himself surrounded by the cops. As a good robber-asshole-coward he took a women as a hostage and started threatening to explode a hand grenade (understanding how a drug store robber was in possession of a grenade is something reserved to Brazilian people).

The cops started to negotiate and things seemed to go bad when something I’d never expect happened. A sniper shot the guy in the head. No injuries to the hostage. Being myself a victim of several robberies and other violence acts I felt really great about it.

I hope his family cries the tiers of all his victims families and his children misses all the money he robbed from someone else.

Video on YouTube

Looking forward on watching more of those.

Cheers!


Enki Blog App

Since my move from PHP to Ruby some months ago I was desiring to move the PHP systems I use to something Ruby based. Mainly this Blog which originally used Wordpress.

My personal stuff has always been a tech playground and I was missing it so I started searching for alternatives. I looked into Mephisto, SimpleBlog and Radiant but they all looked more of the same. I was aiming on something I could have more control of and ended up facing Enki Blog.

Enki is a no fluff, straight Rails blog app, conceived to allow developers to dive into it and customize whatever they want. It’s like a ready to use blog scaffold I can evolve in any way I want.

The migration process was very simple with the help of this simple script.

In some aspects it represented a couple of steps backwards but it will allow me to evolve in another directions more easily and, hopefully, more interestingly.

ps.: I’d like to thanks Wordpress for the good moments I had with it. Also, not choosing Mephisto or Radiant doesnt’t mean they aren’t good. I use Radiant myself for my company website and love it.

Cheers!


IE6 No More

Weebly had a great initiative to finish this web curse called IE6. If you can support it somehow don’t think twice.

www.ie6nomore.com

Cheers!


Amazon accepting Snow Leopard Pre-Orders

Just a heads up on Amazon’s Snow Leopard pre-order release yesterday (I guess).

They’re charging U$ 29,00 and there’s a money back guarantee if they lower the price before shipping day.

No expected date tough. Go Apple!

Here’s the link: http://www.amazon.com/Mac-version-10-6-Snow-Leopard/dp/B001AMHWP8/


Replace TextMate Drawer

With the switch from my old Vaio to a MacBook I finally had the chance to dive into TextMate. And I have to say that it is what all the people say of it. Awesome software.

But like every software it has its drawbacks and one that bored me a lot is the drawer file browser which seems to doesn’t be part of the window itself. A quick google search showed me I wasn’t the only one who don’t like it and took me to the textmate-missingdrawer plugin. Easy to install and delivers what the name states. Worth a try.

See the result below.

Cheers!


Installing Ruby on Rails Environment on a Mac

When I got my MacBook I was in the middle of a RoR development project and needed to get everything up and running really quick. After trying a couple of approaches and wasting a lot of precious time I ended up in this Hivelogic article.

My unique intention with this post is to offer a straight answer on how to setup a RoR environment. Follow their guide. You’ll get everything up even if it’s the first time you’re looking to a Mac.

Installing Ruby, Rubygems, Rails, and Mongrel on Mac OS X 10.5 (Leopard)

Cheers!


Netbeans Error: Rails requires RubyGems >= 1.3.1

I have been working with Netbeans on a daily basis for a while and every time I load it up I get an annoying “Rails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update —system` and try again.” message.

Since I’m using it just as an editor, not making use of its embeded Rails environment, I ignored it for a while but today I decided to face the problem and solve it definitely.

If you already tried to run “gem update —system” in your Netbeans JRuby folder you know it just says there’s nothing to update and the errror message persists. After some research on the web I discovered the rubygems-update gem.

To make use of it, just go to your JRuby folder (usually C:\Program Files\Netbeans 6.5.1\ruby2\jruby\bin\jruby) and type the following commands as follows.

First of all check if you find the home of the problem with the following command which should give you “1.2.0” back.

mhfs@vm $ jruby gem --version

Now type these two commands for the update process to work:

mhfs@vm $ jruby gem install rubygems-update
mhfs@vm $ jruby update_rubygems

And check the version again to be sure you got to 1.3.X.

That should be enough. The message will be gone. If any of you have any problem drop a comment and I’ll try to help.

Update: There seams to be a way to install a newer version of JRuby by downloading it (http://jruby.codehaus.org/:http://jruby.codehaus.org/) and expanding into your “C:\Program Files\Netbeans 6.5.1\ruby2\” folder. Then all you have to do is adding a new Ruby Platform in your Netbeans project properties. Please notice that a new JRuby install means you’ll have to reinstall your gems (if you installed new ones since you first installed Netbeans).

Cheers!


Rails Learning Guide by Me

When I look back to the day I started learning Rails it seems it was more confusing than it should be. Maybe the problem was my approach and anxiety to quickly understand everything. To avoid that you possibly get in the same situation I decided to write something about the steps and resources I’d like to know when I started.

1.Get introduced to Ruby: For this the best resource I got to know so far for someone who already have programming skills is the Ruby appendix of the great Agile Web Development with Rails book by Sam Ruby, Dave Thomas and David Heinemeier Hansson. Not too much. Just the basics for you to understand Rails code. You can buy it online here.

2.Setting a Rails Environment: Well … lot’s of options here. My choice is to install NetBeans for Ruby/Rails. It comes bundled with a full Ruby/Rails environment. Of course you can google for options for different IDEs and OSes.

3.First Contact with Rails: An obvious place that I took a while to notice was the Rails Guides. Their introductory chapter entitled Getting Started with Rails is a must read for a quick overview of Rails architecture and features. If you prefer, the chapters 5 to 13 of the book will work too (I went this way but wouldn’t again).

4.Getting Deeper: My suggestion here is for you to find something to code that you really need. You’ll probably find yourself in trouble and almost everything you’ll need is at Rails Guides topics and the Rails API. Another priceless resource is the community itself. I like to get to them through the #rubyonrails IRC channel on Freenode.

5. Understanding the Rails way: something I noticed about Rails is that almost all the time there is a right way of doing what you want. And it’ll be simple. But it might be difficult to realize it by yourself if you come from another language/framework with distinct paradigms. Somewhere you can find a lot on the right way of doing things with Rails is the fantastic Rails Casts by Ryan Bates.

A general advice would be to read much more than code for a couple of weeks untill you got familiar with Rails. And never forget of you’re good friend Google. Rails has an awesome community who loves to share knowledge. It’s spread everywhere.

If you have any suggestion to this minimal guide do not hesitate to suggest it. In a future post I’ll write something about the gems and plugins I like to use.

Cheers!


Ruby/Rails fading in

So .. as I stated in my previous post Rails felt into my life some weeks ago.

I started looking into it and a feeling that it rocks started growing into me. In the beginning it was difficulty to put that feeling in words. I was getting surprised by features I already knew from Symfony. That was when I figured it out: the first great thing about Rails is Ruby. I’m still far from being a Ruby expert – really far – but I can definitely say that it is a powerful language.

The second thing I couldn’t let by is the hability the developers had to make a lot with a few line of codes. I want to give a simple example about it .

Let’s grab some posts with category id ‘1’ from the database and pass it to the view.

//Symfony
$c = new Criteria();
$c->add(PostPeer::CATEGORY_ID, 1, Criteria::EQUAL);
$this->posts = PostPeer::doSelect($c);
#Rails
@posts = Post.find_by_category_id(1);

Ok … I know a lot of you would say I could create a doSelectByCategory() method inside of PostPeer and I respond to that with “but I would have to do it”. In a large application that would end up with thousands of avoidable lines of code. Every single feature I code in rails feels shorter and much more readable. End of story.

Another small detail that took my attention was the partial engine. The way it accepts both a single object or a collection (iterating through it by itself) plus a view variable being created with the same name as the partial is great. Again .. nothing special but so awesomely handy.

One more example … which way of validating the length of a field looks better for you?

// symfony
$this->setValidators(array(
  'message' => new sfValidatorString(array('min_length' => 4))
));
# rails
validates_length_of       :message,     :minimum => 4

Want another one? What’s the simpler and clearest way of declaring a relation between two of your models?

# symfony - inside a schema file which gives you no visibility in your model
business_unit:
  manager_id: { type: integer, foreignTable: user, foreignReference: id}
# rails - inside your model with fully visibility - read and understand
class BusinessUnit < ActiveRecord::Base
  belongs_to :user, :foreign_key => 'manager_id'

I could continue with that longer and longer … the routing system is great … I would definitely fail to describe in words how fantastic the migration system is.

Rails gave me back my pleasure to develop. And when I finish I look to the result and it’s beautiful.

I challenge you. Go to Rails Guides, read something and tell me you don’t like it. :D

Cheers!

Next: when I started I felt a little bit confused on the way to go. My next post will provide some links and tips on what I believe to be a good way for a newcomer to approach Rails.


PHP/Symfony fading out

Back when I was a college student, around 2001, I had my first contact with PHP. Since that time 8 years had passed and I got really close to it. About 3 years ago I joined a project and had to choose one among several PHP frameworks available out there to use as the base for all the development.

This was when I first got in touch with Symfony. Love at first sight. Compared to the “procedural way of coding” I was used to it was like being instantly dropped into heaven.

Time got gone, code got written, customers got happy and me too. Keeping surfing the delightful waves of great Symfony features.

But like everything else in life, while time went away things that I didn’t even notice in the beginning started to get really annoying.

That’s the case of:

The list could continue a lot longer. But pushing Symfony down is not the point. The point is that even if Symfony is still great and has a lot of fantastic features it simply doesn’t feel anymore like the solution for all my problems like it used to feel.

I have Symfony applications live with which I am pretty happy, Symfony applications under development becoming awesome and I’ll keep using Symfony when it fits specific needs. Probably I’ll even write technical posts about it in here.

But happens that a couple of weeks ago in an afternoon full of Symfony frustration, without looking for it, I found myself in front of a Ruby on Rails blog post. A Rails which by the way I was already been hearing of a lot. Since then I’m investing a lot of free time on it. Sharing this experience will be the objective of my next post.

Cheers!


Comments Count Bug in iNove WP Theme

Well… I was looking into the blog thinking about what would be the next post when I noticed that some unapproved spam comments were being taking into consideration in the iNove theme comments’ count.

A post was stating “1 comment” but when I clicked on that it took me to the post detail page where there was no comment.

After trying a little by myself I ended up asking for help in the #wordpress irc channel on freenode.

Thanks to sivel I was able to correct a small bug in functions.php.

On line 363 (3 below)

function comment_count($commentcount){
  global $id;
  $_commnets = get_comments('post_id=' . $id);
  $comments_by_type = &separate_comments($_commnets);
  return count($comments_by_type['comment']);
}

… should actually be …

function comment_count($commentcount){
  global $id;
  $_commnets = get_comments('status=approve&amp;post_id=' . $id);
  $comments_by_type = &separate_comments($_commnets);
  return count($comments_by_type['comment']);
}

Clear your cache (if you have it enabled) and you’ll be done.

Cheers!