Sunday, January 13, 2013

Code Review: githubsurvivor -- Python web application written in Flask

"GitHub Survivor is a simple bug dashboard that shows an overview of bugs in a GitHub-hosted repo. We use it at 99designs to keep an eye on the bug count and remind ourselves to close bugs."
Interesting concept, nice charts and ability to infer state of git repos by mere glance at dashboard. With Fafadia Tech's continued passion and linking for both Flask and Python, this writeup serves to give you under the hood look at the code with 99 designs open-sourced it about 3 months ago.


  • First quick look at dependencies and packages this project uses:
    • mongoengine==0.7.3
    • Flask==0.9
    • PyGithub==1.6
    • python-dateutil==2.1
  • Apart from now standard Flask + MongoDB setup, this project uses Python wrappers for github APIs.
  • Less is used to for generating css files 
  • Authors have used a Make file with all and cleanup options used to compile from less syntax to css style sheets
  • All static assets is stored in resources folder called res
  • Project configuration is present is external python file: config.example.py (obviously this is just for reference)
  • Jinja2 templating engine is used. All templates exists in templates folder 
  • Template inheritance and block are amongst some Jinja features that are used. Look at base.jinja2 which is extended in most of other templates. 
  • bin directory contains command for setting up, serving and running tasks
  • MVC pattern is followed for organizing code. models folder contains one python file per model, containing document definitions and method calls 
  • sync.py file contains all logic for syncing data from github along with some other helper methods
  • Main webapp logic is written in __init__.py file under web directory 
  • reporting.py file is used for reporting purposes and timeutils.py for handing timezone, date formatting etc

Overall the code is minimalistic and clean. A good reference to learn from.

Thursday, January 3, 2013

Tutorial: Deploy Django app on AppFog


AppFog is PaaS provider which make management of code a little easier. There are bunch of PasS providers out there Heroku, Elastic Beanstalk to name a few. I tried Googling easy to use tutorial for deploying Django app on AppFog couldn't find any so following article is compilication of what has worked for me based on trial and errors.

Before delving into details of the application, there are few pre-requisites we assume

1. You must have AppFog account.
2. You must have virtualenv installed on development machine. Pointer that might help you.
3. You mush have af gem installed locally. Instructions to install.

Optionally you can also you Git hub repo, for version controlling your code. You can find sample code for this tutorial on GitHub.

Steps for Deploying Django app on AppFog

1. Create a New App

2. Select Python Django framework

3. Choose infrastructure Region

4. Wait till the App is deployed

5. Download Source Code

   We need to follow this step because AppFog gives us Jumpstart code with all pre-built configuration incluing but not limited to DB settings.

6. Create Virtual Env and install dependencies

  • virtualenv ~/Installs/env/django-appfog
  • source ~/Installs/env/django-appfog/bin/activate

   This is optional so that we can test our work locally.

7. Update settings and created static files

  • Create directory called static at same level as manage.py file. Run 
  • cd static/
  • python ../manage.py collectstatic
  • Open up setting.py file and import settings
  • Add and change ROOT_PATH = os.path.dirname(__file__) and STATIC_ROOT = os.path.join(ROOT_PATH, 'static')
  • Add following line to urls.py url(r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),

   By default Django doesn't serve static in production, so we need to create separate static folder and put all necessary files. In our case we're going to be checking admin page to see if our static is getting served.

8. Update the Application

  • af update django-appfog
Note: django-appfog is our application name for this tutorial purpose. If you've created a different application name, be sure to use right value. 


The other thing I couldn't figure out was to admin username and password for newly created apps. But couple of posts suggest doing it programmatic or creating an entry in DB, which to be honest for a PaaS solution seems little lame.

Found better solution? Do let us know in comments

Saturday, April 28, 2012

Opensourcing Mac Application to Track Browser History

Jobin Kurian (a.k.a CodeBuster) has been working on creating a Mac application that crawls different browsers including Google Chrome, Mozilla Firefox and Apple Safari. He's written an Objective C code that basically scrapes history from different SQLite files/PList files. Today we're opensourcing the code for this application. You can clone it from github .


If you want to create network diagnostic utility, or forensics utility go ahead and reuse our code. 


Sunday, March 18, 2012

Django Tips

Here are Fafadia Tech we have been toying with Django for some time now, out of frustration of not finding good tips here are some that will help

1. Feature Branching: Until you're working with a bigger team you won't understand value of using Git and feature branching. Code reusability and easy merging are some of the advantages of using feature branching. Although its not directly associated with Django framework it helps while working with non-trivial applications. Do read this interesting article on doing same with Git.

2. Migrations: South is an interesting application which allows you to version changes to your schema. It generates migration files that you can add to your SCM.

3. Maximize use of Django Apps: Django Packages is a great website that has listing of all Django apps. So make sure before you set out to writing your own app see whats available. Django's abstraction on how it treats application makes it easy to swap in/out apps in your project.

4. Beware of Cyclic References: While using Django's ORM, make sure you think through your Model classes, if you're ending up in a situation of cyclic references, group set of classes into same application.

5. Use more of virtualenv, fab & pip: Pro Pythonistas already know tricks of trade for successful Python projects. When deploying/trying to re-create dev environment these tools will save you productive time.

We're playing around with Django Jenkins and Django Selenium to figure out how we can integrate them more in our projects. So expect more articles from us on those lines.

Saturday, December 24, 2011

Meters2Inches Updated



On of Fafadia Tech's first app was Meters2Inches converter. To our expectations it got more actives and installs than we ever imagined. Above table from Android market place gives evidence that simple but useful apps are always going to be in demand.

So in spirit, we are releasing updated version of app today. Although instead of just updating app with existing key(which we lost) we are uploading a newer app. One feature that I though missing was to convert back from Inches to Meters. Give it a try and let us know what you feel.


Monday, December 19, 2011

5 more Widgets released by Fafadia Tech



Fafadia Tech has release 5 widget apps on Android Market place today. Thanks to great effort on Prasanjit Dey and Gaurav Mehta's side. The whole execution was done in less than 10 days. Part of the release following are some of the applications that are available to download

1. Linux Commands
2. PHP Cheat Sheet
3. Religious Quotes
4. Funny Quotes
5. Science Facts

Download it and let us know what you think.

Monday, August 29, 2011

I am Fafadia Tech Part 1 - Yogesh Neman




Starting today we are starting series called "I am Fafadia Tech". Intent of starting these blog series is to recognize excellence in Fafadia Tech's team members. Yogesh is out Employee #1, he has been with us since beginning of the company. His daily job is to keep Fafadia Tech happy. Right from cleaning, helping with supplies and making Fafadia Tech beautiful.
What everyone was surprised was the amount of talent this man inside of him. He hasn't completed his education, he can't write/read English fluently but when it comes to arts he will give you run for the money.



Thanks Yogesh for making this journey beautiful.