Monday, July 22, 2013

software tools for your raspberry pi

The raspberry pi is a really amazing piece of hardware, any computing enthusiast would really love to have.Just reading the specs makes one think about the many things they can do with it, ideally its a small linux box.

I've compiled a series of tools which i've found useful and which you might want to setup on a raspberry pi

  1. Emacs - well, we also have the vim guys but i won't dive deep into this.Its nice to have your favourite editor handy in the terminal.Remember to place an alias for terminal mode.
  2. Apache - Unless you're serving over 200 concurrent requests, then apache will do.In anycase if you had such a high number of requests then you could afford the heavier guns.
  3. Sqlite3 and/or mysql - sqlite is just brilliant for such devices, i'm surprised it doesn't come out of the box with wheezy.
  4. pip,virtualenv,virtualenvwrapper - the pi means python and these tools go hand in hand with any python development.
  5. Git - Version control in case you want to do some coding on the pi.
Now you are ready to go.Feel free suggest some tools which you found useful and should be added to this list through the comments.

Thursday, March 21, 2013

a good track for learning javascript

As i had mentioned earlier in my previous post, javascript is quite important and as a web developer you should know javascript well.The problem however is with the appropriate technique to learn it.I found a technique which claims to be good.
how-to-learn-javascript-properly

I have started this course and i can say i'm seeing some progress, i'm through with the first two weeks.About the resources, i would recommend professional Js for web developers.

I've not finished the week 3 and 4 sections but i really look forward to evaluating whether my skills have increased.

The codeacademy course can be very boring especially if you've chosen to start with the web fundamentals.I chose to skip some sections, but took others which looked like good refreshers.Don't skip this track entirely, you can be surprised to learn things you didn't know.



Tuesday, October 2, 2012

tinkering around but never mastering javascript

I normally hack javascript when i need to, but i have noticed that many people also do this.The reason for this i attribute to the internet and especially google.

There are plenty of resources on the internet offering solutions on how to deal with a specific problem, so one ends up googling how to do something in javascript without going through the basics of the language.

What we end up with is skills at googling and fixing problems but no mastership of the language.This can be said to be the double edge of having plenty of resources available at your finger tips.

For instance, stack overflow is an excellent resource.But i think one should turn to stack as the last resort.The habit of rushing to stack overflow and copying code does not offer any self improvement.A better alternative would be to hit the docs and read a good portion.Still this should come after attempting to solve the problem.

Nevertheless programming is a craft thats all about experience, if you continue hacking at javascript each day for 10 years, you'll eventually master it, but the point is it would be easier if you took time to go through the docs and learn the basics of a language.

This goes for jquery too, its possible to use jquery without knowing a good portion of javascript.This is a bad idea and sooner or later, if you're writing serious code, problems are going to arise that need more than just the basic knowledge of jquery.

So what will be the right time to master javascript?
Why not try a daily schedule.Taking on a chapter a day, there are plenty of good books on javascript out there.

Mac as a development environment

Apple pcs and notebooks are very elegant and offer a high level of aesthetics compared to standard hardware, but what about using a mac for development.

Experience with a macbook pro has proved that mac's are excellent for development.Want a vague proof of this, just take a look at conference videos, most serious developers use macs.And its just not for the aesthetics but there are heavier reasons for this.

Historically linux was the choice environment for many.The popularity of linux is waning due to recurrent issues involving GUI systems and the classic old drivers problem.Its just a pain that should be abstracted, and this is what mac osx does best.The UI is clean and elegant and you still get the power of the unix shell.

The write once run everywhere nature of web apps has also promoted the use of osx.Due to the fact that you can create a web app from any on any operating system that will be available to any system with a browser, this has removed the constraint of having to develop on a particular environment.Thus developers are free to choose which system provides the best user experience, and apple is well known for this.

A general trend I have noted is that most development software and library creators tend to cater for mac users since its a fact that many debs are on that platform.



Wednesday, August 22, 2012

pep 8 on pycharm

Pep 8 standard is a good convention to use when coding especially when working as a team.Standards and conventions make reading other peoples code easier.Getting yourself to start adhere to these  standards takes some time and effort, but by using the right tools it can take a shorter time.By the way, taking your time to learn these standards is quite worth the effort.

Pycharm is a wonderful python IDE which i would recommend to anybody doing development in python.Using pycharm you can set pep8 as an external tool, which you can invoke on any file you are currently working on to  check whether it violates any standards.This can be done this way.

Install pep8 package from the python package index

pip install pep8

go to: File > Settings > External Tools > Add new


if your using virtual env, use the path to pep8 installed in the virtualenv's bin directory.Otherwise point it to the location where pep8 is installed, use the whereis command to find it.
Now add an output filter as follows.

You can now access the command from the tools menu or conveniently right click anywhere within the file currently being edited and select the command.
The output should be quite helpful in identifying changes which need to be made.


Monday, August 6, 2012

django factory boy - better test management

Django factory boy is an excellent replacement for fixtures, most of the time you will encounter problems with maintenance of fixtures.For instance if you do migrations often, the set of fixtures will become invalid and has to be edited to fit the new schema, this can be extremely painful if you have a complex schema and lots of data.
Factory boy makes it easy to create objects when you need them for tests.For example..

lets say you have this set of models,
from django.db import models

class Owner(models.Model):
    name = models.CharField(max_length=200)
    phone = models.CharField(max_length=50)

    def __unicode__(self):
        return self.name

class Car(models.Model):
    name = models.CharField(max_length=200)
    owner = models.ForeignKey(Owner)

    def __unicode__(self):
        return self.name

Then your factories.py for these two will correspond to something like this
import factory
from models import Owner, Car

class OwnerFactory(factory.Factory):
    FACTORY_FOR = Owner
    name = 'bruce'
    phone = '+254728037573'

class CarFactory(factory.Factory):
    FACTORY_FOR = Car
    name = 'jeep'
    owner = factory.lazy_attribute(lambda a: OwnerFactory())

The tests for the factories themselves go something like this
from models import Car,Owner
from django.test.testcases import TestCase

class FactoryTestCase(TestCase):

    def test_car_factory(self):
        car = CarFactory()
        self.assertTrue(isinstance(car, Car))

    def test_owner_factory(self):
        owner = OwnerFactory()
        self.assertTrue(isinstance(owner, Owner))
Many to many fields are a bit tricky to emulate but this does the trick. For instance lets say you have this set of models.
from django.db import models

class Pizza(models.Model):
    name = models.CharField(max_length=120)
    toppings = models.ManyToManyField(Topping)

    def __unicode__(self):
        return self.name

class Topping(models.Model):
    name = models.CharField(max_length=200)

    def __unicode__(self):
        return self.name

Then your factories will go something like this.
from models import Pizza, Topping
import factory

class ToppingFactory(factory.Factory):
    FACTORY_FOR = Topping

    name = 'mushrooms'

class PizzaFactory(factory.Factory):
    FACTORY_FOR = Pizza

    name = 'mushroom delight'

    @classmethod
    def _prepare(cls, create, **kwargs):
        topping = ToppingFactory()
        pizza = super(PizzaFactory, cls)._prepare(create, **kwargs)
        pizza.toppings.add(topping)
        return pizza

So the key here is to override the _prepare method and assign the manytomanyfield objects here, since you have and instance of the object. In conclusion factories are a good alternative to fixtures when used in the right way.

Thursday, April 12, 2012

building web applications

The best method to use when building web applications is to use frameworks. Frameworks save on time and adhere to the principle of not repeating code all the time (DRY). So if you decide to use a framework, what should your choice be.There are many frameworks out there and therefore it would not be okay just to point you to one.To gain a deeper understanding of building web applications using frameworks it is advisable to go down the path of discovery.

  1. Pick a framework based on any language you know of and learn it, this should be the beginning.
  2. After taking a week or two to learn the new framework, do a side project with it, not a serious one but something far from the basics.Try to implement some idea you've always had.
  3. Add the side project to your portfolio and start over again from step 1 this time with another framework which is related.
After going through the first iteration, try implement the idea you had done using the new framework you have just learned.This aids you in discovering weaknesses and strengths in a framework.

Be patient
Nothing comes easy, everything requires time and effort, so don't expect to excel at it immediately.With continuous practice and diligent effort you will notice your skills and knowledge increasing.
I wish to stress the importance of persistence here.It's what will bear the results.