true false maybe

tom longson’s blog on software, design, and user experience

OSX Flex 3 SDK Installation

This is a quickstart guide for installing the OSX Flex SDK on your Mac. I adapted this from a video tutorial at learnhub. If you prefer to watch videos, go check it out. This is just a more straight forward guide to getting you up and running.

1. Download the SDK from http://www.adobe.com/products/flex/flexdownloads/

(click on the "I have read the Adobe Flex 3 SDK License" checkbox, and the download link will appear below)

2. Use stuffit expander / unzip to uncompress the archive.

3. Open the terminal (if not open already), and go to the folder where you uncompressed the archive to.

4. Type the following:

sudo cp -r flex_sdk_3/ /Developer/SDKs/

5. Edit your ~/.bash_login to include the following line:

export PATH="/Developer/SDKs/flex_sdk_3/bin:$PATH"/

This will add the binaries to the path. If this file doesn't exist yet, go ahead and create one. Next, create a new terminal window to have the right binaries in your path.

6. Try it out. Create a file named "helloworld.mxml" and paste the following into it.

<?xml version="1.0" encoding="utf-8"?>
 
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    viewSourceURL="src/HelloWorld/index.html"
    horizontalAlign="center" verticalAlign="middle"
    width="300" height="160"
>
    <mx:Panel
        paddingTop="10" paddingBottom="10"
        paddingLeft="10" paddingRight="10"
        title="My Application"
    >
 
        <mx:Label text="Hello World!"
           fontWeight="bold" fontSize="24"/>
    </mx:Panel>
</mx:Application>

Make sure there is no whitespace before the XML declaration (the

7. Try it out. Go back to your terminal and type (from the directory where helloworld.mxml is) type the following:

mxmlc helloworld.mxml

This will compile the file using the Flex 3 SDK. It should create a file in the same directory called "helloworld.swf".

8. Open up helloworld.swf in Firefox. If you have Flash 9 installed, it will show you your compiled Flex application!


SQLAlchemy Migrations

Migrations are useful for emerging projects because they allow developers to evolve their models, and incrementally define schema change scripts so that old database records can be upgraded and downgraded easily.

When I started using Pylons, I set up a tinderbox to allow a 2nd copy to live for our team to play with the system and create data structures. In order to allow this data to live between major model changes, this meant I had to find a way to manage migrations. Using "sqlalchemy-migrate", I was able to achieve just that. Here's my quickstart on how to get up and running with sqlalchemy migrations under pylons. Now whenever I update my tinderbox (it's not automatic quite yet), I just run "svn up; python dbmanage.py upgrade".

Quickstart Guide:

1. Install sqlalchemy-migrate

sudo easy_install sqlalchemy-migrate

2. Go to your project directory

cd myapp

3. Create your sqlalchemy-migrate repository in your project

migrate create myapp/migrations/ "MyApp"

This will create the directory "migrations" in your myapp/myapp/ directory.

4. Add the migrate tables to your database:

migrate version_control mysql://user:pass@myhost:3306/database myapp

5. See what version the repository is at:

migrate version banyan/migrations

4. Create the dbmanage script. This is mostly a configuration script to make sa-migrate easier to use.

migrate manage dbmanage.py --repository=myapp/migrations/ --url=mysql://user:pass@myhost:3306/database

5. Create the first migration script

migrate script "Add initial tables"

Other documentation says to do 'migrate script script.py', but this didn't work for me properly. What this will do is create

6. Edit your first migration script.

Open up the file in your favorite editor, and change it to meet your needs. In my case, it looks like this:

import time, datetime
from sqlalchemy import *
from migrate import *
 
meta = MetaData(migrate_engine)
 
users_table = Table('users', meta,
                    Column('id', Integer, primary_key=True),
                    Column('email_address', Unicode(255), unique=True),
                    Column('display_name', Unicode(255)),
                    Column('password', Unicode(40)),
                    Column('created', DateTime, default=datetime.datetime.now)
                    )
 
def upgrade():
    # Upgrade operations
    users_table.create()
 
def downgrade():
    # Operations to reverse the above upgrade
    users_table.drop()

7. Test your new script.

python dbmanage.py test

8. "Commit" your changes.

python dbmanage.py upgrade

Note, the documentation I read said to use the command "commit" instead of "upgrade". I have no idea why this is, the dbmanage script doesn't know what to do when you ask it to commit. When you upgrade though, it will run the changes to your database, and change the migrations version from 0 to 1.

9. Rinse and repeat.
Do steps 5 through 8 to whenever you have new database changes you want to add to your database.

Here's another example to show an alter. The module migrate.changeset allows you to alters that SQLAlchemy at this time does not.

1. Create another revision script.
Lets say we wanted to change the column display_name to first_name, and add a last_name column.

python dbmanage script "Change display_name column to real names"

2. Edit that file.

My one looks like this:

import time, datetime
from sqlalchemy import *
from migrate import *
import migrate.changeset
 
meta = MetaData(migrate_engine)
 
users_table_new = Table('users', meta,
                    Column('id', Integer, primary_key=True),
                    Column('email_address', Unicode(255), unique=True),
                    Column('first_name', Unicode(255)),
                    Column('last_name', Unicode(255)),
                    Column('password', Unicode(40)),
                    Column('created', DateTime, default=datetime.datetime.now)
                    )
users_table_old = Table('users', meta,
                    Column('id', Integer, primary_key=True),
                    Column('email_address', Unicode(255), unique=True),
                    Column('display_name', Unicode(255)),
                    Column('password', Unicode(40)),
                    Column('created', DateTime, default=datetime.datetime.now),
                    useexisting=True
                    )
 
def upgrade():
    # This assumes we're moving all existing accounts to have their first_name
    # be their previous display_name
    users_table_old.c.display_name.alter(name="first_name")
    # Note the above users_table_new has a new last_name column already defined in
    # it. This column has not been created yet in the database, so we will do that here:
    users_table_new.c.last_name.create()
 
def downgrade():
    # Again, for every upgrade, we have to have a downgrade
    users_table_new.c.first_name.alter(name="display_name")
    # Any downgrade will result in loss of last_name data with this script.
    users_table_new.c.last_name.drop()

3. Test the changes (again).

python dbmanage test

Everything good?

4. "Commit" the changes (yes, again):

python dbmanage upgrade

Awesome! If you have anything to add or catch any mistakes, please drop me a comment.


Win-Win Software

The power of social bonds is so important, and it's what powers two web apps that I'm very fond of, Causes and StickK. Each service helps non-profits, and each encourages positive change through positive interaction.

Causes allows Facebook users to create a cause associated with a non-profit. When you create a cause, your friends are notified through the news feed. When you get someone else to join the cause, you get credited for recruiting them. When your friend donates, they get listed as a top donor, and their friends get a notification in their feed. Then, you get listed as a fundraiser because your friend who you recruited, also donated. Every positive interaction leads to either awareness or fundraising for the cause. Not only that, but every action makes people feel good, and lets their friends know what they've done.

StickK on the other hand is a bit different. The positive change can be for yourself or for a charity. You pick a goal, for example "Do 20 sit-ups every day for three weeks". After that, you set the stakes (in my case $200), which I decided would go to a charity if I failed to meet that goal. Next, I set an impartial friend as my referee, and then inputted a list of supporters to encourage me. When the three weeks is over, my friend will have to decide- did I do 20 sit-ups *every* day? If he thinks I failed to meet my goal, the money will go to a random charity. If not, I get the $200 back, and put it towards a Wii. Either way, someone wins. In fact, either way, we both win. Now I have an economic push to meet my goal.

Both services rely on friends, which I believe is a great model. Causes to date has raised $59,215 for breast cancer. StickK hopefully will get me into a routine, which this programmer sorely needs. I'm impressed when software creates positive interactions between people, but I'm in awe when that same software causes positive change in the world around us.

  • Filed under: Web Apps
  • Published at: 11:28 am on June 9, 2008
  • Comments: no comments
  • Written by: admin