Archive for August, 2009

Modeling a Path to Successful

I recently read this blog entry http://lethain.com/entry/2009/jul/31/success-and-dancing-shoes/ and starting thinking on what success was REALLY about. The article had much truth to it, saying that one must position oneself amongst the right people, and of course must be willing to work hard, and there should be a sprinkle of luck. I started thinking how to model a path of success.

But honestly, I have a completely different model of the factors of success.

A key ingredient in the model of success is ‘the goal’.

What do I mean by ‘the goal?’

I mean that at some point, there needs to be an idea that can be realized as something concrete that provides real value to people (or businesses). There has to be a direction that is being moved in to create this value. If you want to be successful, you need to be associated (and possibly contributing to) the right goal.

A goal can be a new toy you are going to produce, a new internet startup based around a novel idea, or anything that essentially a group of people can use as a direction to move towards creating something of concrete value. Most of my examples will be business oriented, but this doesn’t have to be the case. All that matters is that there must be value produced.

First, you should ask yourself, is there anyone considered successful who has not been associated with a goal? I can’t think of any.

Now, once you accept that a goal has to exist, the question of ‘how do I become successful’ instead turns into something else. It becomes a matter of being associated with the right goals/directions/ideas, as well as potential goals/directions/ideas.

Everyone is part of many goals today - in fact, you should probably ask yourself ‘What goals am I pursuing?’ - one of them, if you are employed, is your employers goal of doing whatever it is the company is trying to accomplish.

The people who you surround yourself with are essentially your ‘pool’ of potential goals you can pursue. Maybe one of them is entrepreneurial, and has a goal of starting a company. Then you also have a potential to be in that company and pursue that goal.

However, the main thing you should realize is that you have your own goals! You can have an idea of something of value, and share that goal with others and pursue that goal. The important questions to ask oneself are “how can I do this better?”, or if a problem presents itself, realizing that solving that problem for yourself is also probably a problem for others, and it is a small step from solving a problem to creating a new goal of solving this problem on a larger basis.

Thus, success is about the intersection of a two things:
1. How well your defined goal provides concrete value to others
2. How well you and the people you surround yourself with can pursue that goal

The first is about measuring the usefulness of the goal - will people like this new toy? Will people use this internet service? This can be a very hard estimation, but you can improve and hone it over time with feedback.

The second is about how well you can solve the subproblems that creep up and get in the way of the greater goal. With a solid team of smarter, experienced, and well-tempered individuals, you will be able to handle these sub problems better. Some sub problems may be ‘how can I change the product to match the needs of what people are telling me they need/want?’, or ‘how can I tackle this technical challenge’ or ‘how can I get the next round of funding for our company?’

One must attach oneself to a goal, or create the goal and attach people to it. Success is merely the approach and carrying out of this goal.

Tags: , , , ,

Create a Django Dynamic Form with JQuery - Dynamic Field Addition and Removal

So I found a nice piece of Jquery - Jquery-Dynamic-Form ( http://code.google.com/p/jquery-dynamic-form/ ), and thought it would be just the thing to spice up the static forms on my latest venture (a django website, of course). So I downloaded the jquery file and tested it out, and I thought, to myself that it would be no problem to integrate - well, it took longer than I thought, but I finally got it to work nicely.

Here’s how I was able to integrate dynamic addition of form fields on my django form using jquery- dynamic-form:


0. First, fix the JQUERY. This particular jquery library used a ‘php’ style naming scheme for its variables - namely, something like:

<input type="text" name="myfield[]" id="0">
<input type="text" name="myfield[]" id="1">
<input type ="text" name="myfield[]" id="2" >

As you can see, it used the php array as the name - instead, i make a quick fix to the jquery to make it instead just do this naming scheme:

<input type="text" name="myfield0" id="0">
<input type="text" name="myfield1" id="1">
<input type ="text" name="myfield2" id="2" >

To do that was rather easy, simply change a couple lines in the jquery; to look like this:

/* Normalize field name attributes */
            if (!nameAttr) {
				jQuery(this).attr("name", "field" + fieldId);
			}

			if (!/\[\]$/.exec(nameAttr)) {
				jQuery(this).attr("name", nameAttr + fieldId);
			}

As you can see, we only changed 2 lines of code, so that it appends the ‘fieldId’ to the end of the name attribute.


1. Set-up the form template properly with jquery-dynamic-form (easy) - lets you clone whatever field you want, in my case, just a + and - buttons to click on to add / remove text fields on the fly (this template needs a dynamic element to it, but we’ll get to that in step 3)
The JQuery Stuff:

<script type="text/javascript" src="/media/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/media/js/jquery-ui-1.7.2.highlight.min.js"></script>
<script type="text/javascript" src="/media/js/jquery-dynamic-form.js"></script>
<script type="text/javascript">
    $(document).ready (function() {
        $("#duplicate").dynamicForm("#plus", "#minus", {limit:6, createColor:"yellow", removeColor:"red"});

    });
</script>

The template form stuff:

<form method="post" action=".">
 <fieldset>
        <h3>My dynamic text fields</h3>

		<div id="fields">
		    <div class="field">
		        {{ dynamic_html }}
		        <p><span><div id="plus">Add Another <a href="">[+]</a></div>
		        <div id="minus">Remove <a href="">[-]</a></div></span></p>
                    </div>
               </div>
    <p><input type="submit" value="Build it!" /><br/></p>
 </fieldset>
</form>

As you can see, we dynamically create the guts of this template with a variable called {{ dynamic_html }} - I’ll show you what happens with this in a second.

But in general, its just some code that we generate that shows our bound form fields, but it works just like you think it would - clicking the plus adds a field, clicking the minus removes it, intuitive! Here is a quick preview:

A Preview of the Form

A Preview of the Form

2. When the form is submitted, the VIEW dynamically creates a form to match the submitted amount of fields. I used what i call the ‘type’ method to dynamically create the form- we’ll show you this in step three. When the form gets submitted, here is the view that handles it:

Here is the view code:

def myview(request, template_name='myapp/mytemplate.html'):

    if request.method == 'POST':
        #create the dynamic form class here on the fly
        form_class = make_dynamic_form(post=request.POST)

        form = form_class(data=request.POST)

        #this is the template that we insert into our general template
        dynamic_fields_template = make_dynamic_fields_template(form.data)

        if form.is_valid():
            #hooray! A Valid form - process the form fields as necessary!
           return HttpResponseRedirect('/')
    else:
        initial_vals = {'empty_textbox':'',}

        form_class = make_dynamic_form(post=initial_vals)
        form = form_class()
        dynamic_fields_template = make_dynamic_fields_template({'blog_url':''})

    dynamic_html = dynamic_fields_template.render(Context({'form':form}))
    return render_to_response(template_name,
                                {'form':form, 'dynamic_html':dynamic_html},
                                context_instance=RequestContext(request))

#Input: dictionary of fields into this method
#Output: Html (with our field variables not yet bound to context)
def make_dynamic_fields_template(fields):
    template_html = ""
    for f in fields:
        template_html += """
        <p id="duplicate">
        My Form Label {{ form.%s }}
        {{form.%s.errors}}
        </p>
        """ % (f, f)

    return Template(template_html)

Here you can see that we dynamically create our form on the fly from the POST information using a custom method that we show in the next step. If the form is valid, perfect, and you can process it like any other form. If it was the first time we accessed the page (and didn’t POST), then you can see that we simply create a form with one field on the fly, render the template for this one field, and then pass this dynamic_template inside the other template; this variable gets rendered it like a regular variable using {{ dynamic_html }} inside the template.

Why do we have to render the template on the fly? Well, if the template (with a bunch of new, say, text fields you added dynamically) doesn’t validate - well, then you need to return that form you just used (with its corresponding errors) - but you still want it to be a dynamic form, but the original template you used doesn’t know how many fields you added or removed dynamically (using jquery), or what their names are! Thus, we need to dynamically generate a template again from our new form, which we do by created the html and passing it into our template as a variable (and rendering it there)

2.5 To create the form on the fly, we use this method:
http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/ to create the form on the fly. You can see we override the ‘clean’ method; We validate all the dynamic fields, and if there are errors, assign the errors back to the individual fields (otherwise, errors would go in non_field_errors) - this is done using this technique: http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other

And here is how the form is created on the fly:

def make_dynamic_form(myfields={}):
    fields = {}

    #create the fields dynamically!
    for p in myfields.keys():
        fields[p] = forms.CharField(max_length=200, required=False, widget=forms.TextInput(attrs={'class':'text' }))
    #this creates our new form with the given fields
    newform = type('MyDynamicForm', (forms.BaseForm,), { 'base_fields': fields })

    #now lets define our clean method
    def clean(self):
        cleaned_data = self.cleaned_data

        #iterate through each value
        for val in cleaned_data.keys():
            if not val:
                continue;

             if (self.cleaned_data[val] is None) or (self.cleaned_data[val] == ''):
                    continue;

            # clean the individual value below

             ...run your own cleaning tests here....
             ...say it doesn't validate.....

             #we defined assign_error function to assign the error to the correct field
             self.assign_error(val,u'This is an error we want to attach to that specific dynamic field!')
             #this error goes in non_field_errors - we call this method anyway
             raise forms.ValidationError(u'Error!')

    #attaches an error to a specific field instead of non_field_errors
    def assign_error(self,val,msg):
        if not self._errors.has_key(val):
            self._errors[val]= ErrorList([msg])
            del self.cleaned_data[val]

    #create the methods for the form
    newform.clean = clean
    newform.assign_error = assign_error

    return newform

What we do here is create a fields dictionary, pass this dictionary into the ‘type’ function along with some other stuff, and we create our form. Now, we define the methods we want, and set these as attributes for the form, and finally return the new form. In this case, we defined the clean method, and also a helper method to assign the errors to their respective fields - otherwise, django would put all our errors in non_field_errors, because thats what happens when you raise form validation errors inside of the ‘clean’ method.

Thanks! Any questions / comments are welcome!

Tags: , , , , , , , ,

Expand a VMWare Partition Vista / Ubuntu

So I run Vmware on Vista with a virtual install of Ubuntu on an 8GB partition - well, the 8GB filled up, so I needed to expand the ext3 partition.

The three steps to take are:

1. Expand the VMWare partition using the vmware tool (comes with vmware workstation and others)
Here is a link that describes how to do this: http://4sysops.com/archives/expanding-a-virtual-vmware-disk/ . It is fairly easy to do.

The code looks something like this:

'vmware-vdiskmanager -x 10GB myDisk.vmdk'

2. Now, download a live cd that you can boot from, knoppix is the one I used http://knopper.net/knoppix-mirrors/index-en.html — just download an iso file of it. You’ll want to boot vmware from this iso, so what you do is in the Vmware Workstation sidebar, put this iso in the CD Drive (click on the CD drive and load this iso, easy!). Now you need to tell Ubuntu to boot from CD, so go to VM –> Power –> Power on to Bios. Now, this will start up the Vmware bios, now go to the boot menu and press the ‘+’ sign to move the CD Drive up to the top (so it boots first before the hard drive, so that ubuntu will start from this live cd iso that we downloaded).

3. Now Knoppix should be loading, (you may have to hit like ‘return’ to get it to start loading) - once its fully loaded, open up a terminal. type ‘gparted’ in the terminal to run gparted. Now it should show all your partitions and such. Unmount all the drives you need to do stuff with using:

su root

umount /dev/nameofdrive, i.e........ umount /dev/sda1

If the swap partition becomes an issue root, i.e. you need to delete it, you need to turn it off first, so just do:

swapoff -a

Now, make sure there are no partitions between the free space and the original partition you want to expand. Simply select the partition you want to expand and select how much you want to expand it! Then click ‘apply’ in gparted to actually do it, and it should take a while before saying completed.

If the swap partition is between the free space and the other partition, you will need to delete the swap partition and create a new one at the end of the free space.

Once you have hit ‘apply’ in gparted, and it tells you everything was successful, shut it down, and then go back to vm–>power –> power on to bios and reset your boot so that it doesn’t run from CD first anymore. Then restart and it should load up your regular installation (in my case vmware), but this time with more space for you to use!

Note: You should probably check that things are working, and you may have to make a few edits. First, you should type (as root, or on ubuntu use sudo as shown):

sudo fdisk -l
</pre>

This will list all the partitions you have, make sure its set up properly. Now, if you deleted a swap file, you should check to see if the new swap you created is being used:

free -m
</pre>

This should show how much swap is being used. If your swap is not on, well turn it on using 'swapon'. Use the command 'blkid' to check the names of your partitions, then edit the /etc/fstab file and make sure that the names of the partitions are all the same as the ones you saw when you used the blkid command. If they aren't, change the /etc/fstab file to the correct ones.

Tags: , , , , , , ,

C++ Eclipse Install CDT and MinGW GCC Plugin

I just succesfully installed c++ on eclipse using the CDT C++ plugin and MinGW compiler for windows Vista. There are a lot of plugins to get working. There were a few things that I had to set up, no doubt, so here are some notes for those of you trying to do the same thing:

0. Obviously you need to have downloaded eclipse first http://www.eclipse.org

1. Download the  Eclipse CDT Plugin http://www.eclipse.org/cdt/

2.  Now because I am on windows I need to install a c++ compiler (the CDT plugin doesn’t come with one!), so the recommended one is MinGW. Here is a link that says exactly how to install it, and exactly what you will need to install. http://www.mingw.org/wiki/Getting_Started. Note that there is an automatic installer.

At this point, DO NOT FORGET TO SET YOUR PATH VARIABLE! This is very easy on windows; http://www.java.com/en/download/help/path.xml this says how to do it.

If you happen to get the error:”Your connection appears to have dropped out. Reconnect your dial up or check your IE proxy settings.” then this means that sourceforge is having trouble downloading the file. What you should do is first make sure the installer is not on your desktop, retry it a few times, and then set your source forge default mirror settings - this can be done by signing up for a sourceforge account and then going to your account  https://sourceforge.net/account/ and clicking the Default Download Mirror under the main preferences page.

3. Now follow this guide to setting up the code environment - it is a little outdated but you should be able to follow it pretty easily:

http://www.codeproject.com/KB/tips/CPP_Dev_eclipse_CDT.aspx

4. Finally, you will need to set the path of the ‘includes’ library, so to do this, go to Project -> properties -> C/C++ general -> Paths and Symbols, then click on the ‘Includes Tab (first one), and under languages go to GNU C++, then click on the ‘Add…’ button the right, and then select the folder C:\MinGW\include, and press enter.

Done!

Tags: , , , , , , , , ,

Quick Reflections on building ZetaPage

The first thing I am obligated - by pure appreciativeness and nothing else - to thank every one of the Shotput Partners. They have created an absolutely amazing program that has helped us immeasureably to get our startup off the ground and into existence.

Alas, the hour is late, and because this warrants much more, here I will outline some brief thoughts to preceed the upcoming lengthy post.

0. There is no substitute for energy.

Everyday I’m faced with hundreds of decisions, from tiny ones like “what is the proper way to word a sentence on the about page”, to how the database models should change to allow better normalization and ensure easier scalability. Every day, you need to be making those decisions and moving forward. Whatever it is, you need to just do it and move forward - sure you may make some typos or screw up the models and have to refactor a lot of code later - but you can’t stop. Of course, I have always been a huge fan of reasoning through things, and doing things in the best way possible; no doubt you can still do this, but the caveat is that you should do things as best as possible (within the given time period).

1. Meeting once a week and speaking with people

In the Shotput program, once a week we would meet with really awesome entrepreneurs, technology lawyers, professors, marketing experts, and a whole host of really cool and smart people. Similarly, working with the other groups to provide feedback and just being surrounded with other entrepreneurs somehow adds a certain vibe and energy that really makes you feel awesome - it is palpable and apparrent, that each of us knew we were buidling something new and novel.

2. Who you gonna call? (Hopefully Ghostbusters isn’t the answer)

Sometimes you have hard decisions to make, such as changing the focus or direction of the company; sure you need to make a decision and go with it, but, like I said earlier, I’m definitely a fan of doing things the best way possible (and not having to redo things) - thus getting expert outside advice is the best thing possible. That is where key advisors come in.

3. Solving hard problems on a daily basis

Like I said earlier, you will be faced with hundreds of questions a day. Solving problems on a daily basis turns into knowing when it is worth it to sit down and think about something, and when it is completely fine to use a straight-out-of-the-box approach.

4. Adaptation on a daily basis

Now, when making decisions you need to be inundated with the latest <insert statement here>; by this, I mean that each day you need to be in two frames of mind; the first frame of mind is the one you ended yesterday on; essentially, this is the plan going ahead. The second frame of mind is the changeling mind, what it does is test the waters of each decision and assumption you make - it doesn’t prevent you from making decisions, but it makes you aware of all the avenues you could be taking in case you get tripped up or decide you need to go in a different direction. Its like you’re navigating through a neighborhood, following the main road but being aware of all the side streets - you do it because the house you are looking for could be on any street.