Ramblings

December 17, 2009

Some notes on python and com using comtypes

Filed under: com, python — michaelangela @ 2:25 pm

CodeProject: Working with custom COM interfaces from Python. Free source code and programming help

There are a lot of tutorials on Python and COM over the Internet, but in real practice, you might quickly be confused just going beyond standard IDispatch things. The same occurred to me when I decided to write unit tests for our set of COM components. The components are rather simple, they implement one custom interface (derived from IUnknown) and one outgoing IDispatch interface for events.

First, I tried to use the standard pythoncom module, but it turned out that it didn’t support custom COM interfaces. Then, I downloaded the comtypes package and started playing with it. Due to a lack of documentation, it took me about one night to write a simple example. So, here is a step-by-step guide on how to begin using comtypes.

up next…

Python Order2Go Example – DailyFX Forum

For all Python programmers out there that like to play a little with Order2Go:
(On Windows Platforms only)

These are of interest specifically because they deal with getting events from the COM objects and handling them.

Advertisements

Doh! No more testing IE on a Mac now?!?!

Filed under: ie, parallels, virtualization — michaelangela @ 2:21 pm

So I have Parallels 5, and I was about to do some tests but hadn’t gotten things up and running on this box before so I went, did the 500_MB download (XP SP3 not Vista!), loaded everything up, and then “eh? activation?”

IE VPC Images now with WGA :: Crisis Averted!

Just when I was on a virtualization roll using VirtualBox for testing IE on my Mac, Microsoft stopped me dead in my tracks. The latest version of Internet Explorer Application Compatibility VPC Images now have the anti-piracy features of Windows Genuine Advantage enabled.

The hardware signature detected when a VPC image first boots in a non-VPC host is different from the signature present when the image was first created, presumably in VPC. This difference triggers WGA’s re-activation requirement to make sure you’re not a dirty pirate. Of course you’re not a dirty pirate, but if you wish to re-activate Windows you’re going to need the original Windows Product Key which isn’t provided with the VPC images. Microsoft has effectively blocked end users from hosting the VPC images with anything but Virtual PC.

December 14, 2009

PathTools and iTerm instead of Terminal

Filed under: applescript, automation, eclipse, iterm, osx, pathtools, Uncategorized — michaelangela @ 9:44 am

So as noted, I tried using PathTools with FleBuilder under Eclipse 3.5 except FlexBuilder just has too many issues under 3.5. I gave up on PathTools with FlexBuilder but it’s been just awesome with the recent JaveEE 3.5 build. I only had one not-even-gripe as there really isn’t anything to complain about. It opens Terminal for the new paths instead of iTerm. Fortunately a little scripting later and it’s all good based on some code from the iTerm site and also this snippet.

You can see in the PathTool preferences what is called in order to do some of the interaction. Launching a terminal in the selected path is simple enough and is located here: /Applications/eclipse/configuration/org.eclipse.osgi/bundles/685/1/.cp/scripts/cdterminal.scpt

Changing that to the following makes it launch iTerm instead, with a little simple error correction. I hadn’t done Applescript stuff before so was just trying it out. I love these little bits of integration/customizations that are possible.

on run argv
set cdTo to item 1 of argv
tell application “iTerm”
activate
— talk to the first terminal
tell the first terminal
— launch a default shell in a new tab in the same terminal
try
launch session “Default Session”
on error
display dialog “There was an error creating a new tab in iTerm.” buttons {“OK”}
end try
tell the last session
try
— cd to the requested cdTo path
write text “cd ” & cdTo
on error
display dialog “There was an error cding to the requested path.” buttons {“OK”}
end try
end tell
end tell
end tell
return
end run

Simpler Java asynch IO with JBoss Netty

Filed under: cool, education, groovy, java, mina, netty, tip — michaelangela @ 3:57 am

I don’t know what this will look like since I am using Scribfire which doesn’t like to deal with code very well… that should be a standard disclaimer on this site! I try to clean it up as best I can within a short timeframe though. ๐Ÿ™‚

I recently wrote about some Java libraries/code that would simplify asynch socket communication. I hadn’t looked far enough! Looking for references on Groovy asynch programming I came across this:

ojug meeting tue oct 20th โ€” grails and/or netty : Omaha Java Users Group

Netty has been getting some press as a potential successor to Apacheโ€™s Mina asynchronous I/O framework for building low-level custom protocols. E.g. previously Iโ€™ve used Mina to talk binary to a card processing system.

And checking in to MINA and Netty yielded some nice info. There is a great little tutorial on writing a simple server in MINA 2. But the simple Netty TelnetClient example was exactly what I was looking for. Specifically:

TelnetClient xref

TelnetClientHandler handler = new TelnetClientHandler();
bootstrap.setPipelineFactory(new TelnetPipelineFactory(handler));

For those more experienced with Java, I hadn’t seen a simpler way to assign what is essentially an event handler. The code I had seen before required using slots and keys or other bits that seemed a bit more verbose than needed. But then again that could be simply because of my inexperience in the language at this point. Seeing this immediately made sense coming from AS3. It’s not a closure like in AS3 where each event gets a method call of some sort, named or anonymous, but just a class that handles the events.

TelnetClientHandler xref

@Override
public void messageReceived(

ChannelHandlerContext ctx, MessageEvent e) {
// Print out the line received from the server.
System.err.println(e.getMessage());

}

Sweet and simple. Once that’s assigned you can go into your “do forever” loop and do the writing that needs to interact with the server.
TelnetClient xref

// Read commands from the stdin.
ChannelFuture lastWriteFuture = null;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (;;) {

String line = in.readLine();
if (line == null) {

break;

}
// Sends the received line to the server.
lastWriteFuture = channel.write(line + ‘\n’);

// If user typed the ‘bye’ command, wait until the server closes
// the connection.
if (line.toLowerCase().equals(“bye”)) {

channel.getCloseFuture().awaitUninterruptibly();
break;

}

}

Even without Groovy this is really straightforward. I guess a Groovy implementation of Netty would reduce all of this to like 3 lines of code? Heh. ๐Ÿ™‚

December 11, 2009

On the road to becoming a software architect

Filed under: dev, education — michaelangela @ 1:56 pm

I can write components, tie them to data with an MVC model and get things done without any guidance except “this is what it needs to do”. A recent post details recommended programming books. I’m in on the first one, Code Complete 2nd Edition, at section 3.5: Architecture Prerequisite. The book is mostly about construction so it doesn’t delve deeply into architecture but it’s an area I want to develop in. The questions being laid out in this section and the previous one (Requirements Prerequisite) are hitting the issues I have had to fight when things aren’t clear from the beginning. This is extremely helpful for me even when not architecting huge projects.

I have one coming up where the client wants a flat XML file to manage all data instead of a backend database. It will be quite a bit of data as I understand it, not having seen it. I have a better idea now of what to ask when I do set eyes on it for the first time (hopefully soon…).

HP SWFScan Flash security tool

Filed under: as2, as3, flash, security — michaelangela @ 10:50 am

Too bad it’s windows only. I wonder if it would run under wine… at any rate the idea is pretty good. I’ll have to do some more reading to see if it lives up to its promise.

Register now to download FREE HP SWFScan and start securing your Flash applications

HP SWFScan, a free tool developed by HP Web Security Research Group, will automatically find security vulnerabilities in applications built on the Flash platform.

Recommended programming books in the queue

Filed under: dev, education — michaelangela @ 5:10 am

I can’t find the site that brought me here. The first one, Code Complete Second Edition, reading now, is quite eye opening and written for someone just like me: the self taught developer. My major in college was East Asian Language and Culture with Japanese as the language of choice. I have forgotten most of the Japanese I learned and instead speak Chinese now. Go figure! The language learning process fascinated me though and I think that helped prep me for a career in development. So when my type was included in the “who this book is for” that really caught my eye.

The next one down, The Pragmatic Programmer, has been on my “want to read” list for a while ever since I heard about the Pragmatic Bookshelf and got some goodies on iPhone development there.

And with #3, Structure and Interpretation of Computer Programs, being available freely online, I can’t pass that up! ๐Ÿ™‚

What is the single most influential book every programmer should read? – Stack Overflow

If you could go back in time and tell yourself to read a specific book at the beginning of your career as a developer, which book would it be?

I expect this list to be varied and to cover a wide range of things. For me, the book would be Code Complete. After reading that book, I was able to get out of the immediate task mindset and begin to think about the bigger picture, quality and maintainability.

Suggest your programming books

How to package a jar for groovy with maven?

Filed under: automation, groovy, maven — michaelangela @ 4:14 am

Unfortunately the docs are still TODO

Building Groovy Projects – GMaven – Codehaus

groovy-jar Packaging
TODO

However there are some helpful links out and about:

NBT Consulting – Groovy with Maven Quick Start

A Groovy based Maven project can come in at least two different packaging/artifact types: groovy-jar and war . For more information about groovy-jar packaging, see http://mojo.codehaus.org/groovy/groovy-maven-plugin/mixed-compilation.html This document contains two sets of quick start instructions depending on the packaging/archive type the Maven project is to build:

  • Option A: Creating a new groovy-jar Package Groovy-based Module Maven Project (Non-web)
  • Option B: Creating a new war Package Groovy-based Module Maven Project (Web)
    • Bonus: Add Some Ajax Examples with GSP as the Server-side

And another example using Processing.org exported code:

NBT Consulting – Processing.org, Groovy and Maven Together Quick Start

This Quick Start Guide will demonstrate how to create, build and run two Processing sketches written in Groovy incorporated into a project that uses Maven to build. According to the book “Groovy in Action”, Groovy can be run in either direct mode or precompiled mode . In this guide, one Groovy script will be compiled to a Java class file (precompiled mode) and the other Groovy script will be left uncompiled (direct mode).

Building groovy projects with maven

Filed under: automation, groovy, maven — michaelangela @ 4:02 am

So now that I know that Java and Groovy can coexist, the next question is can maven be used to compile a groovy project.

Building Groovy Projects – GMaven – Codehaus

GMaven has kick-ass support for compiling Groovy projects with Maven!

And not only that but it can generate POM files for you tooBuilding Groovy Projects – GMaven – Codehaus

To help get Groovy projects started faster, you can use the gmaven-archetype-basic. This will create a new project with the basic POM configuration and some example classes to get you started quickly:

mvn archetype:generate -DarchetypeGroupId=org.codehaus.groovy.maven.archetypes \
-DarchetypeArtifactId=gmaven-archetype-basic -DarchetypeVersion=<version>

Is it possible to add groovy code to a java project?

Filed under: groovy, java, tip — michaelangela @ 3:47 am

Yes and it’s not so crazy either. The fact that you can swap the extension of a Java class to .groovy and continue to build with it in groovy is pretty cool, too.

Wabi Sabi Software: A Tutorial for Adding Groovy to a Java Project

The steps are basically
a) download and install the Groovy GDK
b) add a how-to-compile-groovy task to your Ant build.xml (the task is included in the GDK)
c) add the groovy-all.jar file to your library path
d) add the groovy-plugin to your Eclipse project
e) enable groovy-nature in your Eclipse project
f) write a Groovy class and use it.

Overall this should take no more than twenty minutes or so. One of the really cool things is that once you have a Groovy class you can use it from your Java classes just like any other class…your Java code has no idea its using a class written in Groovy.
Now lets look at the steps listed above in cookbook manner.

December 10, 2009

Java async communication tools tips and tricks… well only 2

Filed under: education, java — michaelangela @ 1:34 pm

Java async communication is no simple matter and these posts highlight the issues as well as provide some solutions. The NIO tutorial is close to what I want but the callback API may bring in the simplicity I desire. I’ve been dusting off the Java portion of my memory and digging in a bit.

Rox Java NIO Tutorial

This tutorial is intended to collect together my own experiences using the Java NIO libraries and the dozens of hints, tips, suggestions and caveats that litter the Internet. When I wrote Rox all of the useful information existed as just that: hints, tips, suggestions and caveats on a handful of forums. This tutorial actually only covers using NIO for asynchronous networking (non-blocking sockets), and not the NIO libraries in all their glory. When I use the term NIO in this tutorial I’m taking liberties and only talking about the non-blocking IO part of the API.

tech: Java : A callback API for epoll(), building on top of Java NIO

I just finished the first draft of the Java callback API that allows you to do asynchronous socket communication using the scalable epoll() mechanism of Linux. This is built on top of Java NIO, so it will take advantage of the best underlying network mechanism the OS has to offer. In Linux 2.6 + /FreeBSD this will likely be epoll().

…snip…

The Java NIO api can certainly be used for this purpose. But using that API is somewhat difficult and there are various caveats you have to guard against. You need to understand the Selector class, SelectionKey class, InterestOps class, SocketChannel class and their interplay. You need to know the logic for canceling SelectionKeys and setting InterestOps appropriately. And you need to understand the cryptic ByteBuffer class and its variants, possibly how the ByteArrayOutputStream works as well. You need to figure out how to use these classes to store the data separately for each connection, keeping in mind that the data will likely arrive mixed. You also should not call select if all sockets have been completely read, or select() will block – which means you will have to keep track of pending hosts.

December 9, 2009

Manual (local or remote) install of maven artifacts needs sudo

Filed under: maven — michaelangela @ 6:04 am

While prepping to what I outlined in my last post about installing a maven artifact manually, I happened to search to see if it could be done remotely since I knew the repository location. That only makes sense considering what maven itself does. This post on the ever helpful Stack Overflow gave the steps but it just wouldn’t work. I even downloaded the dependency:get plugin and successfully installed it with:

sudo mvn install:install-file -DgroupId=org.apache.maven.plugins\
-DartifactId=maven-dependency-plugin -Dversion=2.1 -Dpackaging=jar\
-Dfile=./maven-dependency-plugin-2.1.jar

That sudo is the required bit. It kept failing without sudo until i turned on mvn -e to see exactly what was happening and why it failed:

Downloading: http://repo1.maven.org/maven2/org/codehaus/mojo/exec-maven-plugin/1.1/exec-maven-plugin-1.1.jar
[WARNING] Unable to get resource 'org.codehaus.mojo:exec-maven-plugin:jar:1.1' from repository central
(http://repo1.maven.org/maven2): Specified destination directory cannot be created:
/Users/michael/.m2/repository/org/codehaus/mojo/exec-maven-plugin/1.1

at first glance it looked like it couldn’t download it which is what I assumed. The actual problem was that it couldn’t create the directory! So with this

sudo mvn -e org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=http://repo1.maven.org/maven2/ \
-Dartifact=org.codehaus.mojo:exec-maven-plugin:1.1

it worked.

Now it’s time to see with this installed can I actually run the Marketcetera ORS…
[update]
IT’S ALIVE! The ORS launched though I had to run

sudo mvn -PexecuteDBInit exec:java

to get the database initialized properly. It aborted when running

mvn -Pexecute exec:java

because the table execreports was missing.

Manually installing a Maven artifact

Filed under: marketcetera, maven — michaelangela @ 5:10 am

In an effort to try out Marketcetera’s open source project, I have been working on building the platform on OS X 10.5. Those instructions were for earlier machines so I have been able to get it to build without using Soylatte 1.6 by resetting the default java used to the already installed 1.6.0. Because of out of memory errors I had to boost the memory directly in mvn.sh by adding

export MAVEN_OPTS="-Xmx1024M -XX:MaxPermSize=1024m"

directly after the copyright notice. That got me through the build process. One test has an error causing the build to fail but building it without testing successfully creates the build. But then running it with

marketcetera-platform/source/ors$ mvn -Pexecute exec:java

fails complaining about missing the org.codehaus.mojo:exec-maven-plugin:pom:1.1 artifact. It’s there, but maven 2.2.0 is not actually supported. I should be using maven 2.0.9. After changing back to maven 2.0.9 I tried to do a mvn clean to start over and it complained of another artifact missing: org.apache.maven.shared:file-management:jar:1.2.1. But this time it gave some useful advice:

Missing:
----------
1) org.apache.maven.shared:file-management:jar:1.2.1

Try downloading the file manually from the project website.

Then, install it using the command:
ย ย ย ย ย  mvn install:install-file -DgroupId=org.apache.maven.shared -DartifactId=file-management -Dversion=1.2.1 -Dpackaging=jar -Dfile=/path/to/file

So before I give up on 2.2.0 I’ll try to add this missing file-management artifact and also the exec-maven-plugin as well and see how it goes.

December 8, 2009

sudo visudo and environment variables like JAVA_HOME

Filed under: bash, java, osx, tip — michaelangela @ 3:26 am

I was trying all sorts of incantations to get JAVA_HOME set. None worked. OS X. Bash. .bashrc, .profile, etc., etc. Turns out the following is the problem, and the solution.

sudo, JAVA_HOME and Mac OS X [Article] ยซ elc technologies

The problem is that JAVA_HOME doesn’t get passed to sudo, so sudo cannot access it. I remembered two solutions to fix this problem, one by telling the env to keep the variable and the other by switching to root user and exporting the variable there.

So, the first solution is to make the JAVA_HOME variable available to sudo, first export it and then run sudo visudo and add the following line to it:

Defaults    env_keep +="JAVA_HOME"

[update]
In the end, it had to go in /etc/profile for it to take as noted below. Maven (mvn -v) just would not show the new version of java otherwise and builds done with maven would fail because they targeted the wrong version as well.

Compiling Java 1.6 projects using Maven on Mac OS X

You can declare this either as a one time export in your current shell above, in /etc/profile as I normally do or in any other startup file of your choice. Afterwards be sure to refresh your shell before you try again. This can be done either by closing your current terminal window and opening a new one or by sourcing whichever file youโ€™ve put the above information into.

source /etc/profile

In order to make sure that it has taken effect one can output it in the shell as follows.

echo $JAVA_HOME

If it shows nothing then the shell has not picked up your change.

December 7, 2009

Flex… um… without Flex?

Filed under: as3, cool, flex, mxml — michaelangela @ 12:56 pm

I had just mentioned compiling MXML without using FlexBuilder and did a quick Google on it to see the current state of such integration. Wow this is pretty cool. ๐Ÿ˜› Some neat info and projects in the comments as well including FLit.

Using MXML without Flex (Example and Source) | Ryan Campbell

I made a few minor changes to the MinimalComps project from Keith Peters and got it playing nicely with MXML. The below application compiles to a tiny 23KB yet makes use of MXML and even data binding.

Restaurant API?

Filed under: cool, entrepreneur — michaelangela @ 12:51 pm

I like this concept. I could see people doing this because the start up is low. At first glance it doesn’t seem to be a problem about being a viable business model. The question to me seems to be is it profitable enough to warrant a full-time business. The example given of the 20-day-per-year model suggests it’s not a full-time venture… unless it takes that long to prepare for the event. Perhaps it is a full time venture and they make enough off of it each time that it really works.

But even if it isn’t full time, if there are restaurants willing to be used in this fashion, or just places where food can be prepped can be found, then those places could become known for certain types of dishes and a Yelp style rating could be developed. (Thinking off the top of my head here.) That would be the restaurant api. But in this case it would be very concrete things (no abstract classes or object inheritance here). Oven is good for baking. Sinks too small to work with. Floor space good and flexible. Everything you wish could me is on a cart so you can move it where you want. Etc.

So the idea sounds cool enough and would lower the barrier to entry for new cooks looking to make their mark. In fact what it would be doing is sort of how software tools became cheap enough for average folks to get their hands on things and make something to be noticed. That’s how I got into software development. I used FlashDevelop to do development for a simple MXML app using a remote datasource provided by amfphp. All free stuff. I happened to send it by the API provider as a “hey I put this together and thought I’d show you” and ended up working for them for a year. ๐Ÿ˜› (And learned AS3, bought FlexBuilder 2, got into Eclipse and that whole world and…) I could see the same happening for folks using time-share restaurants.

Upside-Down Examples

Time-Share Restaurants

Speaking with one of my neighbors here in Crested Butte, she started talking about wanting to create a restaurant, which is a tricky business at best and even harder in a resort town with its ebbs and flows and off-seasons.

I mentioned the example given in Seth Godin’s book Tribes, about a restaurant in New York that is only open 20 days a year, on selected Saturdays. You find out and sign up via the web, and they have a full house every time. Because they don’t have to worry about being open at the whim of walk-in customers, they can spend all their time focusing on food rather than being constantly distracted by day-to-day management of a storefront.

We wondered if a restaurant space, or even just a commercial kitchen and searching for spaces that could be used in a guerrilla fashion, could be a viable model. Working with a number of different kitchen users becomes much more practical via the web.

MYSQL database modeling and change management

Filed under: mysql, tool — michaelangela @ 12:23 pm

I currently use Navicat for MySQL to manage databases (especially nice for managing multiple sites via ssh). Change management is always an issue with snapshots being manually handled with data dumps. There are very helpful sync tools within Navicat but I’d like to try this to see if it helps the way I think it will. The partos of particular interest are the change management and, something I need to learn more of, forward engineering of a database.

MySQL :: MySQL Workbench 5.1

MySQL Workbench enables a DBA, developer, or data architect to visually design, generate, and manage all types of databases including Web, OLTP, and data warehouse databases. It includes everything a data modeler needs for creating complex ER models, and also delivers key features for performing difficult change management and documentation tasks that normally require much time and effort. MySQL Workbench is available on Windows, Linux and Mac OS.

The source of my early Java knowledge

Filed under: education, java — michaelangela @ 12:14 pm

Once upon a time I worked for Lucent. I worked with a lot of great people there and had a good time there actually except for the fact that I wanted to telecommute… except I don’t think that term was popular yet. But among the other good things that happened there, I got a chance to learn Java. And somewhere in that course, Bruce Eckel’s name came up and the resources for the class I took might have been based on his materials as well.

At any rate it is now time for a refresher. ๐Ÿ™‚ Java has come a long way since then. Not to mention the computers. I think at  that time my work laptop was around 130MHz beast! But I’d have to ask to confirm that. ๐Ÿ™‚

Note: all links to mindview.net are not working as it seems to be down. mindviewinc.com links work fine though.

Bruce Eckel’s Free Electronic Books

These are electronic books in HTML on C++ and Java, along with the source code. The HTML books are fully indexed, use Frames for easy navigation through the chapters, and have color syntax highlighting on all the source-code listings. Each HTML download contains an entire book and source code in a single zipped file.

AS3 Design Patterns

Filed under: a3s, design patterns, education — michaelangela @ 12:12 pm

Following up on the recent find of PHP Design Patterns, here is a talk from the very resourceful London Flash Platform Users Group. There is a PDF included but it’s more of a general overview. I hope to get through this presentation soon. Template and reactor I haven’t used and MVc (as opposed to MVC) is a variation I wasn’t aware of.

London Flash Platform User Group ยป Blog Archive ยป Practical Design Patterns for ActionScript 3.0

Decorator; reactor; model view controller; model view presenter; model view little c; template; and reactor. These are just a few of the standard design patterns. There are hundreds out there and it is easy to feel a little lost. I hope to explain some of these patterns and their uses, along with their benefits and cost of use.

[update] There is a book on Actionscript 3 Design Patterns with a companion website. There you can find the aptly titled ActionScript 3.0 Design Pattern Starter Kit. Nice.

git on the command line

Filed under: git, tool — michaelangela @ 12:07 pm

When I get more into git this could be nice. ๐Ÿ™‚

shaun smith ยป OS X Git Prompt

Iโ€™m currently using a modified version of git-prompt that looks something like…

Free (to a point) screen-sharin and web presentation… with an open source community version

Filed under: cool, tool — michaelangela @ 12:02 pm

This looks quite interesting. And the open source version is available to boot.

DimDim Works Well

Over the years I’ve tried numerous different screen-sharing and web-presentation solutions, and most of them have required some kind of adjustment in order for them to work decently. Usually you need to reduce your screen resolution in order to get decent performance, but DimDim didn’t seem to need this. The responsiveness seemed quite tolerable.

Reading chm on OS X

Filed under: cool, osx, tool — michaelangela @ 8:09 am

Nice. Will be trying this out shortly. This was mentioned in comments here.

iChm – Cocoa CHM Reader for Mac OS X and iPhone/iPod Touch – ็Ÿณ้”…ๆ‹Œ้ฅญ

iChm for Mac
Features

* Fully built with Cocoa. No ugly window and slow rendering.
* Tab browsing
* Search. Result sorted by relevance.
* Text encoding detecting/switching
* Find in the page
* Tag powered bookmark
* Index
* Back/Forward
* Text zoom
* Export to PDF
* Continuous reading with Page down/Page up

Robotlegs framework and programming to an interface

Filed under: as3, cool, education, frameworks, puremvc, robotlegs — michaelangela @ 8:03 am

Actual code samples makes things make so much sense. And this is a great example of the (new to me) Robotlegs framework. I really like what I see. The following post has the same small app in several different frameworks.

Robotlegs example project with source

Any comparison of frameworks wouldn’t be complete without Robotlegs. I included Robotlegs in my session at LFPUG recently, but didn’t post the example project here because the framework was in a state of flux. Robotlegs is now settling down as it approaches its imminent 1.0 release, and the MVCS implementation in it is unlikely to change further, so here’s my example.

For this Robotlegs example I’ve used exactly the same project as in the previous examples for other frameworks. Robotlegs is not prescriptive about your application’s architecture, but it does include a default MVCS implementation for those that wish to use it. I’ve used that default implementation here.

Working with this kind of code outside of some sort of IDE or at least a well known convention could be a little baffling. For example, for this project, small though it is, sets the feeds with interfaces and not the actual feeds. This goes along with the principle of “Program to an interface, not an implementation” which is good and flexible. But to a newbie it might a bit confusing. (See here for a discussion about extending AS3 using interfaces, or rather the difficulties in doing so.)

FlexBuilder is a great IDE for AS3, granted there aren’t many. And for those with far more experience in more mature languages like Java with its plethora of incredible tools, it really pales in comparison. But it’s a far cry better than the Flash AS editors! I bring that up because I often learn code by the awesome Command+click (Ctrl+click on a PC?) to jump to the definition of a variable or a class. Opening up Flexcaster.mxml shows a context “FlexcasterContext” and a MainView. I was completely new to IoC programming with its dependency injection. So I didn’t know at that time that a context is a term commonly used in IoC. But I knew it’s an MVC framework so I figured the code I was looking for wasn’t in the view. ๐Ÿ™‚

Clicking on the FlexcasterContext brought it up which showed where the magic happens: how everything is connected. Of note though are these two lines:

injector.mapClass( IFeedsService, OpmlFeedsService );
injector.mapClass( IFeedService, RssFeedService );

This lets me know that wherever I see IFeedsService it’s actually using OpmlFeedsService, and the same for RssFeedService and IFeedService. Through the rest of the code you won’t see any reference to OpmtFeedsService or RssFeedService. This context is the only place I would see where the connection is made. The author actually brings this issue up in a different version that also uses IoC but instead of events, it uses Signals.

All in all I think it worked out rather well. There may even be a potential future in an architecture like this. I do fear the explosion of interfaces and injection rules may make the approach unwieldy for a large project, but perhaps multiple DI configuration classes, a clear package structure and disciplined developers is all that’s required. I welcome your opinions on this.

There is more discussion there. Of course the immediate benefit of programming to an interface is that swapping out a class is a one line change instead of refactoring all affected code. Making mock data objects for the model while testing is a great example of that. It could instead be

injector.mapClass( IFeedsService, TestOpmlFeedsService );<br />

when doing tests which simply returns a preset array of data.

Overall I have to say I like the conciseness of the code. Even little things like having classes instantiated as a Singleton is cool.

injector.mapSingleton( FlexcasterModel );

The FlexcasterModel is just a class but the framework itself handles the instantiation via injection. Saying

mapSingleton

makes sure you only have one and when it is injected, only the one instance already created is passed in. As the robotlegs site says, this helps prevent the boilerplate code. I look forward to trying out the framework. I enjoyed using PureMVC once I wrapped my head around it but this, perhaps because of the conciseness, took far less time to grasp.

AS3 Iteration with valueobjects in collections

Filed under: as3, tip — michaelangela @ 7:28 am

Using valueobjects might be overkill for some really simple things that only require a couple of values where you can just throw an object together quickly. Unless speed is an issue where they strongly typed values have a lower overhead than plain objects (as I understand it). Unless you’re in a big app and you just made a change to some code and suddenly all your other uses of that object break and you’re not aware of it and null exceptions start flying and…. I digress. Having them in a set collection is great, too, for similar same reasons, plus the added ability to create convenience functions specific to that particular data set. But this post says it all very well with code to boot.

AS3: Collection, ValueObject, & Iterator

A while ago I blogged about converting Collection and Iterator classes to AS3 since storing data in ValueObjects has become a regular practice in my coding. I really like how VOs are strongly typed and how you use a Collection to hold all the data together nicely. I am working on a project right now that allowed me to see even better uses for these things so I added a couple of simple (but helpful) methods to my Collection class (most notably the ability to add an item at a specified index as well as output the data currently existing in the collection easily) and created a base ValueObject class that allows you to easily output the data in that VO.

Important to also note is the package move. I’ve moved everything into a com.reintroducing.data package as I believe this fits better with what these classes are actually doing. There is also interfaces for ValueObject and Collection as well.

Just so you don’t have to flip back and forth between posts, I’ll post the classes and data here with a little explanation of each.

Plotting libraries

Filed under: python, tool — michaelangela @ 6:59 am

I wanted to look up some plotting libraries just to get an idea what’s out there. Plus I like Python for throwing numbers around although R has just become a new favorite for quickly working through some numbers… just need to learn statistics now. ๐Ÿ™‚

But I turned to stack overflow for an answer.

matplotlib is powerful.

CairoPlot is pretty.

Older Posts »

Create a free website or blog at WordPress.com.