Building an API vs Building an Application

Aug 05 2010

Going through school, you are taught one thing. How to build small applications with limited input and limited output. This is fine and dandy, and it allows the professors to assign projects to teach a specific topic by example and move on quickly. What they don’t get into is designing full fledged applications and the APIs that those applications might wish to make public.

On one hand you could simply build a plugin loader that would execute a plugin’s initialization to add hooks into the app easy enough. This is what I tried with Keryx 0.92. It was a horrible idea. You’re stuck with having plugins directly manipulate the variables inside of the host app. This is such a horrible idea for many reasons.

For the rest of this article, keep in mind that I reference API calls typically, but this doesn’t only apply to web application APIs, this applies to any library you are building. I learned a lot of this building Unwrapt for Keryx’s backend. My goal was to build a frontend agnostic library that was capable of working in many differnet applications that may not necessarily be Keryx’s GUI or CLI frontends. We have planned on building Keryx into a web based application which could be another frontend similar to packages.ubuntu.com. Honestly the sky is the limit when you are building an API or library. You’re making a general use case tool, so treat it as such. Millions of applications you would have never thought of, so don’t think you are smarter than the people who will be using your library. You’re building it so it is always going to be hard for you to see it from a different use case angle than someone who just read your README looking for a specific tool for their creative new idea.
Continue Reading »

View Comments

The Problem of Internships

Jul 31 2010

Something that has been bothering me throughout highschool and college is the idea of internships. Don’t get me wrong, internships are a wonderful wonderful thing. It gives students real world application to the almost purely conceptual learning they do in school. Rarely do you get a project in school that makes sense in a real environment. This means that internships help to provide the necessary balance between the two to give a truly “well rounded” individual a beautiful set of opportunities upon graduation.
Continue Reading »

View Comments

Ubuntu Color Terminal

Jul 22 2010

So one of the things that might get annoying is Ubuntu’s plain terminal. You see everyone else with these sweet terminals, but when you make the configuration changes, it actually messes up the terminal options for changing colors! There’s actually a really simple configuration change in bashrc that will allow you to have a color terminal but continue using the colors in your profile flawlessly too:

gedit ~/.bashrc
Find this line: “#force_color_prompt=yes” and delete the “#” so it looks like “force_color_prompt=yes”
Save and close
Restart terminal

Voila! And you get something like this:

View Comments

Bypassing Android Activation

Jul 12 2010

Today I decided to finally get around to rooting my Motorola Droid that I received for going to the Google I/O conference. After going back to the 2.0.1 firmware using RSD Lite, I realized that I had to reactivate my phone. I’m out of service range so the phone call couldn’t be completed, and I no longer have my trial month of service even if it did work. Luckily there is an easy way to bypass activation and still use your phone as an internet tablet.

Simply touch each corner of the screen (I used inside the black area where the android logo was) starting with the top left and moving clockwise around it. You’ll jump right into the home screen and be ready to go! Hope that helps!

This worked for only certain versions on my Motorola Droid. Every time on boot I am presented with the activation screen still, however I can bypass it by simply pressing Home (now that I am running Bugless Beast v0.4). I’ve also had the experience where I couldn’t bypass it with these methods, doing the activation call a couple of times, failing, and then pressing home let me through. Who knows what might work for you, but eventually you can get through.

View Comments

Multiple Version Control Systems At Once!

Jul 12 2010

For Keryx, I have been working on a new backend system called Unwrapt (A play on words regarding the APT package system :P ). I’ve been coding on github for the social coding aspects and keeping the branch on Launchpad.net as well to be part of Keryx’s page. This meant every time I wanted to commit and push, I’d have to do twice the amount of commands. Of course, being a lazy coder like the rest of us, I decided to script it. Fired up Gedit, and two seconds later I had this:

#!/bin/bash
 
bzr commit -m "$@"
bzr push
 
git commit -am "$@"
git push origin master

Usage is simple (example is using this script saved in ~/vcs.sh). Just execute this from inside your versioned directory like you would normally with git and bazaar:

$ sh ~/vcs.sh "first commit"

It pushes to your default branches (if you have any setup) in one strike using the commit message you pass to the script. Easy as that! I’m sure people might have some good ideas on features and improvements so leave them in the comments!

View Comments

Complacency

Jun 23 2010

com·pla·cent

1. pleased, esp. with oneself or one’s merits, advantages, situation, etc., often without awareness of some potential danger or defect; self-satisfied: The voters are too complacent to change the government.

http://dictionary.reference.com/browse/complacent

Recently my friend Jacob wrote a post on his blog on The Stupidity of the Job System. I’ve been having some serious feelings about this as well with my graduation from college coming up after this coming school year. I’ve had several interviews recently and have been reading about startups and other businesses who have been successful despite the recent recession. There’s one thing that seems to stand out to me and is the problem with 99% of businesses out there. Complacency.

Most people automatically assume standard practices are best. It’s not. It’s boring and it doesn’t get the job done anywhere near as well as it could be. Businesses need to survive, but as the world changes, they have to change with it. Jacob had mentioned how he was annoyed with building resumes and cover letters because it is the accepted practice that you make up some BS about yourself and submit it to employers.

But I had another view at this. It’s hard to write these kinds of things because that’s not your personality. You don’t normally brag about yourself so why should you have to here? But wait, are these places which look a degree in BS and the ability create a fake, souped up version of yourself on paper really the kind of people you want to work for? You can only assume that they will expect the same approach to climb the chain inside of the business. Meetings about nothing and useless reports are likely going to plague you, stifle any creativity and passion you had for your job, and in the end, you’re going to become a zombie employee like everyone else at the company. Complacent because you are receiving a paycheck which is enough to live on and drink away your sorrows on the weekends. You come to accept that this is life, this is “happiness” as defined by business because everyone else is in the same position everywhere you look.

This applies to school as well. I’ve been kind of frustrated recently with the way I have been taught at my university. I’m a computer science major and things change fast. Daily. They still teach me like it’s the 80′s. I’m still learning C++ as the primary language, when in reality, I think it’s certainly not the best choice. There are many other languages out there that could more efficiently teach concepts and best practices. After all, learning a language is easy, it is the concepts that is the hard part. But no. They’ve taught things this way for years, they are content getting paid to do what they have always done and that’s that. Only one or two professors realize this change is imperative and just like many businesses changes like this must be debated in meetings. Chances are action on this won’t happen for a while.

The companies I would consider working for are the ones driving innovation; pushing the bar. How are they doing this? By providing freedom and core values to shine through the BS that is today’s business world. These are the places that give employees time to work on things they enjoy researching for fun. I mean, look at Google. 50% of their products have come from the 20% of free time they give each employee. Allowing this freedom has given a huge boost to their company. Other places like Tesla are pushing the bar for consumer electric automobiles. How? Because they are free to research and explore in order to find improvements. And just look at the results, it works!

Zappos is another great example. They empower their employees to do what they feel is best, just read any reviews of their customer support. This empowerment brings creativity and excitement to employees which almost all business I’ve known are seriously lacking in. Nobody is excited to go to work anymore, employees are only acquaintances to each other or casual friends, and the core of their business does not thrive. Bring change, bring innovation, and it will create value in all aspects of your business. The true value they have is the interaction with customers.

At the end of the day it comes down to this: People have lost their sense of true happiness. The world distorts the pursuit of happiness into some kind of end goal where material goods are where the value lies. What are the best memories you have? They almost certainly of people.

We all see these campaigns to solve world hunger but what’s the most people do? They donate $10. But where does the money go? It goes to the starving people you say? This doesn’t mean anything if there isn’t someone actually using the money to make a difference. $10 is nothing more than $10. We have plenty of money, but we need ideas and happiness. Neither of these are about money. Sure you need money to attain goals, but money isn’t the goal itself.

Chase your passion, not your paycheck. Change the world, get out of the rut you are living, and quit being complacent.

In case you’d like to get a better understanding of the focus on happiness and culture over at Zappos check out this book:

View Comments

Getting Started With Quickly

Jun 21 2010

Recently an open source project called Quickly has sprung up and looks to be an incredible tool for new developers looking to work on open source GUI projects. The description from their website reads as follows:

Quickly helps you create software programs (and other things) quickly. You can select from a set of application templates and use some simple quickly commands to create, edit code and GUI, and publish your software for others to use. Quickly’s templates are easy to write. So if you are a fan of language foo, you can create a foo-project template. Or if you want to help people making plugins for your killer app, you can make a killer-app-plugin template. You can even create a template for managing corporate documents, creating your awesome LaTeX helpers The sky is the limit!

Sounds like a cool project right? You bet. I’m going to be using Quickly to begin working on the official unstable branch for Keryx 1.0 and will outline the steps I took to get started here.

Installing Quickly

Super simple. Just fire up a terminal and “sudo apt-get install quickly” or install the quickly package via Synaptic or your favorite package management tool (maybe even through Keryx!). Once that is installed, you can fire up the documentation if you like by typing “quickly tutorial ubuntu-application” and it will open up the Quickly User Guide which is a handy reference.

Creating a Project

Nothing more than a “quickly create ubuntu-application keryx”. Just tells quickly you are building a new application with the Ubuntu template named Keryx. Simple as that. It sets up the directory structure for you and everything! So handy!

Getting to Work

Modifying the GUI is simple, just do “quickly design” and Glade is opened up with your ui file ready to go. The same goes for editing the code with a simple “quickly edit” which opens up all the files necessary for your application in your standard text editor.

Committing

“quickly save notes” is all you need to do to make a commit of your changes with the comment “notes” and submit this to launchpad using the bzr version control system.

There are a few other commands you might be interested in, mainly for packaging and releasing but this is a very simple tutorial on how we setup Keryx 1.0. If you’d like to contribute, just download the unstable code branch from launchpad and start using it with Quickly!

So I suppose I will leave it at that for now. Quickly is a way for new developers and contributors to easily be able to jump in and start working on projects. We will be using this for Keryx 1.0 and hope this will encourage contributions and make bugs easier to fix.

View Comments

PyGTK and Threads Part 2

Jun 14 2010

If you’re just coming to this post, you may want to check out my introduction to threads in my previous post PyGTK and Threads Part 1.

Now that we have a better understanding of threads, let’s start learning with an example. You will need Python and PyGTK installed in order to run these.

The following code is the framework for the application we will be using. It’s very simple and consists of a window and a button. This code prints “Hello” into the terminal when the button is clicked so immediately after you click the button you can click it again and it works. This is because printing “Hello” is a very quick process.

#!/usr/bin/env python
#-*- coding:utf-8 -*-
# By Chris Oliver
# Adapted from http://www.pygtk.org/pygtk2tutorial/examples/helloworld.py
 
import pygtk
pygtk.require("2.0")
 
import gtk
 
class HelloWorld:
    def __init__(self):
        """
            Initializes the GTK application, in our case, create the window
            and other widgets
        """
 
        # Create a window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_border_width(10)
 
        # Setup the application to exit GTK when the window is closed
        self.window.connect("destroy", self.destroy)
 
        # Create a button
        self.button = gtk.Button("Hello World")
 
        # Make the button call self.hello() when it is clicked
        self.button.connect("clicked", self.hello)
 
        # Add the button into the window
        self.window.add(self.button)
 
        # Display the button and the window
        self.button.show()
        self.window.show()
 
    def hello(self, widget, data=None):
        print "Hello"
 
    def main(self):
        """
            This function starts GTK drawing the GUI and responding to events
            like button clicks
        """
 
        gtk.main()
 
    def destroy(self, widget, data=None):
        """
            This function exits the application when the window is closed.
            Without this the GTK main thread would continue running while no
            interface would be displayed. We want the application to exit when
            the window is closed, so we tell the GTK loop to stop so we can
            quit.
        """
 
        gtk.main_quit()
 
if __name__ == "__main__":
    # Create an instance of our GTK application
    app = HelloWorld()
    app.main()

Go ahead and try it for yourself. You should get an application similar looking to this:
Clicking the button prints “Hello” in the terminal and the interface is still usable.

Now what if we wanted to do something more? Maybe we wanted to…wait 20 seconds and THEN print “Hello”? Now that might cause some problems. Well let’s try it first. Just change the code to look like the following:

    def hello(self, widget, data=None):
        import time
        time.sleep(20)
        print "Hello"

Now execute it. What happens? When you click the button, it goes down like it was pressed, but does not come backup. The GUI stopped drawing as soon as the button was clicked. Resizing the window was no longer smooth, and dragging around the window erased the button and make it look something like this:

Well, GTK was waiting to take control of your application again. You were busy forcing GTK to wait by sitting around fiddling your thumbs doing nothing for 20 seconds and then printing some text to the screen. Since you don’t take care of the drawing, you forced GTK to wait and made your application become unresponsive for a while. Users might think that your application has crashed, or at the very least they think its poorly written. And well…if you’re not using threads for long running tasks like this…then yes. It is poorly written.

So how do we do some simple threading? Doing two tasks at the same time sounds crazy complicated! Well, in reality, it certainly can be. However, as you begin to get the hang of things, it’s really not so bad.

First off, you need to initialize GTK Threads. I won’t go into detail on why this is necessary other than it’s required to setup GTK to use threads. You simply need to call “gtk.gdk.threads_init()” before the gtk.main() loop is called, so that’s pretty easy. There is a lot of things regarding threads that you need to be aware of, however this is just an introduction so I’m only going to mention what’s necessary. First off, when you have threads, they have access to all the variables in the program. This makes things easier, but unsafe. Think about this scenario: Two separate threads are running, but wish to modify the same variable, what happens? It’s impossible to tell. For this reason, you want to make sure that you NEVER update GTK from a secondary thread. This means you cannot make changes to ANYTHING related to the GUI in those separate threads.

Wait a minute, well then how am I going to do something like a progress bar? Won’t I have to update the GUI from that thread? Yes you will, but GTK provides you tools to do this in a safe manner. The gobject.idle_add() function does this for you. Woah woah woah, now what is gobject? Well, its the underlying architecture of GTK. The gtk.idle_add function has been deprecated in favor of using the direct gobject call. It’s best if you work with this directly but you don’t really need to know much about it for now other than it adds something to GTK’s todo list when it gets the chance. This lets you tell GTK to do things from external threads. GTK will be sitting around waiting to do something while your thread is hard at work. The thread can then tell it to update the progress bar occasionally and GTK will gladly do so safely.

So how do we apply these concepts to our existing application? Pretty simple as follows:

#!/usr/bin/env python
#-*- coding:utf-8 -*-
# By Chris Oliver 
# Adapted from http://www.pygtk.org/pygtk2tutorial/examples/helloworld.py
 
import pygtk
pygtk.require("2.0")
 
import gobject
import gtk
gtk.gdk.threads_init()
 
import threading
 
class HelloWorld:
    def __init__(self):
        """
            Initializes the GTK application, in our case, create the window
            and other widgets
        """
 
        # Create a window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_border_width(10)
 
        # Setup the application to exit GTK when the window is closed
        self.window.connect("destroy", self.destroy)
 
        # Create a button
        self.button = gtk.Button("Hello World")
 
        # Make the button call self.hello() when it is clicked
        self.button.connect("clicked", self.hello_helper)
 
        # Add the button into the window
        self.window.add(self.button)
 
        # Display the button and the window
        self.button.show()
        self.window.show()
 
    def hello(self, widget, data=None):
        import time
        time.sleep(5)
        print "Hello"
 
    def hello_helper(self, widget, data=None):
        print "starting new thread"
        threading.Thread(target=self.hello, args=(widget, data)).start()
 
    def main(self):
        """
            This function starts GTK drawing the GUI and responding to events
            like button clicks
        """
 
        gtk.main()
 
    def destroy(self, widget, data=None):
        """
            This function exits the application when the window is closed.
            Without this the GTK main thread would continue running while no
            interface would be displayed. We want the application to exit when
            the window is closed, so we tell the GTK loop to stop so we can
            quit.
        """
 
        gtk.main_quit()
 
if __name__ == "__main__":
    # Create an instance of our GTK application
    app = HelloWorld()
    gtk.gdk.threads_enter()
    app.main()
    gtk.gdk.threads_leave()

As you can see, there were only small modifications. In this case we created a new function called hello_helper which executes our old hello function inside of a thread. When you click the button now, the thread is spawned quickly and execution continues back to the GTK loop almost immediately. You can click the button several times and many threads will be created and will execute simultaneously. We initialized GTK Threads at the very beginning at import just to make sure that it wasn’t forgotten, but standard practice is to put it just before gtk.main().

That’s about it. It’s a pretty introductory example, but I think it sufficiently explains the basics of threading. There are many more things to it and so I suggest reading up on it some more. Let me know if you have any questions or comments!

View Comments

PyGTK and Threads Part 1

Jun 14 2010

Last semester I took a course called Operating Systems. We dove a bit into memory management, scheduling, and resource management. This was great and all, however our professor was a pushover when it came to projects. Sure we learned the concepts, but you can’t fully understand them until implementation, or at least that’s how it works for me. This summer I’ve been working on a couple projects in which threading is imperative. Last summer I attempted some threading well before I understood any of the concepts so I thought I would put together a blog post or two to introduce the subject a little simpler than some of the other posts I had tried to learn the subject on in the past.

To start this off, we must introduce threads. What’s a thread? Well it’s a lightweight process. Well what exactly is a process? It’s an application that is in memory. On a single CPU system, the operating system can only be executing one process at a time. In order for the computer to be interactive, it needs to execute a small portion of one process, jump to another, work for a bit, and go to the next. This happens quick enough that it appears the computer is doing multiple things at once. It’s not. Each time a process is swapped out of memory, the process needs to save its state, this means all the variables and everything else regarding the process so that it can resume exactly where it left off. Each process also is completely separate of each other. They do not share memory or anything.

Okay, so what is a thread exactly? Well a thread is a lightweight process. It shares the same memory space of the parent process so it also has access to the other threads’ variables. This isn’t possible with separate processes and also makes switching between threads significantly faster than switching between processes. In general, it is easier and simpler to write multi-threaded applications over multi-process ones.

Now that we’ve got an understanding of threads and processes, why do we need them? Have you ever used an application that freezes up while it’s doing something? This is when the developer should have launched a new thread to do the intense calculation. When you want to do two things at the same time, threads are important. This is especially important in graphical (GUI) applications. Why? Well you want the GUI to continue responding while you do your work don’t you? You don’t want it to freeze up do you? The user might think it’s a crappy application or something. Ever have an application that freezes up and you drag it around to see if its still working and the interface becomes blank? That’s because the GUI is not being updated. The thread for drawing the GUI is busy doing some other stupid calculation and leaving the user to freak out. Certainly not what you want right? Didn’t think so. In fact, if you don’t use threads, you couldn’t even use a progress bar to tell the user something was happening in the background.

What we want to do is apply these methods to GTK specifically. This idea works for just about any GUI toolkit including Qt, and wxWidgets, but we are going to keep this in terms of GTK for our purposes. So first off, you need to understand how a GTK application works. GTK provides a loop, that continually redraws the windows and accepts inputs. By default, it does nothing. It’s not until you, the developer, come along and give GTK some things to do. Maybe it’s drawing a window and a button. GTK knows what to do when you tell it what you want. It knows that you want it drawn so it does that for you. The mundane details don’t need to be worried about, you get to do the creative part and use this framework. Maybe you also want that button to do something when it’s clicked. GTK also gets notified of this. You tell it, hey, when someone clicks this button, can you execute this code for me? Thanks. It does this, but here’s the problem. GTK needs to be in it’s loop constantly waiting for input or changes from the user. It is “event driven”. This means that every time something happens, it needs to be ready and waiting to decide what to do. If you take too long in your custom code, GTK may not be able to get back in time to receive those inputs. If that happens, your application appears unresponsive and thats no good. I’ve made a simple mockup of GTK and how a developer’s code simply extends GTK in order to do what the developer wants.

Head on over to Part 2 to start getting your hands dirty.

View Comments

Beautifying Gedit

Jun 13 2010

So I do a lot of work in Gedit when I’m not using Vim. Lately I’ve been using it a considerable amount over Vim and wanted a better color scheme that was vibrant. I came across this article and was pleased to have found something I thought I would like. I have to say, I absolutely love it. All the colors are bright enough and different enough that when you want to look for one specific thing, nothing else stands about better. :D Included in the link are a lot of other things for making Gedit more TextMate like. From the sounds of it, TextMate seems to be an incredible editor, so I might have to check out some of those plugins soon.

You can download the darkmate theme for Gedit here: http://grigio.org/files/darkmate.xml

If you’ve got any other theme or plugin suggestions for Vim or Gedit let me know. I need to build a perfect environment to develop in and I’m sure there are some life savers I haven’t come across yet.

View Comments

Older posts »