8
Apr

Agent Based Systems Development

   Posted by: admin   in Uncategorized

What used to be my fun side projects has quickly become my job. I’d like to continue that cycle by finding new side projects that are fun and challenging. I also like to find projects that I actually think would be something new and interesting that people would appreciate. An idea came to me recently that brought together a lot of past ideas in a new light. When I did some research on it I discovered that that topic area is called “Multi-Agent Systems” or “Agent Based Systems” http://en.wikipedia.org/wiki/Multi-agent_system

What is it?
Agent based systems have multiple independent entities called agents that can communicate / and cooperate. I was happy to find that there are some applications that exist to do simulations and modeling: http://www.cs.gmu.edu/~eclab/projects/mason/ and some standards on programming these systems: http://jason.sourceforge.net/JasonWebSite/Jason%20Home.php

Why?
The appeal is obvious. This approach is not very well developed in computing and robotics. Communications between systems (agents) are plentiful and always improving. Like with people, multiple systems working together can be much more powerful than thier simple sum.

A new implementation!
All of the multi agent systems modeling apps I found are in Java, I’m starting my project in ActionScript. I plan on extending portions of it to use AIR as well. I like Actionscript due to its natural abilities to communicate and be visual. One of the main focuses of my implementation of the agent based model will be on the monitoring, management, and repair of the complex systems. Even in small Agent implementations that are just for a fancy presentation it’s interesting to see the number agents, their status, type etc.

I won’t type out all of my ideas here. I wanted to just put in a quick note on the subject in case any of my colleagues would be interested in sending me tidbits in this area or following my progress. The new projects will start out at http://AgentBasedSystems.com

I had a need to create an extension to IE. When I did my initial research I couldn’t find anything that seemed to address the subject. Since Internet Explorer is the most commonly used browser on the internet I knew I was doing something wrong. Apparently I didn’t even know the propper terminology to use for what I was doing.

The most basic extension to Internet Explorer is called a “Browser Helper Object” or BHO

just knowing that would have saved me a couple of hours.

A Browser Helper Object is in the form of a .dll that is intended to interact with IE. Other things like toolbars can be built on top of it.

Creating a BHO: anything that can compile a .dll can be used. It’s easiest to find references that are in Visual Studio and C++ or Visual Basic.

Development: The development is deceptively simple once you get started. There are a few basic methods that are required like getSite and setSite. These can both be very quirky so I suggest referring to a tutorial to create these most basic methods: http://msdn2.microsoft.com/en-us/library/bb250489.aspx once you have the basics methods setup you have to get yourself acquainted with a new lirary of features know as MSHTML which allows you to interact with IE and the documents it references: http://msdn2.microsoft.com/en-us/library/bb498651(VS.85).aspx

as usual it helps to have code to look at, I suggest browsing the projects at CodeProject, I found many there that were helpful.

There are a few distinct things that a BHO can do that you can’t do easily with anything else (At least for IE).

  1. Create interaction between the desktop applications and the web
  2. Simulate user interaction, that is transparent to sites.
  3. Bypass cross site security restrictions
  4. DOM manipulation on any site.

I only found 1 boook that even mentioned Broowser Helper Objects, and it was very useful. Unfortunately it’s only for VB

http://safari.oreilly.com/1565926706/ch12-94108#snippet

Once you have the BHO developed, what ties it to Internet Explorer is that it has to be linked to IE in the registry. The process is spelled out in the tutorial I linked earlier. It’s very easy to see if the connection to IE exists by looking at the “Manage Addons” menu.

I hope that helps launch someone starting the process.

I have contributed to open source projects ever since I knew what the term meant. I didn’t see the real benefits until I created my own projects, or completed modules for existing projects. Now that I have been doing that for over a year I want other developers and their employers to know the joys and benefits of developing open source projects.

There is an obvious intrinsic benefit of creating something and sharing it with others, and community collaboration, but that’s so surface level I won’t mention it anymore.

When you work in any job that has more than one technical resource, you divide responsibilities. You are often given the responsibility that you are strongest in so that the company can benefit. You might not be in the project from the start or carry it until its finished. You block out your own ideas on the project in order to knock out the next ticket, task or requirement. Over a long period of time, you have done a lot of work but all of the identifiable accomplishments are that of the team. This is all very necessary in order to accomplish an end goal, but what I’ve found is that some smart side tracking can be good overall.

In contrast to the typical workplace; When you create your own project from start to finish every idea is yours. The ones you implemented and the ones you did not. You start to get a new perspective for what decisions need to be made to complete a product at the expense of some lost ideas and compromising standards. As you are developing, you might think of one of the forums you were 0n that was criticizing someone else’s application, so you rewrite half your code just to avoid that same person complaining about yours (You could do this endlessly). As you are developing you find out how much of a niche you’ve been in when it comes to the complete process. You have to create the database, the functions, the presentation etc. there’s a lot to learn in each niche and also a lot to learn in how they work together. You start to gain an understanding for why the DBA needs to be involved early, and why the presentation guy needs to know all of the peripheral components that he’s not working on directly. When you have a product that you think is complete, you go to publish it and realize how far you really have to go. You still have to assign a starting release number and think of a reason it is and how you will progress it. You have to write the documentation. When you get to the install portion of the doc you admit that you would not follow such a long and complicated process, so now you need to write some install routines. Now you have an actual complete package, what will you do with it? If you use other apps as a benchmark you need your own webpage, screenshots, forums etc. By the end you are a bit sick of how much effort there is beyond creating the core product, but hopefully you push through to be proud of something you can release.

By the time you release your project you have learned a lot of things you otherwise would not have had the opportunity to. You put some extra thought and effort into it knowing you’d have your name next to it and people can be rather heartless when review the free software they download. Most importantly, you gain a new perspective for how everything fits together, and logical explanations for why things turn into the messes you work with normally.

After you release it you can get some very good feedback in how to improve you development skills, presentation, etc. You have to be stoic about the process and expect for a few people to just flame you in a non-helpful manner, which in itself is a very useful skill.

From an employers perspective, they have an employee with enough thought to create their own product, drive to implement it and mental agility to learn all the areas necessary to complete it. It’s far better than a training seminar, or college course and there’s something tangible to show for it at the end. If the employer likes the project they can claim it as their own to drive traffic and credibility. If they become a user of the application they will immediately appreciate the completeness of the package including documentation and install routines that are so often missed in internally developed apps. This is something that Google does as a practice and many of their very popular applications were born out of encouraging employees to work on personal projects that were approved. I believe that this is of such an obvious benefit to employers that they will eventually look for employees who have done these projects in the past, because it can tell you so much more about them as a developer than any resume.

Good luck in your Open Source apps and getting them approved!

I have been working with eyeOS lately. I hacked around with some of the existing components, and developed one of my own. I can tell you that after researching every “Web Desktop” and “Virtual Desktop” I could find reference to, this is the best one that you can download and manipulate under an open source license. This project is unique in its approach. They have merged the use of PHP with javascript to seamlessly complement each other and create an actual OS on a web platform. One thing I noticed right away as I started developing with it, is that this team concentrated on creating systems that would be beneficial to having a web environment rather than a bunch of web apps throw together. For example, each running module or “eyeApp” is assigned a serialized process ID which can be used to kill the process, or Identify it. There is a lot of work that needs to be done on it depending on your application for it. The windowing system is done very well but all of the eye candy is not as rich as something like extjs. The PHP is clean and very innovative, but there are many core features that it lacks (Like native DB support). Since I started working with it, I have run across many more projects that are in the same area and I’m still very happy that I chose to go through the learning curve on this one. Here is a summary review to compare with other products: 0-10 style

  1. Cost: Free (Under an Open Source License)
  2. Features: 7
  3. Presentation: 8
  4. Code maturity: 8
  5. Documentation: 4
  6. Community:8
  7. User learning curve: 30 minutes
  8. Developer Learning curve: 3 days

If you have huge $$ to blow and want a commercial product to invest in instead of spending development time customizing eyeOS I recommend checking out the Laszlo webtop.

I have been working on some very challenging projects recently that require retrieving remote pages, manipulating them and then sending them back to the user. There are several problems with this scenario:

  1. Due to a bunch of greedy and malicious hacks, many of the obvious and easier techniques are blocked by necessary security measures.
  2. Whenever you deal with outside code you don’t know what you’re going to get. It could be half formed, have all kinds of javascript workarounds, rely on frames in frames etc.
  3. Relative URLs. If you retrieve a remote page and display it locally, any relative URLs will be off, so links will be broken and image will not show. This also applies to stylesheet and script references.

Here’s the solution in a nutshell:

  1. Use CURL http://us3.php.net/manual/en/ref.curl.php to retrieve the remote page.
  2. Use Tidy http://us3.php.net/manual/en/ref.tidy.php to put the code into a proper XHTML format. This will close tags, give you predictable formatting, make it very easy to read the source and most importantly put it in a format that can be parsed as XML.
  3. Parse the XML using xml_parse http://us3.php.net/manual/en/function.xml-parse.php This is a wonderful function! I have spent hours coding XML parsing functions that recurse, save parents etc. This is a much more efficient method (Depending on your task) it creates 2 arrays, 1 for an index, and one for values. You can use the index to find what position you need in the values array and get any info you need.
  4. Manipulate the cleaned up HTML. Since you have XHTML to work with now you can manipulate it as XML or you can use string replacement. This would be the time to replace all of the relative URLs with Absolute ones.
  5. Display it back to the user! I don’t want to know how you apply this method, I just like coming up with the solutions ;)
7
Sep

MooTools js toolkit review.

   Posted by: admin   in JavaScript, Software Development

I have just completed a project using Mootools exclusively for the javascript.

SELECTORS:

I found the $ and $$ selectors to be extremely useful. The $selector will return a single object based off of a name. The $$ selector will return an array of objects to work with based off of CSS selectors and more. The $$ function is where I found the most power because it allows you to collect a set of elements quickly, recurse through them and apply an action and repeat in very few lines. I used the $$ function to recurse through input elements and add a change event to them. I often had problems with the $$ selector selecting more elements than I wanted. It seemed to be using an “or” on my conditions when it said it would use an “and”. I was able to correct it by trying alternate selectors.

AJAX:

calls and handling are incredibly simple and powerful, but I had difficulty manipulating the return object without putting it in the DOM somewhere first.

DOCUMENTATION:

There is a lot of documentation for Mootools but I came to quickly find out that most of it is just a listing of method or property names, with very few examples. The examples that are provided are very useful. When I posted anything in the forums I got a fast and helpful response.

RECOMMENDATION:

I would recommend this framework to the javascript developer that is looking for a good set of utility libraries and is performance conscious, not an HTML developer that is looking for an easy way to add javascript to their page (For that I’d recommend Dojo). I’m working with jquery now, and I find a lot of the powerful features I appreciated in Mootools are also in jquery. I will write a little comparison between the 2 of them after I have used jquery as much as Mootools.

If you are interested in programming with pure ActionScript 3 code, there is a decent Open Source alternative to Flex, Flash and others. Like most products and especially open source ones, they can be a bit quirky to get started in. So here is a quick guide to get started using Flash Develop for ActionScript 3.

  1. Download the Flex 2 SDK here
  2. Extract the Flex SDK to a directory, make it something easy like C:\Actionscript\FlexSDK
  3. Download Flash Develop here They don’t have a real website. It’s a bulletin board with a topic area for releases.
  4. Open Flash Develop. Goto Tools, Installed Plugins.
  5. Choose AS3, Settings.
  6. Input the Flex 2 SDK location to match the path in step 2.
  7. When you create projects, choose “AS3″ in the Syntax menu, and it will use the settings you just set.

That’s it!
I have found a few workflows in the IDE, but for the ost part it’s a stable alternative. I’ve been able to run all of my ActionScript3 projects from Flex2 without issue.

Here is some code to get you off the ground in Actionscript only programming, in combination with the link I previously provided.

  1. Run Flex Builder, create a new ActionScript Project. Name it whatever you like.
  2. Change the name of the .as file to Main.as
  3. Right click in the navigator window and create a new Actionscript file and name it ObjSpawn.as
  4. Paste the Code for Main and ObjSpawn.as into their respective files.
  5. Run the program.
  6. Read through the comment in the code that explains the structure and syntax.

This project is very simple, so there isn’t a lot going on to confuse you if you are picking this up for the first time.

Main.as

package
{
    import flash.display.Sprite;

    //The class name MUST be the SAME as the filename that contains it.
    public class Main extends Sprite
    {
        //The function with the same name as the class is the known as the constructor.
        //since this is the constructor for Main, it’s the first thing that runs and will control or fire off everything else.
        public function Main()
        {
            //You must declare a variable to use it.
            //If your variable is an instance of an object, then you need to instatiate that object with "new"
            var _Wall:Sprite = new Sprite;
            _Wall.graphics.lineStyle(5,0,100);
            _Wall.graphics.drawRoundRect(0,300,500,10,5,5);
            //the name attribute can be used to quickly identify an object later. You probably don’t want a lot of objects with the same name, so you may add a serialized number to a string for the name.
            _Wall.name = "_Wall";
            //everything that will be displayed MUST be added to a display container. if you do not add the following line or an equivalent to it, you will not see the object you created.
            //This can be used to your advantage because you can build and manipulate an object independatly of when you display it.
            //The order of these child objects determines the depth of the display, where the last child is at the front.
            this.addChild(_Wall);

            //the is calling the custom class I have written, which will call its constructor etc.
            var _Rect:ObjSpawn = new ObjSpawn(100,100);
            this.addChild(_Rect);
        }
    }
}

ObjSpawn.as

// ActionScript file. If you put it in the SAME directory as your main file you don’t need to define the package name, and it is automatically included with Main.
package {
    //These are the libraries required for the script. Without including the correct libraries, the compiler will simply tell you that it can’t find the data types or methods you are trying to use.
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.geom.*;

    //everything in Actionscript 3 must be in a class. When you create a class you can extend an existing class so that it inherits all of the properties and methods of that class.
    public class ObjSpawn extends Sprite
    {
        //a private var or function can only be access by this class and its subclasses.
        //variables are defined as:  accessLevel var variableName:dataType = value;
        private var _XSpeed:int = 5;
        private var _YSpeed:int = 5;

        //a public var or function is availabel to all other classes, even if they aren’t related to this class.
        //function declaration is: accessLevel function functionName(requiredParameters)
        public function ObjSpawn(_width:int, _height:int)
        {
            this.graphics.lineStyle(1,0,100);
            this.graphics.beginFill(0xFF8800);
            this.graphics.drawRoundRect(_width,_height,10,10,0,0);

            //event listeners assign a function to an event. since the event listener is defined inside the class it only applies to this class.
            this.addEventListener(MouseEvent.CLICK, onMouseClick);
            this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }

        //function used for the enterframe event for this class.
        //this fires as many times a seconds as is running on the client, so you may ant to standardize the framerate programmatically.
        private function onEnterFrame(event:Event):void
        {
            //action that looks at X and Y hits separately.
            /*
            if (this.x >= stage.width || this.x < 0)
            {
                _XSpeed = -_XSpeed;
            }

            if (this.y >= stage.height || this.y < 0)
            {
                _YSpeed = -_YSpeed;
            }
            */

            //This looks for a basic collision of 2 objects and takes action.
            if(this.hitTestObject(parent.getChildByName("_Wall")))
            {
                _XSpeed = -_XSpeed;
                _YSpeed = -_YSpeed;
            }
            //call to the movit function.
            this.moveIt();
        }

        private function onMouseClick(evt:MouseEvent):void
        {
            var _Rect:ObjSpawn = new ObjSpawn(0,0);
            this.addChild(_Rect);
        }

        //accepts direction and speed for moving the object. The effect gained from moving a # of pixels on the enter frame event is simple animation.
        private function moveIt():void
        {
            this.x += _XSpeed;
            this.y += _YSpeed;
            //this.rotation += _XSpeed;
        }
    }
}

With the introduction of Actionscript 3.0 I’m going to try to implement some ideas that wouldn’t have performed as well in Actionscript 2.0. Also, now that Actionscript has matured to the point where I’m more familiar with the syntax and methodologies I’m more comfortable in approaching it. I’m much more comfortable with code than the flash interface and timeline.

Here are some links that are both very inspiring and helpful:

This has many examples of element interaction and physics. Each example is segmented so that it’s not complicated by too many things occuring at once, and source code is provided for all of them.
 http://www.entropyswitch.com/3_00.html

This is a physics engine written in ActionScript 3.0, the performance seems very good, and it has a lot of features. This could serve as a basis for collisions, attraction, repulsion, gravity etc.
http://www.fisixengine.com/engine.asp

This is the most impressive display of creative skill applied to flash I’ve seen yet. This guy gives out his source on any of his projects, all of his projects are worth looking at for inspiration and ideas. This guy definately belongs in the “Master” class of Actionscript developers.
http://lab.andre-michelle.com/

This is a project in SourceForge I found where they allow you an interface to draw on a web canvas and then it saves all of the ActionScript code so you can copy and paste it into your apps. This is a great tool for those who don’t care for the Flash IDE and timeline! http://musprite.sourceforge.net/

Here is a blog for someone who wrote and AS3 animation system for others to use. His blog also well done. http://www.boostworthy.com/blog/?p=171

A VERY impressive 3D engine for AS3. http://blog.papervision3d.org/

I’ve decided to use Flex Builder to write my “Actionscript projects” so that I have more of a development interface than the Flash one.
http://www.adobe.com/products/flex/flexbuilder/

 But FlexBuilder does cost some $$ so you may want to check out FlashDevelop: http://www.flashdevelop.org/community/

No matter what IDE you use, you’ll need the languag reference: http://livedocs.adobe.com/specs/actionscript/3/wwhelp/wwhimpl/js/html/wwhelp.htm

Another Extension Library, when the existing language isn’t enough: http://www.senocular.com/flash/actionscript.php

Nice blog I found on Actionscripting http://www.actionscriptarchitect.com/
Good luck on your projects! I’ll be posting mine on this page.

More amazing work: http://levitated.net/daily/index.html

15
Jun

Javascript Error Logging

   Posted by: admin   in JavaScript, Software Development

Javascript Error logging.

Upon investigation this is so incredibly simple I’m surprised it’s not done more often. any javascript error that occurs on a page can be gracefully handled and/or logged. It still makes sense to use a try/catch block for important functions so that you can handle errors at a more specific level. This serves as a good catch all.

W3Schools link

I think this information would be very useful to have and report from if you rely heavily on javascript in your pages. If you have a commonly occurring error you’ll know about it and be able to fix it and monitor the results. The opposite can be assumed as well. If you have a lot of connections from a certain browser / OS combination and you don’t see any errors from those session (Assuming the logging is working) you can assume with some evidence that those combinations are working.

What I did is gather all of the errors up in an XML string and send them through webRTAM so that I could associate it with the rest of the session info being logged.

Page 2 of 3«123»