From DHTML to Node.js

dhtml-to-node

I’ve been using JavaScript since we used to call it DHTML or something like that. Things have changed dramatically for the language we all used to love hating. There’s is a new community, with new platforms and even a refreshed language about to land with the arrival of ES6.

While writing this blog post I remembered a post I wrote on 2009 when I announced that I was going to learn Python. This blog post is basically about the same thing. I’m going to dive into Node.js.

The only difference is that this time I’ve been using the language for years, if you count all the years I used it without really knowing it. I divide my JavaScript experience in two parts before and after JavaScript The Good Parts.  Reading that book made me realize that JavaScript was a real language and not just a thing you had to use if you wanted to get fancy on the browser.

In the past year while working on Blimp I’ve learned a lot about JavaScript and about the new ecosystem that has emerged around things like Backbone.js and Node. Also having an awesome JavaScript developer (@Elving) always around has helped understand the new things a lot faster.

Why node.js?
Simple, the kinds of web apps I want to build in the near future are all going to be using web sockets and trying to do real-time interactions as much as possible. Node was built specially for this kind of thing and seems to be the more performant choice out of the box. It feels like the right tool for the job.

I already have a few projects in mind so my diving into Node should begin pretty soon. I’ll try to keep you posted.

Presentación: Python en Blimp @ #prPIG

xkcd: Python

Este próximo martes, 9 de Abril de 2013 a las 6:30 pm será la cuarta reunión de prPIG (Puerto Rico Python Interest Group) y la primera con el “nuevo formato”. De ahora en adelante en cada reunión tendremos a alguien del grupo o algún invitado especial haciendo una presentación al principio de la reunión.

Para estrenar este formato el martes José Padilla y yo presentaremos sobre Blimp, que como muchos saben está escrito principalmente en Python. Creemos que va a estar bueno y que será útil para todos los interesados en web development no importa el lenguaje que usen, ni el nivel de experiencia programando. Los problemas que tenemos que resolver en Blimp son los mismos que tienen que resolver todos los web developers, no importa si programas en Ruby, JavaScript, Java, C# o PHP.

Así que toda la comunidad de developers de Puerto Rico queda invitada para esta reunión, incluso los no Pythonistas. La misión principal del grupo es crear una comunidad de developers local sin importar los lenguajes. Se escogió Python porque pareció ser bastante popular y la fundación de Python está ayudando al grupo a organizarse.

Hay muchas iniciativas que queremos hacer y estamos sólo empezando. Este es el mejor momento para unirse y aportar a la comunidad.

La reunión se celebra en la oficina de AsoPYMES en la Avenida Ponce de León 452, Suite 403. Esto es en el edificio de la Asociación de Maestros de Puerto Rico en Hato Rey, cerca del Departamento del Trabajo. Hay un estacionamiento amplio y seguro.

Aquí hay un mapa que marca el edificio donde se celebran las reuniones y el estacionamiento.

El grupo está en todas partes así que no hay excusa para no hacer “follow”.

Los esperamos el martes.

Categories
Default

How to fix “foreman’s missing output issue” on Python projects

Since we started using Heroku for most of our projects, foreman has been part of our toolkit. We figured out that if we were going to be using it on the server we might as well use it on our development environments. The only problem that we found was that we were not getting all the output from our apps on the terminal. While hacking on a piece of code I’m used to inserting simple ‘print’ statements until I get what I need. With foreman this was not working.

The solution is very simple. Just create a .env file next to your Procfile, and add this environment variable to the first line PYTHONUNBUFFERED=true That’s it, the next time you run your project with foreman you will see all the output.

You can use that .env file to put all the environment variables you need while running your project. Foreman will take care of setting them up for you. Also know that there’s a plugin for the Heroku CLI that makes easy to grab your applications config vars, and place them in your local .env, and vice versa.

My “other” solution. AppleScript?
Before I found the PYTHONUNBUFFERED=true solution, I was using an AppleScript to start my web projects. I must admit that I still use this for some projects, because it’s very fast.

The script does one simple thing very fast and very well. It opens iTerm2 and creates splits for everything I need to run a project. For the most complex project I have it run the Django development server, Redis, Celery and Brunch. I also create an extra panel ready for doing git commits on the project. The best part is that I can run the command using Alfred (with the run command) which makes it event better. Here’s a video of the script doing it’s thing on a simpler project.

Sometimes I wondered why no one has written a Procfile parser in AppleScript. Here’s the AppleScript I stitched together from various places online.

launch "iTerm"

tell application "iTerm"
	activate
	
	set myterm to (make new terminal)
	
	tell myterm
		launch session "DevelopmentEnvironment"
		
		# Start Django Server
		tell the last session to write text "workon lift && ./manage.py runserver_plus --settings=lift.settings.development"
		tell the last session to set name to "Django Server"
		
		# Start Brunch
		tell i term application "System Events" to keystroke "d" using {command down}
		tell the last session to write text "workon lift && fab brunchwatch"
		tell the last session to set name to "Brunch"
		
		# Panel for git
		tell i term application "System Events" to keystroke "d" using {command down, shift down}
		tell the last session to write text "workon lift"
		tell the last session to set name to "git"
		
	end tell
end tell
Categories
Default

Want to learn Django? Start here.

Today I read a post on HN called Want to learn Rails? Start Here and it seemed like a great idea so I decided to do the same for Django.

This is my collection of web resources for folks who are just getting started with Django. The list contains what I believe is the absolute essential for the total n00b. I added a link to more than 170 videos on various Django topics as a bonus just to give newcomers an idea of how much information about Django it’s out there. What are you waiting for? Get started.

The official Django tutorial – Writing your first Django app

Getting started with Django on Heroku – The easiest way to deploy your projects and free hosting

The Django Book – It’s a bit outdated but still a great place to get started

Django Best Practices – Here you can learn some really good tips on how to organize your projects

170+ Django conference videos – Everything and anything, great resource

Finally a cool tip I just found out about. If you are looking for information about any object in the Django framework you can just type in your browser http://django.me/<any object here> and you will be redirected to the proper page in the official documentation. Try it http://django.me/render

How to host Django apps on Heroku

Today Heroku announced their integration with Facebook. Now, with only a few clicks you can have a Facebook application running on Heroku. This sounded interesting so I gave it a try. But while doing it I noticed something unexpected. The environment option of the Heroku hosting dialog showed PHP, Node.js, Ruby and Python. Wait what? Yup, it seems like Heroku can host Python apps. I don’t know if they announced this or not, but this is news for me.

So, I stopped playing with the Facebook integration thing and started working on getting a sample Django running on the service. After a little trial and error I ended with this instructions.

First install RVM and Ruby 1.9.2

Now add RVM to your .bash_profile

Reload your .bash_profile

Now install Ruby 1.9.2 and set it as the defautl

Install the Heroku Gem and set it up

Now lets start by creating a new folder for our app.

Create a virtualenv for new our project and install all the dependencies

Now let’s create a new django app inside our heroku-template folder

Make the manage.py executable. This is required by Heroku

Finally create a file called Procfile in the heroku-template folder with the following content

Ok that part is complete now lets put everything on a git repo

Now start the Heroku application using the Cedar stack.

Finally

This is how the final folder should look like

That should be it! Happy Hacking.