Mahdi Yusuf

Mahdi Yusuf


A Developer’s Year in Review

Saturday, December 24, 2011

2011 has been an extremely fun year for me. I have met a lot of new people, built quite a few things. Experienced failure, learned a lot. I believe everyone is by product of all things they experience or force themselves to experience. You think you may know something because you read about it, trust me experiencing it for yourself has no comparison. 

As I look back, I am getting better at building things as the timeline will hopefully show.

All of this work has been done outside of my 40-55 hour work week job in software security.  No excuses. 

TL;DR

I built a few things. Learned from my experiences. Links to those things and the people I worked/debated with below. 

Dusty Programmer

This maybe soo META, but this blog itself has been a integral part meeting a lot of people I have worked with on various projects. When I first started writing, I knew having a clean and working design would be essential. I had admired the work of Serena Ngai, content maybe the king, but design is certainly what wins people over. So I emailed her. I didn’t know her. She didn’t know me. 

It was a pleasure collaborating with her on the design. I would eventually work with her again. 

Once that was completed. I began several write ups on various topics, that I found interesting which rung in with the developer community on Tumblr, the blog grew and grew. 

Then one day in passing I wrote a simple blog post about, How much bandwidth was used with Tumblr ASCII art. It took me about 45 minutes to write. I did most of the math in a Google search bar. As I was writing the blog post. I submitted it to HN, it was well received. I think. 

That was actually the first time, I got reaction that strong from anything I have ever written. That being said, Justin is still in ICU and we expect him to make a full recovery in the new year. 

That being said here are the best articles from the year of 2011. 

 

I learned a lot about how people consume information, and what resonates with people. Extremely interesting to me. Things like bounce rate, are ridiculous when you think about it. I kept trying to do things like linking to the site and passing users to other content, something you will see I have done throughout this post.  In case math isn’t your strong suit, that’s over 949K views on those 4 posts. Last month I was proud cracking 1 millions views :)

Takeaways:

  • Write.
  • Proofread(still working on this)
  • Create a brand for yourself.
  • Find like minded people. 
 

Prologger

First solo project. I am by no means a designer, but friend Ahmed(developer by trade) claims to be. So he eventually came on to make this releasable with me, Thanks. 

I started playing with ideas around achievement systems. I extremely irritated by the way hiring was being done in organizations solely based on claimed skills rather that accomplishments. 

So I thought about building an achievement system that would tie in all your online contributions to various projects, if you were the lead developer on a project, if you a big contributor, languages you were proficient in. 

So I discussed it with anyone who would listen. This is where I meet a quite a few people. Kenneth Reitz was the probably the first person talked to this about who genuinely got excited about it, this was before he was famous for Requests. Mike Grouchy was indispensable to me, gave me someone I could talk to about design decisions I was making.

Since building something on your own, can be particularly daunting task, especially when doing most of the development on your own and very very late at night, but I took it as a personal challenge. 

So I was building away, the site was quick. But, I was beaten to the punch by coderwall. They were a team. Working on it full-time. My ego would have liked for me to be able to compete but it wasn’t realistic. They had the exact same concept, I am sure they had exact same discussion I had been having with my friends. It was a serious blow to me. I was working super late nights. Then the glory gets all swooped up just like that. Truly depressing, but with failure comes success. So I thought hard about what to do next. So then I thought why not OS the project. I did it was one of the most followed projects on Github that day. 

I ended getting a couple of thousand users. It was fun meet a bunch of cool people who were excited about what I built. Learned a few planning and skills and to focus on MVP. Fork it here. If someone wants to clean it up ( it needs seriously cleaning). 

Takeaways:

  • Your ideas don’t mean anything
  • Execute first.
  • Open Source is fun.
 

Courtside

I was quite certain I needed something else to fill up my free time. This came up in a casual lunch discussion with Denis Zgonjanin and Omar Shammas. I had this awesome chicken Caesar wrap. We were excited about the idea of Courtside not the chicken caesar wrap. We knew Django Dash was coming up so we decided to build this for the competition. So to do well we I knew we needed someone who was good designer. Serena popped into mind. I messaged her, she agreed to join in.  Everything was a go. Denis was unable to join us since he building his start up eProf. We did build it at his place. There was little sleep had that weekend.

I soon came to realize, I hate coding sprints. They extremely good for getting  MVP out the door extremely quickly, but don’t expect a polished product. I like to release things when I feel they are ready, but with coding sprints everything is rushed and slapped together, but it a beautiful experience every developer should experience once. 

We had a three way tie for 8th place out of 40 teams it was extremely close. It was the first time we all worked together and our first coding sprint competition. It was extremely fun!

Takeaways:

  • Built something cool.
  • Worked with smart people. 
  • Learned you need business people. They aren’t so useless. :)
 

Bro Did You Hear

I needed something else to create. I think I am funny. I doodle quite a bit. I thought why not put some of this online. I knew I needed to meet more designers. Often times when I want to build something, I lose steam because I know it will be ugly. So I posted to Forrst. I had some many ideas, just no one down to hack on them. 

Valentin responded, we then continued to work for the next 5 hours, never having meet in person. We worked well together, site was well received. It was added to subreddit comics. It received quite a bit of traffic, gave me another insight on bounce rates as well. People on this type of site tend to stay longer, in hopes of another laugh. But with my blog often arriving through reddit or HN, they would quickly consume the knowledge and move on. Problem I have observed and yet to solve. 

Takeaways

  • Learned more about traffic and people. 
  • Made a new friend. 
  • Hype can do magic.
  • Do what you love to do. 
 

Notewagon

Once I had released a bunch of the projects. I started to realize that I need to consolidate my efforts into producing things outside of the fact of me just building them. Everything I have built I have learned something through each of those experiences, but those returns were diminishing. 

I was thinking about building a Note sharing tool for the university I went to. My one friend had started something similar and told me about the Notewagon guys. We started talked and since then I have been working with them. That’s why I have been off the radar for the past couple of months. :)

Takeaways:

  • We will see. 
 

Conclusion

 

If you think something is cool. I am sure there are other people out there who do as well. It’s your job to find them. Build a brand. Be kind. Be passionate. Be awesome. 

You can do anything you want to do. Work hard. Oh I can’t I have no time. bullshit. You rather be lazy and sit around. Focusing your efforts is the thing I have learned the most this year. 

I wish I could list everything I built. If you want to see the complete list. Tweet me here, or follow me here on Github. 

We will see what next year holds. :)


Discussion


Ultimate Django Deployment Tutorial

Tuesday, September 13, 2011

First things first, I will try to answer as many questions as I can in the comments. Please don’t ask stupid questions like why wont this install. The guide will assume you have the following:

  1. Ubuntu 10.04 Server Edition (I am sure other version work well too)
  2. Know your way around a terminal. 
  3. Django application you want to deploy
  4. Little bit of python (Fabric)

Now that being said I am using Linode as my hosting provider for my Ubuntu instance I will be using and they provide a lot of the documentation which I will be following for the majority of this tutorial. 

First things first. You have a clean Ubuntu server, you need to do couple things to start off. Dont be like the server admin at Sony, keep your shit up to date and secure. Run the following commands. 

Now that is done we are ready to get the rest of the machine up and running. 

Apache and mod_wsgi

 

Now a lot of people say Apache is heavy and its not the best for serving files and blah, blah, blah. Now for most people they just want to get their site up and running and be able to push new code without having to worry about horrible horrible breakage. So Apache will do.

Now once you are complete installing Apache and the mod_wsgi module. Here are some useful locations and commands for dealing with Apache, that I learnt the hard way. 

Now that you know your way around Apache we will come back later to setup some other stuff. 

MySQL

 

Now unless your some kind of hipster, you are going to need to do a couple things like persist data. I know lame and boring, but how else would the hipsters benchmark how cool they are. 

I haven’t needed to do super complex database setups myself. In no regard do I consider myself an expert, but I do know a little. Excellent thing about Django is that it provides a beautiful ORM which lets you basically say this database, this user, this password, this table, and go. You will see why those are in bold in a second. 

You will then be prompted to enter root password for the MySQL server. I would keep it the same as your machine’s root password. I cant tell you how many times I have forgotten this trying to get all US intelligence with MySQL server. Keep it simple stupid.

Now remember when I told you to make sure your system is always safe and secured. You will need to run the following command to tighten up MySQL, I would suggest answering yes to everything it asks, its for your own good. 

Now that you have offically installed and created your MySQL server lets get a database up in this bitch! Before we can do that we will need to connect to the server. Here is how its done. 

You have successfully configured, secured and setup a user with a database with MySQL. Now we move on to tying it all together with mod_wsgi and Django. 

Oh wait we never installed Django all you need to do is install pip and get all your requirements form your requirements.txt. Here is a post that outlines how to do with with virtualenv

Django and MySQL

 

So you have successfully installed Apache and MySQL. Now its time to tie everything together and get your application showing up in the browser. 

You will need to copy your code to the server. Here is an example structure of a project I have deployed.

Within the apache directory this a file called brodidyouhear.wsgi which the name of this site. More to come later.

Lets first connect up the database. 

Now that you have successfully connected to your site you will need to do two things. 

  1. Write your wsgi file
  2. Create the Apache site file.

These will be outline below. I would take some time to make sure everything is setup correctly, and you are ready to progress. Most of your issues will happen in the next bit. At least it did for me. 

Django, Apache, and mod_wsgi

 

Here is a sample wsgi file with comments up in that bitch. 

Beautiful now you have your wsgi application created. Now its time to tie in Apache.

You will need to create a site and enable it. Follow the instructions below: 

You will now need to enable the site and reload Apache:

Congratulations, if my guide didn’t suck and you were full of win! We did it. If anything is broken check out the logs where I pointed you earlier, its the only way your going to get any information back from Apache!

This post got a little long. Next time I will cover some Fabric.

References

 

Discussion


Handling Static Files in Django

Monday, September 5, 2011

I have been working with Django for the past couple of months at work. Through this time, I have learned quite a bit, and solidified some other skills. I will be writing a few post to summarize what I l have learned as well as little notes on things, I will unfortunately forget as time goes on. 

One simple thing that I have constantly having trouble with is dealing static files in development vs. static files in production. 

So I am going to outline the final way I decided to deal with this in Django 1.3. This follows very closely to the documentation, just less ambiguous for me. So please don’t nerd on the fact that the docs are clear, they are great. The way you want to have your django static files organized is as follows, each application has it own static directory, which contains files specific to that application. 

Here is the structure of an app I have been working on. 

I will get into how I like to structure my Django projects in the future; it has been a process of stealing and refining what I need over time. Anyways inside this project there are several application directories used for storing app logic. Shown below. 

Nothing new here. The way I have found to have the best environment for storing and serving static files in development is to have a static directory for which each app, which deals with its static files. Now that being said that brings up a couple of other issues as to where to homepage and other generic views, I usually tend to write another simple application to hold simple navigation pages as well, for some specific reason these were avoided in this project. 

So as you can see above within the game application, I have stored static files within the app! Which is automatically served by Django in development, due to this little magic. 

Boom static files in development. Now you maybe wondering great you taught me this now how do I handle things when I am want to run them in production. Well what you would like to do in development is to have these files collected and stuck somewhere so they can be served. 

Enter collectstatic command. 

The -n option is for dry-run so you can see what will be copied, and make sure that the directories are being found and put in the correct spots and check for collisions. Then you simply point your server to this directory and all your static files will be served. 

References

  1. https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/
  2. https://docs.djangoproject.com/en/dev/howto/static-files/
  3. Hours spent trying to make sense of it after I forget again and again!

Discussion


Up until recently I have been maintaining Python dependencies manually in my development environment. I would do things like editing the python path and symlinking in python packages, which made me feel very clever until, it quickly turned into the 7th level hell. I would quickly forget where I put things and waste a bunch of time trying to figure out why things were breaking all the time. Don’t even mention trying to figure out what I needed to export when trying to deploy or reproduce the environment for a collaborator. 

Requirements

I will be basing this tutorial on the setup I have at home. So for the best results using this guide I would recommend using Ubuntu 10.10. I will try and keep the instruction as generic as possible. Overall goal will be to introduce you to the magic of pip and virtualenv.

Install easy_install

Now it may seem unintuitive to install a tool with the very tool its trying to out date, but it easiest way I have found to do it. 

You will need to install easy_install 

Once that is installed you are ready to get pip

Since were installing things you might as well install virtualenv. 

Creating a virtual environment

The problem that virtualenv is trying to solve is that when you install multiple python package often with various installation methods.  It will become increasingly more difficult to keep your core system in order. The idea with virtualenv is to create disposable and quickly reproducible environments to run your python projects. 

For ease on my system I have mapped /srv/virtual/ the space where I keep all my virtualenv. So lets say I have Django project I am working on I would name the virtualenv something along the lines of django-<projectname>.

The —no-site-packages option tells virtualenv not to inherit any libraries from your existing Python installation’s site-packages. To activate the newly created virtualenv, you will need to do the following. 

Once you have activated the virtualenv you are running within a system that has all the packages you have installed to that particular virtualenv. You can freely browse your file system and run tools as normal; but with the added value that you have the newly installed packages in separated and clean environment maintained by you. 

So know we have just created a pristine environment to begin customizing for our projects needs. Enter pip. Pip is designed to make sense of all the various ways you can install python packages on your system. Its trying to solve the problem of how to consistently add and remove desired python packages without any adverse affect on system. I cant tell you how many times I have forgotten the install method for some package and I have to go rummaging through my python path to attempt to remove all the installed eggs. Ugh not fun. 

We can use pip to directly install into the virtualenv just by specifying it. In order to do the following your working directory will be the directory that you just created your virtualenv within. In this case it will be the parent directory of the django-mimo virtualenv

Now this package wont be accessible outside of the virtualenv, which is exactly the desired outcome. 

Now lets say you have a friend and he wants a copy of your pristine django virtualenv with all the correct package for a project you guys are working on. Do the following.

Thats gives him everything you have installed and he can then turn around and create his own virtualenv with the same exact setup. Everything just works.


Discussion




Copyright 2012 Mahdi Yusuf
Errrrday I be programmin' (oh and hustlin' too)