Find minimum or maximum value from Array

Browsing through the questions at the Adobe Flex forum again and came across one about having an issue with the Y-axis display on a dual-Y axis column/line chart. I’m not sure I gave the answer the poster was looking for, but my guess was that the minimum and maximum values for each LinearAxis was not set. You could set them to static values, but that wouldn’t be too useful. So, I did a quick search for some code to find the max value of an array and then modified it for AS3.

private function findMax(sourceArray:Array, sourceValue:String):Number {
	var maxNumber:Number = 0;
	for (var i:int = 0; i < sourceArray.length; i++) { 		var tmpNum:Number = new Number((sourceArray[i][sourceValue]).toString()); 		if(tmpNum > maxNumber) {
			maxNumber = sourceArray[i][sourceValue];
		}
	}

	return maxNumber;
}

private function findMin(sourceArray:Array, sourceValue:String, startMax:Number):Number {
	var minNumber:Number = startMax;
	for (var i:int = 0; i < sourceArray.length; i++) {
		var tmpNum:Number = new Number((sourceArray[i][sourceValue]).toString());
		if(tmpNum < minNumber) {
			minNumber = sourceArray[i][sourceValue];
		}
	}

	return minNumber;
}

— update —
There is apparently even an easier way of finding the minimum and maximum in an array of values using a Math function. However, you still have to split out the particular set of values from the overall array, which I don’t think there is a way to do.

Math.max(Array[]);
Math.min(Array[]));

It is pretty straight forward. Go through the array and find the value for a particular column, then check to see if it is smaller or larger than the previous stored value. The only difference between the two, is setting the starting high value for finding the minimum. So, when using these functions, you should find the maximum first and use that value as the startMax in order to find the minimum. This is who it was used in the LinearAxis code.

// VERTICAL AXIS
var verticalAxisLeft:LinearAxis = new LinearAxis();
verticalAxisLeft.autoAdjust = true;
verticalAxisLeft.maximum = Math.ceil(findMax(SMITH.source, "open"));
verticalAxisLeft.minimum = Math.ceil(findMin(SMITH.source, "open", verticalAxisLeft.maximum));

var verticalAxisRight:LinearAxis = new LinearAxis();
verticalAxisRight.autoAdjust = true;
verticalAxisRight.maximum = Math.ceil(findMax(DECKER.source, "close"));
verticalAxisRight.minimum =  Math.ceil(findMin(DECKER.source, "close", verticalAxisRight.maximum));

However, using the right Array, that has higher values than the left, will cause some issues. It is probably best to either use 0 or the smaller minimum value of the two arrays.

WP People

Tags: xfn, links, blogroll, people
Requires at least: 2.7.1
Tested up to: 2.8.4
Stable tag / Version: 3.4.0
Plugin Download
Support Forum : Hacks and Scripts / wp-people Thread

This hack plug-in will search a post and find names that match database records of people maked with the WP Category in the XFN Links. When it finds a match, it will replace the name with a link to the person. There is a administration screen for adding people and their bios to the database and viewing the current people marked for the filter. More than one person can be linked on a post. A individual name will only be linked once per post.

The original author of the hack stopped supporting it a while ago. I took his original idea and used another hack (acronymit) as a guide to make this work. The original worked with the my-hacks script used in WordPress 1.0.1, so this is beyond the functionality of the original.

If you were using the version 2 of Word Press People, then you will be able to see any current people in WP People. As of version 3.1.0, you can Copy records from the WP People table into the XFN Links databse.

Installation

  1. Upload `wp-people` to the `/wp-content/plugins/` directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress
  3. Go to the WP People administration page under the Tools section. The first time there will create the “WP People” Category
  4. Go to the Links administration page. Add new Links or add the WP Category to those people who you want to be included in WP People.
  5. Optionally Install the ‘WordPress Force Word Wrapping‘ plugin to prevent the description text from extednig past the popup window area.

Usage

The field on the Links form match up the following way:

  • Name is the Real Name (searched name) in WP People
  • Description is the Nick Name (displayed name) in WP People
  • Web Address is the Link in WP People
  • Advanced Notes is the Description/Bio in WP People
  • Advanced Image Link is the Photo in WP People

WP Mixed Tape

Tags: mixed tape, mp3
Requires at least: 2.7.1
Tested up to: 2.7.1
Stable tag / Version: 1.1.0
Plugin Download
Support Forum : Hacks and Scripts / WP Mixed Tape Thread

This a plugin that will take shortcode for track listings and make a “Mixed Tape” by turning the mp3 file links into music players and creating a play list of the tracks. The play list is a second shortcode that can be placed anywhere in the post. The play list can also show the tracks as a single album by changing the type. This will only show one link to the artist name added to the play list. The play list icon can be changed to show the mixed tape, cd, cd box, head phones or any image. The image should be small enough to fit inside the play list.

There are no admin options for the plugin.

Usage information can be found below.

The plugin uses 1PixelOut‘s standalone WordPress MP3 player, but should not conflict with other plugins using the player.

The plugin creates a search link to MusicBrainz music database for the artist of the track.

Installation

  1. Upload `wp-mixedtape` to the `/wp-content/plugins/` directory
  2. Activate the plugin through the ‘Plugins’ menu in WordPress

Usage

Adding tracks

[ track title="{track title}" artist="{track artist}" url="{track url}" alt="{alt text}" ]

  • track title is the title for the song. This does not change what is displayed in the mp3 player as the title information is taken from the mp3 file.
  • track artist is the artist for the song. This does not change what is displayed in the mp3 player as the title information is taken from the mp3 file.
  • track url is the full url for the song.
  • alt text is the alternate text shown if the player is not displayed. If left empty, it will show the track title.

Adding the mixed tape play list

[ mixedtape title="{mixed tape title}" style="{override styles}" class="{override class}" type="{play list type}" icon="{override icon}" cover="{image url}" artist="{single album artist name}" ]

  • mixed tape title is the title for the mixed tape to be shown at the top of the play list
  • override styles is any extra style attributes to add to the overall play list
  • override class is class name given to override play list for class style
    The style class should be part of the div classes. (ie. div.myMixTapeClass )
  • play list type is the type of play list either MIXEDTAPE or SINGLEALBUM. MIXEDTAPE is the default and will list each artist with the song.
  • override icon is the option to change the icon, choices are TAPE, CD, CDBOX, HEADPHONES.
  • image url is the url for a custom image to override the icon, ALBUMCOVER must be used as the icon value.
  • single album artist name is the name of the artist for the SINGLEALBUM type. It is ingored on the MIXEDTAPE or default type.

Things to do

  • Playing one player shuts off the other one. This was fine with version 1 of the payer, but version 2 doesn’t seem to work.
  • Code clean up – just need to make sure everything is in it’s proper place and such
  • Language translation – not many words in the plugin, so hopefully this won’t take too much time

Change Log

Version 1.1.1

  • Didn’t have the SVN directory properly setup. The audio files were missing.

Version 1.1.0

  • Added the ability to change play list `type` (MIXEDTAPE, SINGLEABLUM)
  • Single album type allows for `artist` value to be added to play list, ignored for mixed tape type
  • Added the ability to change the play list `icon` (TAPE, CD, CDCASE, HEADPHONES, ALBUMCOVER)
  • Added the ability to add change the icon to an defined url image with the `cover` option

Version 1.0.0

  • Inital release.

Updates and updates

WordPress has been making more updates lately than a backstage of a Las Vegas review.  Since the automatic update hasn’t worked in a few attempts, I have been forced to update manually by finding the files that are updated and uploading them to the site.  Hopefully I am finding all the files and doing all the updates.  I guess when they do their next big release, I’ll do a complete update of all of the files just to be on the safe side.

One issue with the updates is that if you create plugins, like I do, then you have to verify that your plugin works with the new update.  This usually isn’t a difficult task when you have a demo page on your site.  Just go to the page and see if it still works.  That was the step I took with my Mixed Tape plugin. However, as a plugin creator, you aren’t done there.  In order for someone to feel a little more comfortable about your plugin, you have to keep the “Tested up to:” version up-to-date.  Updating this information on your plugin requires an update to the “readme.txt” file and then a checkin to the source control database.  Apparently I’m getting better at it, because I am not reloading the files up multiple times.

What prompted me to make my plugins compliant with the new version of WP was a suggestion in my forum about a change to the WP People plugin.  The user wanted to customize the title or hover text on the link to the WP People bio.  I thought that was a great idea and now I found a little time to tackle the request.  While I was coding away, I changed the code around to work a little more like a plugin I made for 9/12 Candidates.  And, I also removed the table html that creates the layout for the form.  The changes aren’t major, but they weren’t minor either.  Hopefully it will allow me to do updates to that plugin much easier in the future.

But of course, my two little plugins are free, so I don’t see myself making a living off of WordPress plugins, even though a few developers get some money.

svn causing me heartburn

Arrrghh!!

So, the Plugin Directory finally pushed the 1.1.0 version of my Mixed Tape plugin to the repository to download. After I upgraded the plugin through the admin Dashboard, I noticed that the players were not showing in the test page. Well, apparently the svn check in blew up when I tried to add the 1.1.0 version and never put the audio files up to the site. I copied the audio directory from the trunk, which is apparently a no no. So, from now on I will have to remember to copy it from my working directory, which happens to be my local directory of my site.

I know some people have demo sites of their blogs. I really never thought I would have to worry about that, until now. I really don’t want to go through the hassle of setting up a duplicate blog just for testing, but it might come to that. My blog doesn’t get much traffic, but who knows, with the plugins and the Meetup Organizer Tool, it might just start.

Anyway, I’ve released 1.1.1 of the Mixed Tape and I see that the audio directory is under that version. I guess this will also be a good test to see how the tags/revisions work. Since the audio folder wasn’t in 1.1.0, then there will be a definite change between the two version. Of course, I will have to wait until it gets pushed through the repository, however long that will take.

An ah ha! moment

So, I apparently didn’t get enough sleep last night and my brain isn’t working on all cylinders. Anyway, it hasn’t stopped me from some side brain storming. Since I finally got my Mixed Tape plugin to show up on the plugin directory, I guess I was thinking about the type of people who might use it. I shared it with one of the guys over at Music Brainz, who plans to do a little write-up about the plugin. I guess that was in the back of my head, because it came to me that people who review music could use the plugin. Of course, that might have nothing to do with a music database, but it might. I bet there are plenty of people who write-up reviews about the latest album from their favorite artist, before they submit it to Music Brainz.

Since the plugin basically just takes the tracks and makes a playlist a reviewer could discuss each of the tracks on the album and link to the track as the review goes along. So, when they are done, someone could listen to the track and see if they have the same impression as the reviewer.

So, this means I probably need to make some small enhancements. I can probably add an option to the playlist to show either the mixed tape or a cd or maybe just an album. Or maybe I could show do a thumbnail of the album art, if the reviewer had that. Then I guess there would be an option as to whether or not the page contained a mixed tape or single album.

Welp, guess I better add that to the “to do” list.

Patiently waiting

Arrghhh!!
So, I got approval and the “go ahead” e-mail for my Mixed Tape plugin. I did the checkout using TortoiseSVN and it created the folders for the plugin. But, after adding files to the trunk, creating a tag folder and committing the files back up to svn, nothing. The files are up on svn, but the download page has yet to update. The page still shows my login as the author and doesn’t have any of the other information that my WP People plugin download page has. Very frustrating.

I know I’m not the only one who has gotten frustrated with creating plugins. Just check out The Agony and Ecstasy – Creating a WordPress Plugin. I even found a guy who posted a video series called How to Host a Plugin on WordPress in a four part series. The only thing I learned from the series is that it would be nice to have a new computer and maybe I would use a free open source IDE called Aptana.

I think I’ll let it set for a day and hopefully it will magically fix itself. Until then, I manually reloaded the plugin so that the demo page would still work.

My new Mixed Tape plugin

Mixed Tape

Mixed Tape

I am about to release a new plugin for WordPress. I am calling it WordPress Mixed Tape (WP Mixed Tape). If you have no idea what a mixed tape (mix tape) is, well, take a little trip back in time with me. Back in the day (let’s say the 1980′s), [W:cassette tapes] where the way taking your music with you. The [W:8-track tape] had gone the way of the [W:Dodo] and record [W:albums] were not portable. If those terms seem foreign to you, I included Wikipedia links to help you understand a little better. The great thing about tapes were that you could copy them to another tape. And, if you didn’t particularly like all the songs on a tape, you could copy tracks or part of tracks off of one tape and put it on another. You could even put your own voice recording or other recordings on to the tape.

Of course, this lead to people making their own full tapes for different purposes. One of the best or worst purposes for mixed tapes was for wooing someone. If you had a crush on someone or had been dating them for a period of time, you could show your love by copying a bunch of different songs that related to your emotional attachment to the other person onto a mixed tape. You could also be creative and add your own commentary in between tracks to show how that particular song meant so much to you about the current situation. For better or for worse, mixed tapes either helped or hurt the lovelorn and their situation. In today’s digital age, mixed tapes are now replaced by CDs (if you are legally allowed to make them now). But, even CDs are going away, since people can download music directly. So, what is a person supposed to do now to make a mixed tape? Well, you write a blog post as a mixed tape.

You are probably wondering how I came up with this idea. Well, Dean Logic is always all over the place, but there was a focus for this.

I was reading a coupe of posts on Gizmodo about the Windows PC commercial where “Lauren” buys a laptop for under $1000 and keeps the change. The Apple Fan Boys on Gizmodo didn’t appreciate Lauren’s selection. Not really caring about what her selection was, I was thinking I could write her an open letter stating that I didn’t care what she bought, because she’s cute. Then I started thinking that it would be great it I could make the post into a Mixed Tape. And that’s how this came about.

Basically, you add tracks to your post as you write. The idea would be that the tracks correspond to that particular part of the post. And then you add a tag to add the play list to the post with the name of your mixed tape, because very good mixed tape has a label. The code goes through and converts the track and play list tags and presto! You have a post that is also a mixed tape.

Now, to work on my open letter/mixed tape post for Lauren.

WordPress plugins and svn annoyances!

Small things in programming have been annoying me the last couple of days.

WordPress has started using svn (Subversion) as a method of version control for plugins. What this does, is allow the developer to upload version of the plugin to a database and then the plugin will automatically be updated on the download page. Also, it will alert anyone who has the plugin that there is an update to the plugin. From there, the user of the plugin can easily install/update it through the Admin panel. It’s actually very useful.

Well, I just recently updated my WP-People plugin to be compatible with WordPress 2.7.1 and also use the XFN database used in WordPress. As part of this update, I submitted the plugin to the svn database. After trying to find some easy instructions on how to use Subversion, I found some instructions on Designpraxis. The first time through was easy. But, the display on the download page was not exactly 100%. Only a short description was showing, even though I added the information for the other areas in the readme file. However, I didn’t have the readme file named correctly. So, I changed the name of the readme file and tried to up the versions to 3.01. Well, I did something wrong and ended up with a sub-folder of my plugin under the plugin directly. This caused errors, because it tried to load the plugin twice. After trying a few ways to update it to 3.02 without the sub-folder, I finally got it to work with version 3.03.

I think I have the steps for updating:

  1. Create a folder under the tags with the version number.
  2. Update your plugin in the Trunk directory. Make sure to update Version information in the main php file and the Stable Tag in the readme file.
  3. Copy the files into new folder under the tags directory and commit the changes.

After a bit, the updates will pass through on the download page. I guess after I make some updates, I can determine if these are the correct steps. The trunk folder lost it’s green check mark symbol, that’s probably not a good thing. Also, I am still not sure where I put the version release notes, I guess I can put them at the end of the main description. I add them to the log when I do the commit, but they don’t show on the download page.

I plan on including the relationship values from the XFN and a better layout on the WP People Admin page of those who are part of WP People. I might eventually include an easy way to edit the XFN data from the WP People Admin page.