Don't forget to...


Sunday, December 25, 2011

Ruby on Rails Testing tools

These are a summary of the tools I've been able to get working on my Ubuntu 11.10 machine for use while testing & developing with Ruby on Rails, while going through the book Ruby on Rails 3 Tutorial, M. Hartl


for up-to-date installing instructions, go to

Saturday, November 26, 2011

Rails on heroku

Just found out that the new Rails 3.1.3 can be deployed to heroku using 'heroku create --stack cedar' instead of 'heroku create'.  By doing this, the only thing you have to change in the Gemfile is delete the line 'gem sqlite3' and add the following:

group :development, :test do
  gem 'sqlite3'

group :production do
  gem 'pg'

then commit and push to heroku.

Friday, November 25, 2011

Deploying a Rails 3.1.1 app to heroku using Ruby 1.9.3 and Ubuntu 11.10

Hello friends. :P

I (FINALLY) got a Rails app working on heroku!  But it took some doing - even the basic template rails app wouldn't work on heroku!  And the getting started walkthrough on the heroku website didn't tell me what to do about the errors.  I'm still not sure if it's my OS that makes this trickier than advertised, or if it's the version of Ruby or Rails that I'm using...or maybe it's heroku's problem?  Oh well.  But here's my setup, and if you've got the same then this tutorial should work for you.  This tutorial assumes you've already setup your heroku account.

Operating System: Ubuntu 11.10
Ruby version : 1.9.3p0
Rails version : 3.1.1
Source control : Git

 First off, if you haven't already, generate a stock app, and enter its directory :

>rails new my_app
>cd my_app

Next, initialize a new Git repository, and add everything to it :

>git init
>git add .
>git commit -am "Initial commit."

now, open up the file called 'Gemfile' in a text editor, and add the following code to the very top of the file:

if RUBY_VERSION =~ /1.9/
   Encoding.default_external = Encoding::UTF_8
   Encoding.default_internal = Encoding::UTF_8

and then add the following code just underneath the word 'end' after the 'group :assets do' section :

group :production do
  gem 'pg'
  gem 'execjs'
  gem 'therubyracer'

now save the file, commit it to git, create a heroku app, push it up (and don't forget to run 'heroku rake db:migrate' if you have a database running in your app already) :

>git commit -am "updated Gemfile to work on heroku."
>heroku create
>git push heroku master

Now navigate to the url that heroku gives you, and your app should (finally) be running!  Congrats.

Friday, October 7, 2011

Adapter Design Pattern

The adapter pattern is an extremely useful pattern for a few reasons. The reason I like it so much is because if you understand it, then you understand the concept of Dependency Inversion (the "D" in SOLID object-oriented design).

Dependency Inversion is an object-oriented principle which states that in code, higher level modules should not depend on lower level modules. Instead, lower level modules should depend on higher level ones. Let's say you've got one higher level object that requires a lower level object to do it's job. But the lower-level object is likely to change or be swapped out for another. Here's the bad way to do it:

namespace HigherLevelModule
    public class HigherLevelObject

        public void Run()
            LowerLevelObject obj = new LowerLevelObject();
            string result = obj.GetSomething();

namespace LowerLevelModule
    public class LowerLevelObject

        public string GetSomething()
            return new String("you got me!");

Now, the reason that this is bad, is because it makes the task of swapping out the lower level object more difficult than it needs to be. The higher level depends on the lower level! LowerLevelModule can be compiled without HigherLevelModule but not vice versa - which is the opposite of what we want.

So here's a better version:

namespace HigherLevelModule
    public class HigherLevelObject

        public void Run()
            IAdapter obj = LowerLevelObjectFactory
            string result = obj.GetSomething();

    public interface IAdapter
        string GetSomething();

    public class LowerLevelObjectFactory
        private static LowerLevelObjectFactory Factory =
                                new LowerLevelObjectFactory();
        private LowerLevelObjectFactory()

        public static LowerLevelObjectFactory GetInstance()
            return Factory;

        public IAdapter GetLowerLevelObject()
            return new LowerLevelObjectA();


namespace LowerLevelModule
    public class LowerLevelObjectA : IAdapter

        public string GetSomething()
            return new String("you got A!");

    public class LowerLevelObjectB : IAdapter

        public string GetSomething()
            return new String("this time you got B!");

With this new code, the higher level doesn't care what the actual type of the ILowerLevel instance is, it just cares that it has a GetSomething() method, which is guaranteed by the ILowerLevel contract. Now the higher level can use the factory method to create lower level objects all over the place, and if the type of the lower level object ever has to be changed, there's only one line of code that needs to be changed:

public IAdapter GetLowerLevelObject()
    return new LowerLevelObjectB();

Now THAT's maintainability. Wurd.

Wednesday, October 5, 2011

Command Design Pattern

The command pattern is best used when you have a command that must be executed by one object, while another object has the responsibility of deciding WHEN that command will be executed.

The three entities associated with the command pattern are:

client: the object that CREATES the command object and assigns it's receiver receiver: the object that HAS the method that will be run invoker: the object that DECIDES WHEN the command will be run
Now let's look at an example. You have an IDE, and the 'undo' command is extremely important. Every action that is performed on the IDE has a method called undo() on it. But the actions have to be stored somewhere after they perform their task though, so that it's possible to call the undo() methods later, right? The solution is to push each action onto a stack when it's run, and register a listener for the 'undo' keyboard-combination/menu-item. The listener will pop() the stack, and invoke the popped action's undo method...voila!

So what are the entities? The module in the IDE that pushes each action onto the stack is the client, each action on the stack is the receiver, and the listener is the invoker. The actions can also be thought of as command objects.

Tuesday, October 4, 2011

Flyweight Design Pattern

So you have a group of objects that can be reused, but each time you use one you have to create it first. The problem is that instantiating these types of objects is expensive, and you don't want to instantiate the same kind every time you need it. Enter Flyweight design pattern. With this pattern, the trick is to create a new object only when you've never created that same type of object before - if you HAVE created it before, then simply look it up and use the one that's already instantiated. Here's some code:

public class Flyweight
    public static Dictionary _Table = new Dictionary();

    public ISomething GetSomething(int key)
        ISomething something;
        if(_Table.TryGetValue(key, ref something))
            return something;
            something = new Something(key);
            _Table.Add(key, something);
            return something;

What this code does is ensure that the only time an object of type ISomething is instantiated is when there's a type requested that hasn't been requested before. Otherwise it'll return the one that was requested before. The GOOD: saves clock cycles by instantiating each type only once. The potentially BAD: uses more memory than creating new instances on the fly. Cheers.

Monday, October 3, 2011

Factory Design Pattern

The factory pattern is used when you want to separate the creation of objects from where they'll be used.

For example, say you have one object that must get a Triangle object and draw it on screen. It doesn't care about what the triangle's state is, just that it has a void Draw() method. Suppose further that you have many types of triangles, and they can all be 'drawn' onscreen. In order to separate the creation of triangle objects from the caller, we would use the Factory Design Pattern:

1.) Create an interface called ITriangle, with one method : void Draw()
2.) Have all types of Triangle implement ITriangle.
3.) Create an interface called ITriangleFactory with 1 method: ITriangle GetTriangle()
4.) Create a concrete 'factory' class for each type of Triangle, each of which implements ITriangleFactory, and returns a new instance of their respective triangle in their implementations of GetTriangle()...since each Triangle type implements ITriangle, each factory can return whatever type of triangle it wants.

Now you can easily add triangle types in the future and change the type that is drawn by the caller, without changing every line of code that references the triangle:

public void callerMethod(ITriangleFactory factory){
    ITriangle myNewTriangle = factory.GetTriangle();

In the above code, if you want to change the type of triangle drawn, simply change the type of factory passed into callerMethod(). The rest is already taken care of.


Friday, September 23, 2011

Coding Fun

I was coding at work the other day and was having a great time. Things were moving fast, and no roadblocks were coming up. Then I asked myself : what's the difference between what I'm doing now and what I'm doing when I do when I'm not enjoying a coding session (other than the fact that I had no major roadblocks appearing)? The answer was pretty clear. I was writing tests first! It wasn't always easy; often it's difficult to think about how I should test a certain functionality when I haven't even designed a solution or written the method or section of code...but it usually pays off afterwards, when I know exactly what is required by the caller/user (should be in the test) and I've already come up with an interface for the functionality (designed by writing the test). After that, all that's left for me to worry about is solving the problem and turning that nasty red 'test failure' light to a bright, tangy green. Just the fact that green and red are used to symbolize passage/failure makes coding more interactive and fun - you get instant feedback on your work :p So the next time you find yourself bored or annoyed while programming, grab your required version of the xUnit framework, and write a test...then make it compile and fail....and then make it pass! It can be the difference between a :D and a >:(

Wednesday, September 21, 2011

A quick reminder

Not much to do with technology, but a helluva lot to do with progress. If you've got any goals in your life right now, you need to read this.

Monday, August 8, 2011

Deploy an ASP.NET MVC 2 Web site on IIS 6.0

Hey sports fans!

Today I was given the task of deploying my web site to my development machine. With MVC 2 plugged-in to Visual Studio 2008, it should have been a cinch (with VS2010 and IIS7, it IS), but I ran into some roadblocks I thought I'd blog about.

So all I thought I would have to do is right click the ASP.NET project in the solution explorer while the solution was open in Visual Studio, and click publish, and then specify the directory to publish it to. Visual Studio was supposed to do the rest. But ACTUALLY it was much tougher. First I had to open the properties of the ASP.NET project, and go to the "Web" tab, and set it to run on an IIS server instead of a development server. THEN I took the step of right clicking the project and (publish...)ing it. But everytime I tried to navigate to http://localhost/ it would give me a weird error saying the directory was inaccessible.

The problem was that IIS had no mapping for paths without extensions. you see "localhost" maps to "localhost/home/index", but what IIS was expecting was something that ends in ".aspx" - so IF "localhost" mapped to "localhost/home/index.aspx", then the page would display and everything would be peachy. But it didn't. So here's how you map something with NO file extension (i.e. a "wildcard" mapping). (I learned it from here: haacked

1.) Open up IIS from the start menu.

2.) Expand the tree so that your website's name is displayed (underneath "Default Web Site").

3.) Right click your website, and go to the properties.

4.) Click Configuration...

5.) Click Insert under "Wildcard application maps"

6.) Enter the location of your aspnet_isapi.dll file (find it by going back and Editing the .aspx file extension in the previous window)

7.) Fill in the other fields the same as in the above pic, and click ok

8.) Keep clicking ok until you're back at IIS. Now try the webpage and it should work!

Saturday, August 6, 2011

Rate my design

Yesterday I worked on refactoring one of the components in my ASP.NET MVC2 project. If anybody's reading and knows anything about software, I'd be glad to have your feedback on the design.

The controller handles all the logic, taking requests from the web and processing/delivering the response. My models are basically just data-transfer objects, and the Views are each strongly typed to a model, so that it can access values given by the controller.

There are 3 different types of views, one inside the other.

The outermost view is not type cast to any model, it just calls some javascript that asynchronously loads _ServerView views into a div element. The _ServerView's are strongly-typed to ServerModel's. The _ServiceView holds the smallest bit of information, and they're loaded one-by-one for each _ServerView. The _ServiceView is type cast to a ServiceModel.

Using this structure, we can have any number of _ServerView views on a page, and any number of _ServiceView views for each _ServerView. This is stuff that the business-side would desire to be configurable. .......Any thoughts? HA!

Thursday, August 4, 2011

Models, Views and Controllers

The MVC design pattern is one of the most widely used design patterns around, but it's talked about so much by experienced developers that sometimes noobs can get mislead as to the meaning and purpose of it. So here's an overview of the design pattern and what it's parts are for.

We'll start with a high-level flow of events:

1.) The user interacts with the user interface, which sends a message to the controller.
2.) The controller receives the message, converts it into a form that the Model can understand and interact with, and then sends it to the Model.
3.) The Model accepts the new information, and makes changes to it's own state reflecting the new information that it's just received.
4.) The view detects the changes in the Model, and updates itself accordingly.
5.) Repeat 1 - 4.

This is very high level and can change a little with every implementation, but the overlying theme and idea is there. Also, the way in which the view detects the changes will vary a lot : it can query the model every so often, there could be an event fired when the Model changes that is detected by the View, or the Model can notify the View.


The Model is the representation of your application's data. Models contain most or all of the business logic of your application.


Views represent the user interface of your application. They provide your Controllers with data from the user, and provide the user with data stored in the application - in the Models.


Controllers connect the Views and Models together. They act as a translator between the two, taking data from the View, translating it into something the Model can understand, and then passing it on to the Model. They can also operate in the reverse direction in many cases.

If you want to use MVC in one of your ASP.NET web apps, checkout ASP.NET/mvc. And Ruby on Rails uses the MVC design pattern too!

Now, if anyone starts talking about how MVC helped them build a solid webpage, you can engage them in conversation. Maybe it's a cute girl who said it? Maybe you can impress her with your Ruby on Rails knowledge by reading the previous post too!


...Love you.

Wednesday, August 3, 2011

Connecting to an API written in C from C#

The last couple of days have been trying for me at work.

Fortunately, I learned something. I was working on an application that needed to connect to a 3rd party API that was originally written in C - like a billion years ago. There was good documentation on the software, but in order to connect to it in C#, I had to go online and find out how from somewhere else. So here's what you do:

First, make sure the API was installed on your system, so that the dll's are registered in the GAC.

Second, start a new project in C#, and create a new class. Make sure to import "System.Runtime.InteropServices". At the top of the class definition, do something like this:

public static extern int MessageBox(int h, string m, string c, int type);

Now, you'll have to know the signature of the methods you want to use from the API first. Anyway, once you declare that the function you want to use is defined externally, and you've told the compiler where it's defined, you can start using the function:

MessageBox(0,"API Message Box","API Demo",0);

This is great stuff to know. You might think that you could just reference the dll in the Solution Explorer in Visual Studio, but if it's not a valid .NET dll, it won't let you do so.

The tutorial I used to figure this stuff out is located here.

One more thing that might be useful to you is passing pointers to variables, especially if you're calling C functions. to do so, just declare the function with the keyword "ref" right before the parameter, like so:

public static extern int blahmethod(ref char[] someVariable, int otherVariable);

And then use ref again when calling the function:

var x = blahmethod(charArray1, someInt);

Tuesday, August 2, 2011

TryRuby today!

Evening code fans.

I'm making some progress on a software system that I'm building at work, and I've started to enjoy the process of finding a problem, creating a solution, and writing code to represent what I've come up with. But now I wanna try something new...

I've been hearing a lot about Ruby on Rails in recent times, and I'm highly interested in it at this point. For those of you who don't know, Ruby is an object oriented programming language, but it's different from Java and C# in that it's a scripting language, so it doesn't get compiled down to machine code before it's run. "Rails" is a framework written for the Ruby language that makes it ridiculously easy to create websites in a Model-View-Controller sorta way. Just to get a basic web server up and running requires only 2 super simple commands on the command line!

A Rails webpage differs from ASP.NET MVC (the stuff I'm using at work) in that it doesn't require Microsoft servers to host it - translation : possibility for FREE hosted webpages using services like Heroku. A few popular sites that run on Rails include :

Yellow Pages
Living Social

for a more complete and prettier list, click here.

Frickin' Twitter! Twitter runs on Rails! An open-source (oh yeah, it's open source too! and has a HUGE community for support, questions, and plug-ins & frameworks for anyone who wants to use 'em) web framework runs one of THE most visited site in the world!

SO all-in-all, I was excited about the possibilities, but I didn't know how to get into Ruby. I mean, learn a new language, just like that? Who's gonna teach me? I'm not even a graduate yet! Lo and behold, I found this awesome site called It hand holds you through the first bit of learning Ruby, and I mean it HOLDS your HAND! It tells you exactly what to type, and what Ruby's doing when you hit enter. I'm also planning on beginning reading a book on the Ruby language called Programming Ruby 1.9. Hopefully something comes of it. If you're interested in web dev, or find coding fun, click the link above to try it out!

Happy coding.

Monday, June 27, 2011

Today I populated an html div element asynchronously using jQuery and JSON in my ASP.NET MVC2 project. Now, when you were 10 years old, did you think you'd one day find a sentence like that above interesting? I bet not. But here's why it is (lol) :

In MVC you're allowed to mix javascript code (client side) with C# code (server side), but you have to understand where each part of it is being run. Here's the code (the important parts of it anyway):

Client side (mostly):

<script type="text/javascript">
$(document).ready(function() {
$.getJSON('<%=Url.Action("GetJsonDriveList", "DiskSpace") %>', function(jsonData) {

for (i = 0; i < jsonData.length; i++) { $.get('<%=Url.Action("LoadDiskSpace", "DiskSpace") %>?serviceAddress=' + jsonData[i].serviceName, function(data) {

Server side :
public class DiskSpaceController : Controller {
public JsonResult GetJsonDriveList()
return Json(GetDriveList(), JsonRequestBehavior.AllowGet);

public List GetDriveList() {
// yada yada

public PartialViewResult LoadDiskSpace(string serviceAddress)
var drives = GetDiskSpace(serviceAddress);
var aDriveModel = new DiskDriveModel(drives[0]);

return PartialView("_Drive", aDriveModel);

jQuery : javascript library that makes it easy to do asynchronous server requests and select elements on a webpage.
JSON: JavaScript Object Notation. Makes it easy to convert C# objects to Javascript objects and vice versa.(e.g. list converts to javascript Array()....etc.)


So first off the client side stuff. That's a script tag you can put on a view (MVC term) and it'll run when the page loads. (OH make sure you've referenced jQuery.js, microsoftAjax.js and microsoftMvcAjax.js first, btw). Everything inside the <% %> tags runs SERVER side, and the other stuff runs client side. And the Url.Action call might seem wierd, but all it does is construct a url that looks like "DiskSpace/LoadDiskSpace" and the "?serviceAddress=..." is the querystring that will be sent with the jQuery GET request.

So the $(document).ready part only runs when the DOM (document object model) is ready. This is the first thing you do ANYtime you run jQuery, as far as I know. Then $.getJSON sends a request to the server and expects a result in the form of a JSON object. When the result is returned, the callback is run, and in the callback we send another request, this time for a PartialView to be inserted into our div element with id "mainDiv".

Now the server side stuff. There's some stuff in MVC that maps the request (e.g. "DiskSpace/GetJsonDriveList") to an action method in a controller. "DiskSpace" is the controller (or the class, to put it simply) and "GetJsonDriveList" is the name of the action method to run and get the result from. So the method is run, and returned as a JSON object using Json(ObjectToReturn, JsonRequestBehavior.AllowGet). The "AllowGet" cannot be left out or else you won't get anything returned and will stare at the screen for hours in a state of frustration!! And then, when the client side receives it, it can be interpreted easily. The next action method that's called has the same idea, but without the json : it creates a View with PartialView("ViewName", modelObject) and then returns it to the client side.

MVC makes web development easy...but jQuery and JSON make it easier! If you wanna make a webpage ever (and you don't know ruby on rails), d/l the plug-in from pluralsight and watch the free screencasts, they're SUPER easy to follow and get you started quickly.

Hope this was...entertaining? ... lol

Tuesday, June 14, 2011

Mono for Android

I'm excited.

I've recently been looking for a way to motivate myself to learn better software development practices, and stumbled on something called mono. No, I didn't get it from kissing someone. Mono for Android is sort of a Visual Studio plug-in which allows one to develop Android applications in C# ! I'm SOOOO happy about this.

Personally, I learned Java in school and tried out Android development for a couple weeks, and liked it. Unfortunately, Java is going the way of the dinosaur, and it seems that .NET is taking it's place. That's why I decided to pursue learning C# instead of Android.

Now that mono has arrived and (hopefully - I'm updating the API's as I type) works, I can pursue BOTH Android development AND .NET ! Basically this means I can get good at working for the man, and developing for myself.

I'm super excited.

For a brief history of mono's inception, check out this blog:

AND if you're a .NET dev and wanna try it out, the trial version is FREE :

Sunday, June 12, 2011

App.Config files

Dear all,

when you use a config file for a Visual Studio application, make sure to do a few things:

1.) Make sure to create an identical app.config file for your test project. Otherwise, when running tests, the config file will not be found.

2.) If you're going to use ConfigurationManager, you have to add a reference to it under the references tab in Solution Explorer.


Tuesday, June 7, 2011

NAnt for automating builds in C# works fine....

I've been learning NAnt the past few days, and it's really quite simple.  Unfortunately, using it with NUnit isn't.  I'm supposed to be able to use NAnt to build my projects automatically and test them too, all with one quick call to a batch file:

./build.bat test

where build.bat just calls nant.exe and passes it a buildfile, which is an xml file that includes "targets" for nant to run.  NAnt compiles my project and my test project just fine, but then when NUnit runs, I get some messed up errors.  I can run my tests properly in Visual Studio using ReSharper, and they behave properly, but it doesnt work on the command line using NAnt...what the crap is up?!

A couple notes for you:
my folder structure is as follows :
src : contains application projects in one folder (app) and test projects in another (test)
build : should be deleted and rebuilt every time NAnt runs
config : contains config files for the project
tools : contains the NAnt folder and the NUnit folder including the exe's and dll's
lib : 3rd party libraries
base : contains the above folders, as well as the .sln, the batch file and the buildfile for NAnt.

There were a few solutions that seemed to work for various scenarios, but I think the one that will work most consistently (and unfortunately is a bit cumbersome) is this:

Use NAnt to clean and rebuild your projects and tests into a single folder (/tmp).  Then, place all the NUnit dll's directly into that same folder.  Any references to NUnit should point to the copy in the tools folder.  Then, when everything is built and the NUnit dll's are placed in the tmp folder, run the tests from the base directory through NAnt by creating a new "target" in the buildfile that runs nunit-console.exe.  The target should have no dependencies. You may also need to add this to the nunit-console.exe.config file:

underneath the configuration opening tag put:
<startup><supportedruntime version="v4.0.30319"/>
and under the runtime opening tag put:

<loadfromremotesources enabled="true" />
I'll have to do this everytime I build, until I figure it out...lame.

P.S. I learned to use NAnt from my bro, and from here:

Monday, May 30, 2011

SQL Server 2005 Hidden Install of Express Tools

A few weeks ago I was given the long-winded task of installing all of the necessary software on my new remote developer cpu at my shiny new job.  All went well until - GASP! - SQL Server 2005 refused to complete its installation.

Now there were actually 2 problems with the install.  You see, it would hang while the status window read "Setting File Security" and it stayed there for what seemed like forever.  This was happening because the remote machine was connected to a network which was monumentally large (it's a pretty large organization) and the install was trying to find all the nodes in the network.  There's a patch for this type of problem that can be used with the installation, but if this is the only problem, the user can also just wait it out.  Which is what I chose to do.  And then the real problem showed up.

After 2-3 hours of waiting (I had other work to do..honest) the installation finally "completed" by giving me an error message saying something like the developer tools were already installed.  So basically, all of the SQL Server components installed correctly, except for management studio...which is the one I needed!

After scouring the internet for days and trying every patch fix and forum tip I could find, I finally found a solution.  But it was dangerous.  I had actually found it earlier on, but hesitated at trying it, as it required me to edit the registry, which I've never done before, and I'm sure could royally screw up my new remote machine.  But at this point I had no choice, as even my coworkers had no idea what was going on.

So I followed directions in the article, and it turns out that on my remote machine (which had been used previously, probably by another programmer) there was a previous install of SQL Server 2005 Express Tools that didn't show up in add/remove programs in the control panel!  It must've been un-installed un-properly.  Long story short, I followed the articles instructions and removed all the SQL Server entries in the database, including that one for the Express Tools.  Then I ran the installation one more time (again, I just let it go for 2 hours to alleviate the first issue) and lo-and-behold, SQL Server was finally installed on my cpu.  Here's the article that made it all worth while:

and here's the article on my page, in case it ever gets moved:

Thursday, May 26, 2011

Adobe Flex 3.0 - Passing parameters to event listeners - actionscript

So I just started this job, and I'm writing an application that lets users view photos and tag them, giving descriptions of the tags as well.  I was trying to add an event listener to a Text object, when I realized there was no way to add a parameter to it!  Because the addEventListener function goes like this:

var itemToPass:Object;
textObject.addEventListener(MouseEvent.MOUSE_OVER, callbackListenerFunction);

there was no way to pass a parameter, except for the event object, which is passed automatically.  Of course you could use an anonymous function for the callback, like this:

var itemToPass:Object;
textObject.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event):void {

And this will work in many cases.  But the underlying problem is still there!  You see, if you change the value of itemToPass later on in the current code block, then the value that's passed into callbackListenerFunction is ALSO changed!  The code I had at first was something like this:

for each(textObj:Text in TextObjectList)
    var itemToPass:Object = someValue * whatever;
    textObject.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event):void {
        var param1 = itemToPass;


which may seem like a good solution to the untrained eye....or brain...whatever.  The problem is the way Flex 3.0 (or actionScript, I dunno) instantiates and stores variables.  You see, in most object-oriented languages, when you instantiate a variable, it's value is only available within the block of code where it was declared, and if it's declared in a loop, then it gets garbage collected and then re-instantiated every loop through. BUT Flex 3.0 doesn't work that way.  In Flex, when you instantiate a variable, it's available for the rest of that entire function or class where it was declared, and if it's declared in a loop, then the variable stays the same, but it's value may change.  So, in the code just above, I was passing the exact same value to all the listener functions for all the Text objects! - Whatever value itemToPass has on the last loop execution.  The solution is to put whatever's inside the loop in it's own function.  That way, every time the loop executes, a new function is started and new variables are instantiated.  Here's the code:

for each(textObj:Text in TextObjectList)
    helperFunction(someValue:int, whatever:int);

private function helperFunction(someValue:int, whatever:int):void {
    var itemToPass:Object = someValue * whatever;
    textObject.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event):void {
        var param1 = itemToPass;

So there ya go.  If you ever have an issue like that again, you know where to look for the solution.


Sunday, April 24, 2011

Hosting a Website Right on your Windows Machine!

Hey cyberfreaks!

Okay, today my bro showed me how to host your own website off of your own computer...and it's REALLY easy, if you've got the right tools.  FYI this post is really for my own reference, but if you have Windows with Internet Information Services (IIS) installed, then this is a quick and dirty tutorial to get to hosting your own site off of that cpu you're reading this post on...right now!  Here we go...

First find your network/router/home's IP address (visible to the entire internet):

1.) Go to, click 'SHIELDSUP!' in the 'Services' drop down menu, and then click proceed.

2.) Now click the 'All Service Ports' button.

3.) Your computer/network/router's IP shows up (the one visible to the entire internet).  Copy it somewhere safe.

Second, you must register a domain name:

1.) Go to and click the link near the bottom left that says 'Dynamic DNS Service'.

2.) Follow the directions and get a host name, and use the IP that we found in the last section, which is the address of your network/router, visible to the entire internet.

Next, you must setup your router to direct incoming requests to your site to go to the right cpu (probably not necessary if you don't have a router) :

1.) Open a command prompt (start > cmd).

2.) Type 'ipconfig' and scroll up to where it says IPv4 address and Default Gateway.

3.) open a new tab in a browser and type in the default gateway IP address.

4.) enter the username and password (it's likely admin for username and blank for password if you haven't set it).

5.) Set up a virtual server by opening port 80 and redirecting all incoming traffic (requests) on your router's port 80, to port 80 of the IPv4 address from the ipconfig call in the command prompt.

6.) Make sure the configuration is enabled before you finish.

What this does is redirect all incoming requests that your router gets on port 80 to port 80 on your local machine (the IPv4 addy from the ipconfig call).

Setup the site in IIS:

1.) Go to the start menu, and type in IIS.  You should get a menu item called Internet Information Service (IIS) Manager.  If you do have it, click it.  If you don't, then you may not have IIS installed on your cpu.  Google it, get it installed and come back here!

2.) In the dialog box, for site name put anything, it doesn't matter.  For the Physical Path, navigate to a directory of your choice.  Preferably put it as close to the C: (or another partitioned drive) as possible.  Otherwise you might run into security/accessibility problems when trying to access the site from a browser.

3.) For the host name, type in the host name that you selected when you set up your account.

4.) Click ok.

5.) If you haven't already, save a file called 'index.html' inside the directory you selected for Physical Path when doing #2 in this section.  Enter some html in the file so you know it's working, like so:

Hi there, I'm a website!

6.) Open a new tab in a browser, and navigate to /index.html

7.) This should navigate to your site!  Congratulations, you're hosting your own custom built website!

Now, when you're not working on it or you don't want it to be running, it's a good idea to go back into the router configuration from the 3rd section, and disable the virtual server.  This protects against attackers trying to get into your network or do something malicious.

Saturday, April 9, 2011

Scrum Master - Agile Methodologies

I was searching for videos and information about agile software development to help me better understand why it's so popular these days, and why I should learn more about it, and I stumbled upon this video.

It explains, very elegantly, the agile development practice called SCRUM.  If your into software dev. it's a must-watch!