Choosing a database and hosting an app on a Raspberry Pi


This week I attempted to make my own application centered around energy and green button data. However before even working on that app I ran into a speed bump. The default database that comes with django is sqlite3 and while this suffices for tutorials and pre-production apps it does not fair as well for production applications, especially for hosting on popular virtual servers like Heroku. For my purposes I wanted to start with the right database even during test production because migrating databases is a challenge I would rather actively prevent. The popular database for web applications is postgresql because of the many advanced features that come included. I decided to go with postgresql as my SQL database of choice because it is recommended as a best practice from the book Two Scoops of Django.

I had many options for hosting my database and hosting this test production app, I could use a one year free trial of Amazon EC2 to host the application and scale appropriately for more users later on. I could push my application to Heroku and use their 5 mb of free storage. Or I could self-host the application and database through my own home-built server. Because I had a raspberry pi that I was playing with I decided to make this miniature $35 computer my home test server. This small computer might not be able to handle tens of thousands of users an hour but it has been known to be able to handle a few thousand users an hour. Because I have an 8gb sd card in this little computer and the energy cost to run it all year comes out to about $7 this actually makes economic sense for test production. It took a bit of time to sort out which database to use for django, setup my raspberry pi server, and understand the appropriate services to host one’s application but I am now ready to get back to coding my app!

Here are the tutorials I used on setting up a postgresql database using Ubuntu, and settting up my raspberry pi server!


Machine Learning, Django, Git, and Virtual Environments in Python

This week I have learned some of the best practices for coding including using a virtual environment for my python packages and using Git as a way to keep a log of my codes throughout projects. The benefit of running on a virtual environment is that the many packages that Python offers are constantly being updated and one may update their packages and not realize that a prior program they made is no longer compatible with the new package. This is where virtual environments come in handy, they store older versions of packages so that your work environment can be frozen in time for that given project while you can start a new environment for your next project that requires up to date packages. The VirtualEnv package can be found here and it is a must for running any applications on a server.

The second tool that I am learning is Git and the tool called GitHub. I am still in the beginning phases of realizing the power of git but so far from playing around with it it offers the potential to take snapshots of your project as you move along so that if something breaks you can tell git to move backwards to any point in time you desire. This is one example of the uses of git. GitHub is a repository for code and collaboration and many of the Python tutorials that I have done have code stored on GitHub.
I completed a very simple machine learning task on Kaggle using the Random Forest Algorithm from SciPy. This expired competition is called Predicting a Biological Response and I scored in at about #358 out of the 700 submissions. I also completed most of the videos as well as various exercises for the Andrew Ng led Machine Learning course.

To further my Django application development skills I finished the book Instant Django 1.5 Application Development and all of its exercises. This was a great applied way of building web frameworks quickly. Solely reading about web development from a book is not effective for me with regards to retaining material and this books excels in being a feet first applied approach.

Learning Django from Scratch and by Example

Let me preface with a quick summary of what Django is and why learn it. Django is a pythonic means of constructing a web framework quickly, not to be mistaken with the Quentin Tarantino movie. When building a web application many of the moving parts are universal among all web applications from moving data between databases to creating user accounts. The other popular web framework constructor is Rails which uses the Ruby language. Since I have chosen Python as my go to language learning Django was a natural extension to my self-education. It goes without explaining that web applications are replacing standalone installed programs. Companies such as Microsoft are moving office to the web, and many many other SaaS or Software as a Service companies are turning to the web as the medium for providing a service. My personal goal is to become knowledgeable of web app development and in my free time create tools online that benefit society, hopefully from a sustainability angle.

From last week’s exercises I found that I learn best through example. So I decided to take the same approach with getting started with Django. There are many good books out there on Django but since I am interested in only Kindle e-books, having my entire library accessible digitally is vital, I chose to go with Instant Django 1.5 Application Development Starter. The advantage of this book is that it is still relevant, as of this posting the latest version of Django is 1.6, while one of the main resources out there The Django Book is admittedly outdated. Instant Django is a relatively short book that assumes basic competence with Python but no prior knowledge with web development. I have worked through 1/3 of creating my own simple question and answer app and though not everything makes sense yet this has been a gentle learn by example exercise.

Learning Python Rapidly – Where to start and how to find the Programming Community

My objective this year is to become a master of python or at the very least proficient enough to pick up someone else’s code and hit the ground running. The nice part about python compared to other languages is that the forced use of indents makes reading the code of other authors smoother because the indentation makes it easier on the eyes to spot blocking of for loops, if statements, etc..

This weekend I completed all the python exercises provided by Google’s Python Class. Google’s coding lessons are highly efficient when learning the basics quickly. I started my python journey by completing the exercises in Learning Python the Hard Way and I am currently reading Mark Lutz’s Learning Python. I think all of these resources were essential to improving my understanding but I think the best order to study Python is start with Google’s Python Class, then Learning Python the Hard Way, followed by the exercises in Learning Python. I am currently attending the San Diego Python User’s Group which is a Meetup organized around the passionate study of Python.

The people I met have been very enthusiastic and supportive of my goal to become a better programmer. I go to the library at least four times a week for a three hours programming learning session and it can be a solitary journey at times. This San Diego group of Python programmers, a group at all levels of experience, has been a great resource for encouragement and vision of where I can be if I continue to pursue this creative outlet.

By the way the IDE or Integrated Development Environment that I have chosen to start with is PyCharms and the community version is free. I have heard of other good IDE’s namely Spyder, Eclipse, and a few others but I went with PyCharms because of the compatibility with multiple operating systems and ease of use. While I am learning Python I am also learning Linux, specifically Ubuntu 12.04 LTS, at the same time. I used to question why anyone would try to learn Linux when they could stick with the OS they know such as Windows or OS X. It took me about one week with the book The Linux Command Line to get on my feet walking. I will never willingly buy another Mac or Windows OS again. The first advantage I came across were two simple command line instructions in Linux called “sudo apt-get update” and “sudo apt-get upgrade”. In Windows or Mac OS X one must manually update Flash, Safari, Word, etc… one by one on a weekly if not daily basis. In Linux “apt-get update” grabs the newest updates from repositories and “apt-get upgrade” updates all your software. I am pretty pleases with Ubuntu so far and it is my preferred OS for getting work done.