Posts de ‘Gabriel Falcão’

[Gabriel Falcão] Avoid python pitfalls and be happy

Thursday, January 21st, 2010

This morning I was just reading the feed, when I stumbled on this post about one of the weird behaviors of lists in Python.

In a few words, lists and dictionaries behave like C pointers, thus they are mutable objects.

So, if you are beginning on python, you probably will like those articles:

Hope it helps :)

[Gabriel Falcão] Solving “connection refused” issues on Debian Sid

Tuesday, January 5th, 2010

Some weeks ago I started to experiment some network issues on my debian sid:

  • The selenium-remote-control was not running:

I could even try to do a: “telnet localhost 4444″, it just did not work.

  • My Apache-Solr was not capable to subscribe to apache-activemq

When reading the log, I saw:

javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:280
Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused
Suddenly I noticed something weird in my netstat:
tcp6       0      0 :::8983                 :::*                    LISTEN      3865/solr-globocom
tcp6       0      0 :::8161                 :::*                    LISTEN      3901/activemq-globo
tcp6       0      0 :::61616                :::*                    LISTEN      3901/activemq-globo
tcp6       0      0 127.0.0.1:41879         127.0.0.1:61616         ESTABLISHED 3865/solr-globocom
tcp6       0      0 127.0.0.1:61616         127.0.0.1:41879         ESTABLISHED 3901/activemq-globo

Everything is being bound as IPv6… humm, that doesn’t have a good smell….

Looking for solutions I’ve found this file:

/etc/sysctl.d/bindv6only.conf

interesting, huh?!?

Openning up that file, I saw a full description of it, then I just needed to change its property from this:

net.ipv6.bindv6only = 1

to this:

net.ipv6.bindv6only = 0
Well, if you have the same problem, jsut change that, restart your PC, and be happy!

[Gabriel Falcão] Introducing Sponge, a python web framework aimed on testing

Tuesday, September 1st, 2009

Sponge first prage

Some time ago, a friend of mine created a cherrypy-based continuous integration application, we both work with Django, but we think that its stack is too big for simple web projects, specially when we do not need to access SQL databases.

More on Django

In adition, I think that Django-powered applications are hard to make unit tests, mostly related to the fact that models, templates and other django helpers need the DJANGO_SETTINGS_MODULE environment variable set, which turn its tests wired.

We have created a few patterns to make Django projects unit-testable, but it is for another post :)

Are you trying to say that Django is not a good framework ?

Nope! I work with Django, and I just LOVE Django, that is a great framework. Its models, forms, and everything else are awesome, and help me to write web applications without much effort, thus keeping high level of quality.

So, why did you create another framework ?

As I’ve just said some posts ago, I really enjoy agile, and I use to write simple web applications that does not demand the whole Django stack, and I need to have agility to write my tests.

CherryPy is a good solution for me, I don’t want another huge-ish framework, even if its based on cherrypy. I just need a few helpers functions, and a pattern to follow.

Idealizing sponge

Bernardo and me wrote a few web applications with cherrypy, and always focusing in TDD, we needed to create some helper classes to cherrypy. Sometime after, we figured out that those helpers could be grouped in a simple library, or a kind of tiny framework.

I started some mashups, and Sponge has been developed.

The name comes from the fact that a sponge can be used to dry stuff. We like the concept of DRY, hence the name :)

Sponge has been developed with TDD, but that is not all.

I’m trying to keep 100% of code coverage in both unit + functional tests, at minimum. It’s because 100% of coverage does not assure that the code works. Lines of code can be covered with some tests, but the same lines can have one or more different behaviours that won’t be found with 100% of coverage.

Principles

  • Help and incentivate developer to write unit and functional tests
  • Less friction as possible
  • Be simple to configure
  • Be simple to deploy
  • Be 100% testable, specially with unit tests
  • Provide pretty URLS through a rails-like syntax
  • Be as most compliant as possible, with package-systems, such as APT
  • Free software (LGPL-3)
  • Comes with jQuery javascript library and 960 grid system
  • Fun to use :)

Hands on!

Installing

If you are using Debian Unstable, just run:

sudo aptitude install python-sponge

If not, you will need, unfortunately, to use setuptools:

In this case, just grab the bleeding edge version through git:

git clone git://github.com/gabrielfalcao/sponge.git

Or just the latest stable relase:

Sponge 0.3.1

Extract, if needed, and run:

sudo python setup.py install

Tutorial

Sponge comes with a simple tutorial within its documentation, but you can access it online

[Gabriel Falcão] Emacs + Snippets

Sunday, August 16th, 2009

People use to joke on me about the fact that I use EMACS, some say that I even need to use my toes to acomplish EMACS commands, and so on…

But I keep being even more productive, and every day I figure out new ways to improve it.

I really use EMACS the whole day, I keep editing anything with this awesome editor.

This weekend I was starting a new project, and as I use to, I was needing to repeat  the same GPL headers at every file.

So I found myself questioning if it could be more productive than inserting rough templates on my files.

Then I found out this yasnippet, which is totally awesome, and made me be even more productive.

For those who also like emacs, I share my emacs configuration on github.

There is a screencast that I made. Is a EMACS snippet demo.

[Gabriel Falcão] Bolacha, httplib2 wrapper with cookie handling and file upload.

Sunday, August 9th, 2009

I really like httplib2, but unfortunately it does not oficially support sending multipart/form-data.

So last Monday I was at work, and realized that I was needing exactly to make a http upload from within a python program, and also needed to make a session login right before.

I remember that I needed that before, but I could not find something simple and concise, yet pythonic and well tested.

So I decided to work on a proof of concept, 2 days after that, at last wednesday, I got really sick. I thought was just a simple flu, but I got even worst. Going to hospital, doctors found out I have sinusitis.

So since wednesday I am at home, having lots of damn medicines.

But the good thing is that I got time enough to hack :)

So I would like to introduce you Bolacha.

You can see de docs here

There is a debian package available here

The code is available at my github page: http://github.com/gabrielfalcao/bolacha/tree/master

[Gabriel Falcão] New projects + agile = releases

Sunday, July 5th, 2009

When I lived in Belo Horizonte/MG, I used to make hack parties with some friends of mine (nothing to say about all those pizzas and beer).

The hack parties had no specific goal, but a main idea: Hack some free software, and share the knowledge.

Many of us, but specifically Lincoln and I, used to create new projects in every hack party,but only a handful of those were actually released. It was often matter for jokes like: “Oh, you are up to raise the “too many projects” exception”.

I have two words for that fact: “not agile”.

Our projects were often POCs, and we had no culture of TDD, short releases and so on.

But since I started to work at Globo.com, I learned so much about agile, specially Scrum. And some months ago I’ve just accomplished what I call as “agile feeling”.

I mean, it’s a feeling that I can deliver software with quality in a short period of time.

But how ?

The idea is quite simple, you just have to follow some principles:

Think simple

This basically means focusing at the problem at hand, never trying to solve future problems you don’t have. Most of the time the problems your foresaw will never happen, yet you spent a lot of time preparing for them.

Test before programming

Write tests for small parts of your software, they will be very modular, and you will get a trust-able software, and I can assure you that you will be 100% able to embrace the changes.

Release fully functional versions, with simple features

As human beings, we want to embrace all possibilities and solve all possible problems at once.

But this is not agile at all. Talk to your client, be pragmatic, he will like to listen the truth: “You can not ship a full-featured final version of software within the term. But you can totally ship a primary version, fully functional, with all the basic needs of the client. Keep improving the software in next releases”

I tried to summarize those thoughts, but I need blog posts for each one.

Applying those thoughts to personal projects

As I said, I have unfinished projects, and they are still unfinished, mostly because were started with a non-agile approach, and I can’t get interested to finish them.

But there are a few projects I worked in, and others I am the creator. For instance:

  • Dead Parrot, a pythonic RESTFul framework django-based. Is on release 0.1-hellopolly, being used within some globo.com projects.
  • Ma-Chérie, a simple filesystem-based web application to navigate through pictures. Current release: 0.1
  • Sponge, a tiny web framework built on top of CherryPy and used Genshi as default template language. Sponge is the base of Ma-Chérie. Current release: 0.1
  • Pyccuracy, s BDD acceptance testing tool. Heynemann started that project, as a comitter, I worked in the biggest refactoring. Current release 1.0.3-viagra
  • Sleepy, is a crude, slow and rough template language, 100% based in regular expressions (which mades sleepy so slow). Actually I do not plan release it by now,  I am just having some proofs of concept of how possible is to write a template language 100% regex based, just with TDD.

All projects above, except Sleepy, were released as well, all them were developed with TDD and have  a good code coverage.

But the big deal is that, actually they will never get finished, for a simple reason. They will be in continuous development and continuous released as well.

By the way, if you want to contribute, just go to my github profile and check them out.

[Gabriel Falcão] Eclipse + Java + UML + RESTful, the real silver bullet

Wednesday, April 1st, 2009

Some days ago I was just thinking about all these agile bullshit.

I mean, no matter if you do TDD or not, if you do care about continuous integration, this is all a real lose of time.

When thinking about shipping good software, the best combination is, indeed, quite simple:

  1. Use a powerful IDE. You as developer don’t even need to now how the things work, let the IDE do everything for you. Eclipse is the one you really need.
  2. Use a well known, certified and reliable language. Why using dynamic languages ? You don’t need to be agile, you need to ship something with trust value, so build it with java.
  3. Don’t code, use wizards and boilerplate generators. Once again, what is better, easy money or thousands of hours hacking things from scratch ? You can use UML-based code generators, and super-duper eclipse plugins to generate your code. Forget all stress and make your project manager happy.
  4. Prepare yourself for possible future needs. To build a real scallable application you must ALWAYS use a complex SOA approach, so you can separate business-rules in each module and distribute in many servers. A RESTful approach is even better. Forget everything about agile software development, your customer doesn’t need a term, he needs a full-featured project.

To but it bluntly, Fred Brooks was totally wrong in his book “The Mythical Man-Month”, about “no silver bullet”, the steps below are, indeed, a silver bullet and you can see proofs of this sentence in the “Martin Flawler’s” article.

[Gabriel Falcão] Geeks from venus eat geeks from mars at breakfast

Saturday, January 31st, 2009

Many of my friends (maybe, so many) are geeks, but i’ve recently noticed that they are forked in two kinds thus I found completely fair to name as “Hedonistic Geeks” and “Parnasian Geeks”. Therefore, the hedonistic ones can also be labeled as “geeks from mars”, thus makes the parnasian ones from “venus”.

The hedonistic geeks

They keep doing computing stuff every single day of their lives, but it’s kinda enough for them. The rest of the days (vacation and weekends), are free day in which they feel the social duty of keeping at least a bit away from their computers.

Most of them have videogames such as Wii and XBOX, and it works like a “more social life”, they use Macbooks, and do use softwares such as iPhoto, Safari, Quicksilver and so on. Oh… yeah, I almost forgot, they use to have an iphone too.

Putting bluntly, hedonistic geeks can define themselves as geeks or not, because they don’t always accept their geekness to everybody. They are too cool for doing programming, hacking and stuff through the free days.

The parnasian geeks

Parnasian geeks love what they do, love what they are good when doing. They do programming and hacking for work, and keep doing it at the free time for fun.

They prefer Thinkpad as macbook, EMACS or VIM instead of Coda or Textmate. They dont have videogames, because they just can’t waste their hacking time playing videogames.

Instead, they create softwares suck as linux kernel, GNOME apps, python true stuff and so on.

Parnasian geeks are romantic with their geekness, and if they decide to don’t geeking in the free time, will not be playing videogames, but looking for people to have a real social life, to dance, to make the difference. And even to look for a partner to get married and keep their specimen in this world.

To be continued …

[Gabriel Falcão] Hosting and deploying django apps on Dreamhost

Tuesday, December 2nd, 2008

About two years ago, I’ve signed up to Dreamhost. My goals were and still being to host my personal projects, websites and so on.

Once I am a Django web developer, one of my first actions were to create a django deployment setup, good and flexible enough. The time passed on and have been got new experiences, and the best desision, i think, was to create a new python sandbox, i mean, a customized python environment.

How is it possible ?

Simple! Just compiling python from scratch, with a fake root path (a prefix)

Anyway, the deployment process involves more variables, like setting both htaccess and dispatch files for each project, installing some basic modules such PIL and MySQL and so on…

So, i ever wanted to create a super duper script to do all that “dirty” work. And i did it last weekend!

I were working ia a freelance job and decided to create a subdomain to host test instance of them.

A new sandbox, ready to make my tests to create the super script.

So folks, i present you the brand new: django_dreamhost.sh :)

It’s composed by 4 files:

  • django_dreamhost.sh itself
  • djangify.template - a template with will become a script to setup new projects (htaccess and dipatch files, for instance)
  • htaccess.template - a template that will become the .htaccess of each project of yours
  • dispatch.template - will become the dispatch.fcgi for your projects as well

“But do i need to download all them ?”, of course NO!

You just download the main script, and he will do all do hard work!

“I wanna contribute, modify or do anything with that script, can I ?”, of course yes! All parts of the script are GPLv2 +

You can also always get the development version through git repository:

git clone http://git.nacaolivre.org/django_dreamhost

Don’t want to get all code, just the script ?

Download it at: http://gnu.gabrielfalcao.com/django_dreamhost/django_dreamhost.sh

What does that script do ?

He will do the following steps:

  1. Download Python, Django, Python-setuptools, Python-fastcgi to a directory called downloads
  2. Extract all
  3. Create a local root at $HOME/.myroot and the subdirs etc and usr
  4. Set the new bin path to you global path through bashrc and bash_profile
  5. Compile and install python to the new prefix: $HOME/.myroot/usr
  6. Install Django, rename django-admin.py to django-admin
  7. Setup your bash-completion to support django scripts
  8. Install the python modules above with the new python
  9. Install PIL and MYSQL modules through easy_install (setuptools)
  10. Download the template scripts to $HOME/projects/script_templates
  11. Replace the custom tags in templates
  12. Move the djangify.template to the new bin PATH: $HOME/usr/bin and give it execution permission

I thinks it’s all.

I currently use Fabric to help on deployment, and i have a quite smart basic setup for it to work with this dreamhost django environment, but it will be approached in the next blog post :)

See you, folks!

[Gabriel Falcão] Graduation done!

Saturday, July 12th, 2008

Today i’ve reached my first graduation.

It’s funny to think that i’ve made a friend during the course, but he wasn’t from my class, actually, he done another course, but our classes joined to some lessons. The funny fact is a long history….

The government of Brazil have a project who support students with “high scores”, paying private universities, this is really awesome and give great oportunities to people who could not get it by themself.

The thing work like this: You make a test, based on your score, you can choose a range of different courses and universities.

So, this dude, Glauco, choose as first option the course of “Free Software Technology” and as second option he choose “Web development technology”,  and I choose the inverse: Web developement as first and Free Software as second option.

The funny fact in all this is because we got the inverse of first options. So if nowadays i know, develop and give my blood trying to help free softwares, maybe Glauco should be in my place, and I in yours, but i am so happy to this haven’t happened :)