Archive for September, 2008

actionscript SoundMixer fun

Ever since I grabbed ye olde flex builder for linux, I’ve been get jiggy with some ActionScript.

I did a few things with papervision, but nothing ready to show.

Here are some observations on…

AS3 weird stuff

I’m pretty used to Java these days, so the AS3 class layout was a little weird to me:

package my.package.name {
     import flash.stuff.and.or.junk;
     public class Funzone extends Zone {
          private var x:int;
          public function Funzone() {
          }
          public function fu( n:Number ) : int {
              return 1;
          }
          public function gu() : void {
          }
     }
}

Fer starters, the whole thing is inside a package xyz { } wrapper. If you put something there, the .as file (and it has to have the .as extension of mxmlc will ignore freak), it has to be inside some sorta java-ishy directory nesting and you have to figure out the args to mxmlc >.<

Or you can leave it blank… and keep it in pwd… and compile it directly with mxmlc… yeah… I know…

Look at the weird way the imports go inside the package stanza… ok, maybe not that weird…

The class definition (and if it extends another class) is nice and familiar.

Variable definitions are in the form of: (private|protected|public)? var name:type

Which is why the functions (cleverly marked as such in case you might confuse them for hamburgers) have that quirky colon return type look… Except for the constructor…

It’s a little different, but it looks pretty reasonable… not like ruby/perl/python…

Anyhooo… nuff said? Oh, you can compile it like so: mxmlc Funzone.as , as usual, the filename needs to match the classname and have the “.as” extension…

So, lez…

SoundMixer it up!

One thing people seem to find neat is sound visualization, so I thought it might be something fun to cut my teeth on.
I found a couple of pretty cool posts about using SoundMixer.computeSpectrum and thought… neat!

Those guys go into mechanics of it and there’s really not a whole lot to it. The only real improvement I made was to drive it all of the “Event.ENTER_FRAME” event handler.

inherit the drawSpectrum method

The original class I made to visualize it up was Souvouzou, the method which ultimately does the per fram drawing looks like this:

        public function drawSpectrum( graphics:Graphics, byteArray:ByteArray ) : void {
            graphics.clear();
            graphics.lineStyle( 0, 0x0000FF );
            graphics.beginFill( 0x0000FF );

            var w:int = 2;
            for ( var i:int = 0; i < 512 ; i += w ) {
                var n:Number = ( byteArray.readFloat() * 256 ) + 1;
                graphics.drawRect( i, 256, w, -n );
            }
        }

Which is pretty much copied from the example, but by breaking it out into a separate method, it was pretty easy to override it in Magnozou where I got a little more jiggy with it:

        public class Magnozou extends Souvouzou {
            // ....

        public override function drawSpectrum( graphics:Graphics, byteArray:ByteArray ) : void {
            this.fade();
            this.magnitudes( byteArray );
            graphics.clear();
            this.drawHits( graphics );
            this.drawHats( graphics );
            this.drawMags( graphics );
        }

It’s a little more in the flavor of the olde fadey, jumping hat thing of yesteryear with some nutty laser light show…

Notice the sly override, if you forget it, don’t worry! mxmlc will remind you… :-D

Error: Overriding a function that is not marked for override.

Thanks! I almost left off the handy “override” keyword! What a mess that would have been!!!

???

weird AS3 variable scoping

Another really weird thing about AS3 is that it appears that variable scoping is per function rather than per code block.

Which is weird! It means stuff like this:

        public function noworkie() : void {
            for ( var i:int = 0; i < 512 ; i++ ) {
            }
            for ( var i:int = 0; i < 512 ; i++ ) {
            }
        }

will get a saddy face like:

Warning: Duplicate variable definition.

and you can do weird stuff like this:

        public function noworkie() : void {
            for ( var i:int = 0; i < 512 ; i++ ) {
                var n:int = 12;
            }
            n++;
        }

which is REALLY weird!!! X-D

AS3 is weird

It is weird! But despite it’s few quirks, it’s a pretty usable language. The mxmlc compiler seems really slow…

It also seems really quirky.

Once I get the real directory structure / package / mxmlc straightened out I’ll post it.

BTW, don’t ferget, you can still write in Haxe, have it generate the AS3 and compile that with mxmlc… the big advantage of that is Haxe’s cool dynamic type inferencing, and it can also translate yer code to Javascript too…

I’m just saying… there are alway alternatives

Comments (1)

AIG screws the pooch!

Just got done reading about how AIG screwed the pooch so badly the gubment had to jam in $85b to keep the US economy from imploding!

This is even worse that the other crap bailouts cuz these wiz kid’s claim to fame is financial management. That’s their value add: making money by using money.

Can you imagine? It’s like having to bail your anger management coach out of jail on assault charges!

WTF? Too big to fail?

And check out this gem “the Fed decided to keep its key interest rate steady at 2 percent”

Here is my proposition: if the fed lets me refinance my home mortgage and car loan down to 2 percent, I will make a signed statement that I won’t ask for a multi-billion dollar bailout for the next six months… unless I really, really, really need it.

Who is OK’ing this corporate socialism?

What McCain said:

According to cbsnews,

“These actions stem from failed regulation, reckless management, and a casino
culture on Wall Street that has crippled one of the most important companies in
America. The focus of any such action should be to protect the millions of Americans
who hold insurance policies, retirement plans and other accounts with AIG,” McCain said.

“We must not bailout the management and speculators who created this mess. They
had months of warnings following the Bear Stearns debacle, and they failed to act.”

Obama sed

Bloomberg has Obama down for:

"The Fed must ensure that the plan protects the families that count on insurance,''
Obama said today in a statement, his first comment on the takeover. ``It must not
bail out the shareholders or management of AIG.''

"[Obama called the crisis] a stark reminder of the failures of crony capitalism and an
economic philosophy that sees any regulation at all as unwise and unnecessary.''

What does Bush say

This is not exactly a quote but…

Bush agreed with the loan for AIG at the White House on Tuesday

funny… I thought he was against gubment handouts… oh.. right.. only for poor people… mah bad.

Comments (1)

xm l.jar-czar.com">looking up jars by sha1sum on xm l.jar-czar.com

update: there is now an easier way to do this as a js widget!

% sha1sum jcr-1.0.jar
86b984b459383c8d4ba911785afef426be8fca7e
% sha1sum *.jar | sed 's,\([^ \t]*\) *.*,\1 \1,;s,^...,&/,;s,/...,&/,;s, ,/,;s,.*,http://xml.jar-czar.com/pub/&-jar-czar.xml,'
http://xml.jar-czar.com/pub/86b/984/b459383c8d4ba911785afef426be8fca7e/86b984b459383c8d4ba911785afef426be8fca7e-jar-czar.xml
% alias sha1_to_jar_car="sed 's,\([^ \t]*\) *.*,\1 \1,;s,^...,&/,;s,/...,&/,;s, ,/,;s,.*,http://xml.jar-czar.com/pub/&-jar-czar.xml,'"
% sha1sum *.jar | sha1_to_jar_car
http://xml.jar-czar.com/pub/86b/984/b459383c8d4ba911785afef426be8fca7e/86b984b459383c8d4ba911785afef426be8fca7e-jar-czar.xml

using search on jar-czar

Just plugin the sha1 into the url pattern: http://www.jar-czar.com/search?type=sum&text=SUM

ie, http://www.jar-czar.com/search?type=sum&text=000e21736b021c1f6033e6cd1484f504176069b4

It also works for md5sums too: http://www.jar-czar.com/search?type=sum&text=31f97f979d99308b6530b93338ca3b01

xm l.jar-czar.com" class="permalink">Permalink Leave a Comment

generating schemas from sample xml

Writing (Java) code to read xml is long dead thanks to jaxb which generates all the binding code from an XSD. The next piece to remove is the need to create and maintain XSD’s.

Sometimes known as “schema by example”, at least initials XSD’s can be created on the basis of exemplar xml files.

xml to dtd via dtdgen

DTDGenerator or “dtdgen” was written by Michael Kay and is very easy to use:

% wget http://prdownloads.sourceforge.net/saxon/dtdgen7-0.zip
% unzip dtdgen7-0.zip
% java -cp dtdgen.jar DTDGenerator
Usage: java DTDSAXGen input-file >output-file
% java -cp dtdgen.jar DTDGenerator ${JAR_CZAR_DATA}/pub/000/d31/bfbcfe8d6a2dce7f6eb0113d07969ac965/000d31bfbcfe8d6a2dce7f6eb0113d07969ac965-jar-czar.xml > jar_czar.dtdgen.dtd

xml to dtd via DtdJenny

I wrote DtdJenny a while back but it tries to do a similar job in javascript.

Here is it’s DTD for the same input file.

The only really difference other than spacing is that DTDGenerator says:

<!ATTLIST sum type NMTOKEN #REQUIRED >

and DtdJenny says

<!ATTLIST sum type CDATA #REQUIRED >

which is probably a point to DTDGenerator

Need to fix that…

dtd to xsd

The only tool I ever really found to translate from XML schema language to XML schema language is trang by James Clark.

It is also really easy to use:

% wget http://www.thaiopensource.com/download/trang-20030619.zip
% unzip trang-20030619.zip
% java -jar trang-20030619/trang.jar
fatal: at least two arguments are required
Trang version 20030619
usage: java com.thaiopensource.relaxng.translate.Driver [-I rng|rnc|dtd|xml] [-O rng|rnc|dtd|xsd] [-i input-param] [-o output-param] inputFileOrUri ... outputFile
% java -jar trang-20030619/trang.jar jar_czar.dtdgen.dtd  jar_czar.dtdgen.xsd

How easy is that?

correcting the xsd

There is a reason DTD’s are a technology of yesteryear… It is not nearly descriptive enough to be used seriously.

If we had xml like this:

<example>
    <a b="1.0" c="1" d="fat"/>
    <a b="2.0" c="2" d="cat"/>
    <a b="3.0" c="3" d="hat"/>
</example>

The attributes “b”, “c” and “d” would all be of type “NMTOKEN”!

Which is just dumb!

“Obviously,” “b” is a “float,” “c” is an “integer” and d is a “string”

I realized this lameness near the end of developing DtdJenny as I was working on the type inferencing!

Ack! I had to basicly drop this info on the floor cuz DTD doesn’t support it!

Someday I will try to salvage what I can to create XsdJenny…

For now… you have to fix it by hand! Blecho!

Next trick… The maven 2 jaxb plugin

Leave a Comment

submitting sitemaps to google and yahoo

So… after submitting my xml.jar-czar.com, over a week ago, I had a brief “yippee” as 1 or 2 pages popped in followed by “hmm… that’s really sparse”

Since the core of my application is xml data instead of html data, I attributed the blame to that.

I know, I know… Google and Yahoo both tell you it can take 3-4 week and even then it may not even happen.

So I was bummed… and almost ready to pony up $49 to yahoo with it’s guaranteed refresh… I still may, but let’s face it…

Google is really it for search.

what do you mean by a sitemap?

Before, I thought a sitemap was that lame part of a lot of web pages where they list “all” the pages of interest or all the starting points or some mess.

Well… it’s that too, but it’s also a goofy xml standard:

<urlset>
    <url>
        <loc>http://xml.jar-czar.com/pub/703/424/64a2e92d7df6fa28bf2cb375371628d472/70342464a2e92d7df6fa28bf2cb375371628d472-jar-czar.xml</loc>
        <lastmod>2008-09-08</lastmod>
        <changefreq>weekly</changefreq>
    </url>
</urlset>

That’s just a little taste, but you get the general idea (this is about 1mb of xml).

It turns out the max url’s in a single file is 50k. And I have 62k xml files…

Oh… and my s3 publish freaks out if a files is bigger than 1mb… :-P
Oh… but it can be gzipped…
Oh… well… maybe next time…

Ahem…

So I had to have a sitemapindex:

<sitemapindex>
    <sitemap>
        <loc>http://xml.jar-czar.com/.sitemap.site00000000.xml</loc>
        <lastmod>2008-09-08</lastmod>
    </sitemap>
<sitemapindex>

Each sitemapindex can point to a max of 1k sitemap files which means it can indirectly address up to 50 million files.

And you can have more than 1 if you do have more than 50 million files…

Yeah… That would be a lot…

one last word on sitemaps

If you publish your sitemap as say http://xml.jar-czar.com/site/, it can only refer to files under http://xml.jar-czar.com/site/ (including nested down under any subdirectories) and never say files in http://xml.jar-czar.com/ or http://xml.jar-czar.com/images/

Registering the sitemap with Google

google register sitemap index

Google’s interface (as usual) is spartan and practical. You can add sitemap indexes and then you can view details as far as how many urls are reference, when it was downloaded, how many urls are processed and click to see stats for individual sitemaps.

If someone is really interested, I’ll take some pictures of it…

Registering the sitemap with Yahoo

google register sitemap index

As usual, Yahoo’s SiteExplorer looks really sharp. Kinda makes Google look like it was written in python or something! j/k

But seriously…

So what?

Right? Now I’m sure Google and Yahoo know about my files. That’s still no guarantee they will index them.

At least with Yahoo, I can still do something to make it happen, but then again… it’s Yahoo’s search…

Maybe that’s great if you have a site that sells commemorative plates of Chuck Norris fighting Donkey Kong, but the whole point of jar-czar is to provide a technical resource to Java developers.

Every developer I know uses google….

Now what?

Leave a Comment

Older Posts »