Mediatemple (gs) and svn+ssh

About 3 months ago, I moved my hosting to mediatemple,
and have been pretty satisfied thusfar with the level of support and
accessibility for only having a grid (shared) server account. That is,
until I tried to setup my own subversion repository. The grid accounts
only support svn+ssh, so it's a bit different from simple svn:// or
http:// access. Here's a multi-step process that should give you a
kickass setup. I mostly have it here for personal reference but I
figure it should help others out there too. I assume you're nerdy
enough to know your way around *nix.

a) Create your repo (EASY):
http://kb.mediatemple.net/article.php?id=143

b) Generate an ssh key for yourself if you don't have one already:
$: ssh-keygen


By default, an RSA key pair is generated and you'll want to place your private key here:
$HOME/.ssh/id_rsa

c) Upload your public key to your server and append ( or create it
) it to $HOME/.ssh/authorized_keys. There are plenty of fancy ways to
do this, but the easiest would be to just ftp it up and then
$: cat key.pub >> authorized_keys

d) And voila! You'll no longer have to log in each time you want to
commit files. Additionally, you can use this public key for any
environment you ssh in to.

Math Mod Util Class

In most programming languages (or Actionscript at least), they use the
computational definition of mod where it simply is the remainder of the
first operand divided by the second. This works fine for n % m where n,
m are elements of N. However, for -3 % 4, the computation looks something like this:

for n % m, n = -3, m = -4:
-3 / 4 = -.75
-.75 * 4 = -3
so -3 % 4 = -3

The mathematical definition of mod says for n mod m, where n is an element of Z, and m is an element of N,
the result of n mod m is in the range [ 0, m - 1 ]. So -3 mod 4 = 1.
This is a simple fix for Flash's % operator. The code below is in AS2,
but the AS3 version is essentially the same (maybe you would ensure n,
m are ints):

public static function mod( n : Number, m : Number ) : Number {
var tmp : Number = n % m;
return tmp < 0 ? tmp + m : tmp;
}

This is great for implementing a circular array, say for a nav where
you can press left + right keys and when you get to the first element
and press left, you go to the last nav element ( n - 1 if n is the
length ). So for your leftKeyHandler function you can just do something
like this instead of checking if index == -1, index = length - 1:

function leftKeyHandler() : Void {
selectNav( MathUtil.mod( --index, navElements.length ) );
}

Now on Chryp

I've migrated the blog to Chyrp. The feed is still the same url http://feeds.feedburner.com/timwah.

Make Eclipse Faster

With FDT installed, Eclipse now liked to prompt me with an "Out of Memory" error and quit itself. Sweet. I guess the 1.4 gigs of virtual memory allocated to it wasn't enough. Eclipse in general chugged, especially with FDT, despite whatever kick ass hardware I had. Ronnie let me know that Eclipse actually has a configuration file where Eclipse is only allocated about 40-256 megs of RAM. For boxes with >= 2 gigs, this is ludicrous! So, to remedy this, go to your Eclipse.app in finder, right click and select "Show Package Contents", then navigate to "Contents/MacOS" and edit "eclipse.ini." You'll want to change the lines "-Xms40m" and "-Xmx256m" to something like "-Xms1024m" and "-Xmx1024m" where the numbers are equal and a power of 2 (depending on how much memory you'd like to allocate). You can also add the lines "-XX:PermSize=256m" and "-XX:MaxPermSize=256m". Restart Eclipse and go to Eclipse->About Eclipse SDK->Configuration Details and you should see your new specs in there. I've only been using this new configuration for a few hours, but as far as I can tell, it is pwning n00bs. Let me know if you notice a performance boost or if you have anymore details on this eclipse.ini file.

Singletons in AS3

Yes, this is the obligatory "Singletons in AS3" post. As you very well may know, private constructors (the root of the singleton pattern) is not supported in AS3 / ECMAscript, along with abstract classes for that matter. I've done my fair share of scouring the web for a nice, succinct singleton example, and after some purging, this is what I came up with:


package com.timrobles.modules {

/**
* A Singleton example adapted from Steve Schelter
*
* @author tim.robles
*/

public class Singleton {

private static var _instance:Singleton;

// Constructor
//=====================================//

public function Singleton(fcn:Function = null) {

if (fcn != Singleton.getInstance)
throw new Error("Singleton can only be instantiated by Singleton.getInstance()");

if (Singleton._instance != null)
throw new Error("Only one instance should exist at a time");

}

// Public Methods
//=====================================//

public static function getInstance() :Singleton {

if (Singleton._instance == null)
Singleton._instance = new Singleton(arguments.callee);

return Singleton._instance;

}

}

}


Et voila, singletons are your homies again.

Algorithmic Botany == Motion Graphics?

I had an interesting thought the other day while under the influence of 'performance enhancing' drugs. As an interweb groupie, you may remember Josh Davis / praystation doing some shit with Lindenmayer systems a while back. It's basically a set of algorithms that mimic organic growth (which implies it looks natural, etc). So maybe, this same sort of "growth" can be applied to motion graphics. Oftentimes, we want smooth transitions, nice intros, etc, so what if these kind of build animations can be well-defined, through something like these algorithms? Maybe a keen sense of design and motion is not based on a critical eye, but can be defined through an algorithm based on real-world growth and motion. Long story short, expect some little experiments from me, and I'd love to get any feedback based on code I post.

Actionscript Woes & Tips

Well I figure I should have some useful shit on this blog since it's live now:
With any development, there's always that search for the perfect IDE. I've used Eclipse / FDT, Vi, Textmate and the Actionscript Editor in Flash. Yes, you've read correctly: Vi. I started using it partly because of my frustration with FDT expiring and costing $400 bones (almost as much as Flash itself). After my brief stint in the stone age, I'm now back to Textmate. There are bundles for AS 2 & 3, and snippets are great. One of my favorite features is that you can run Textmate from the command-line. So here's a tip: you can open your "flsrc/com" folder with one nice command (or any equally important folder for that matter). Open up Terminal (I like iTerm for tabs), and edit your .bash_login file:

$ cd
$ vi .bash_login

Add this line to the end of the file (or the top if not yet created):

alias nikewomen_la_fa07='cd /path/to/my/project/flsrc/com; mate .'

Exit out of Vi.

$ . .bash_login
$ nikewomen_la_fa07

And voila! Now you have Textmate open from the command line with all your source files open. Maybe I'm just lazy, or maybe I love bash, but I think this is useful when you're addicted to command line actions.

Labels: