So, I’ve had to do this on a few occasions now, and I have found the most efficient ( well in terms of lines of code ) to do this in Actionscript 3.

Before you can use this, you must have the x,y positions of the the 2 objects you want to calculate the distance between ( of course ).

The line of code I ended up using looks like this

var distance:Number = Point.distance(new Point(objectA.x, objectA.y),
                                     new Point(objectB.x, objectB.y));

There may be ways to extract the point object right out of an objects, if so , let me know. But this definately works.. now I can move on  to finishing my app : )

This is an issue I have been wrestling with for a few months now.

It’s come to a point now where I have to figure out. The issue is, when I create a custom event so I can transport data between my loosly coupled components, the eventListener never picks it up.

I found this pretty straightforward easy to understand article here, that explains that the event never travel across from component to component ( up and down the container stacks ) but in fact only travel 1w ay, up the stack to the parent.

Ok so that is great to know..  now the only way I can trap these events is always attach my listeners inside my custom components to the systemManager.  Do I always have to do that ? seems weird.

Anyways I discover more, I will comment on this post

N-way tile based worlds

November 6, 2009

This is an excellent tutorial and introduction to AS3 Flex Tile-based world design and fundamental concepts.

The Author Jeff Fulton summarizes :

In this tutorial we will discuss the theory and practice behind 360 degree n-way blit fine scrolling in AS3. What does that mean? N-way scrolling is a means by which you can scroll the screen in any direction based on the angle the main character of the game is facing. In this example we will talk about simulating an overhead 2-d car driving game, but this technique can be used for any game where the player can rotate to an angle before walking / moving.

Thanks Jeff, this article is great.

The title of this post sounds exciting, and it’s something I’ve been wanting to try for awhile. I’ll put a link in here to show you the sample code running.

I pretty downloaded and ran the code from Tremani, who have made an advanced artificial neural network in PHP. And it’s pretty easy to use so far.  The interface is simple.

Tell it how how big you want the network to be

Feed it your input data

Tell it your expected output for each testset, and hit the go button.

of course this is in PHP but and not literally a button.

but with very little work it could be setup with a button.

So these guys have done an awesome job of  making the setup and usage of an ANN this simple.. there is no reason why anyone can’t just start making little AI’s running around the net.

ok so I would like to try that. So now next steps.

  1. figure out a problem to solve
  2. figure out how to map that problem into inputs and outputs.
  3. then run it and figure out a way to test if it’s working

Sounds pretty good… so that is something I am going to try to play with.

Pretty excited about this

now I just need a genetic algorithm class that is this easy to use :)

Man I don’t know how many times I’ve had to do this. I get a list , I want to clean dupes before I import, or after.

and I’d like to do this with a query ( it’s gotta be possible right ? )

so I hunt I test, i break stuff… it sucks, I undo.. I redo.. I blah and I blah.. then it’s done..

waste of time.. so here it is.

First make sure I find what I am looking for :

SELECT *
FROM email_db, email_db AS vtable
WHERE vtable.id > email_db.id
AND vtable.email = email_db.email

very simple and elegant right ?

This is the one I actually ended up using.. to remove the dupes

  1. CREATE TABLE temp_table AS SELECT * FROM foo WHERE 1 GROUP BY bar;
  2. DROP TABLE foo;
  3. RENAME TABLE temp_table TO foo;

Adobe Air library

August 17, 2009

I recently came across a very good library called everythingflexairlib.

This library includes :

Components

  • NativeAlertWindow
  • AlertWindow
  • ContextWindow
  • SuperWindow

Managers

  • ConnectionManager
  • UpdateManager
  • IconManager

You can download the swc and source code hosted at Google code

CSS centering

August 13, 2009

It seems I like to do alot of centering in my CSS. I always end up searching for ways to do this, and there are a few tricks that work very well in both browsers.

For now here is a link to a W3 article explaining some simple and effective ways to do this

First time for everything

November 5, 2008

I am still getting familiar with the wordpress blogging system. I am testing my first post. My posts should get more interesting as time goes along.

Flash to Facebook bridge

November 19, 2008

I recently got working a Flash to Facebook bridge. I downloaded the as3 classes and example files from Zerofractal.com.

I spent a good couple of hours setting up my code and finding it not working. 

So back to square one, I loaded ZF’s example code and it worked. So I knew the issue remained with my setup

I first tested the calls with my barebones swf placed in an FB:iframe.

It worked!

So next  I started adding the flashvars I was trying to pass into the swf inside the frame.

It still worked !

next I added back the POST variables I was passing from the main page into the iframe.

BROKEN !!

It turns out I was not url-encoding my POST vars.

Lesson learned : urlencode() my vars !..   and of course the JS code and such did not alert me to any problems, it just didn’t work.

Development marathon

November 26, 2008

So we are on week 6 now of developing our first multi-user Flex based facebook game.

3 of us are working on it, it seems like a 2 steps forward, 1 step back cycle. Sometimes 1 step forward, 2 back.

Either way we are seeing progress. The main application file is at it’s 115th iteration, and I think we are approaching about 10,000 lines of code.

All the major functions work, but still appear buggy. We have successfully integrated into the Facebook platform and speed looks good in our tests.

Over the next fews I hope to iron out the last of the bugs, make some final design decisions, and move towards a beta testing phase with live people.

The Social web of trust

November 29, 2008

Today I found a “friend” connected to me in Facebook amongst the 220 people.

In my account, there is only about 5 people I’ve never met, and “met” through Facebook.

I was looking through this guys profile and he’s got about 300 friends, and about 15 in the last month of so.

Most of his friends look like commercials.

I was thinking, is this a robot account ?

It could be, couldn’t it ?

All my personal details are being splashed into this account’s feed, all the data could be getting dumped and sifted.

Am I being paranoid ?

Flex Facebook app in beta

December 22, 2008

We have finally released our first social gaming Flex application on Facebook.  The application is called Presidents & Assholes, it based on the popular card game Asshole. The application is real-time, and requires 4 live players to activate a game table. We have added a betting component, so users have a sense of reward.

Presidents and Assholes The application has a Spectator mode that will allow users to “preview” the game without forcing them to install. This same preview is available to the global internet without logging into Facebook. You can preview the game by clicking http://apps.facebook.com/play_president/.

The game has an easy to use chat window that will broadcast your message to the room. Users can enter and leave any number of game table rooms, and optionally sit down if they have installed the Facebook app.

multi-user flash games

January 6, 2009

I just come across a network that will power a flash game with:

  • real-time multi-user capability
  • data storage api
  • payment api
  • acheivements
  • high score

the service is called Nonoba

I recently came across this ad network that is designed for Flash and Flex game developers to monetize and promote their online games.

The network is called Mochiads and will allow you to embed a couple of lines of code , that will show ads in your game. Optionally you can upload an ad, and depending on how many impressions you send them, they will show your ad. Click to check them out, you can sign up for free.

I’ve had to do this task a good many times, soI figured I should note it here for easy access.

Problem: How do I format an external USB drive for access in the linux filesytem.

First plug in the drive and power it up.
To ensure the Linux OS recognizes the new device, you can run the command

dmesg

It should output something like:

 I/O error: dev 08:10, sector 0
 unable to read partition table
 I/O error: dev 08:10, sector 0
Device 08:20 not ready.
 I/O error: dev 08:20, sector 0
SCSI device sda: 625142447 512-byte hdwr sectors (320073 MB)
 /dev/scsi/host2/bus0/target0/lun0: p1

What you are looking for now is the device the OS has mapped it to.. in this case it’s sda ( it may also be sdb or sdc, depending on what other devices you have connected )

You will now be able to access this device through /dev/sda
Next I ran

cfdisk /dev/sda

This allows me to view the partition table on this device. It should show you the type of filesystem if any ( ntfs,fat or unformatted, etc )

In my case I want to make it a linux partition.
I created a [new partition], and set the type to 83 – Linux

I then chose [write] and [quit], this will create the new partition ( and WARNING!! :permanently erase everything on the device)
I could then format the device. I use ReiserFS, which I find great for devices that get jostled around and may get slight corruption, Reiser is awesome at recovering and fixing itself, even better than Ext3
I ran

mkreiserfs /dev/sda1

The 1 on sda1 now signifies the first partition on the device sda.
This will format the device and let you know the result.

At this point I did a quick check to see the health of the device with the command

fsck.reiserfs –check /dev/sda1

Which output:

Do you want to run this program?[N/Yes] (note need to type Yes if you do):Yes
###########
reiserfsck --check started at Tue Feb 10 09:57:44 2009
###########
Replaying journal..
Reiserfs journal '/dev/sda1' in blocks [18..8211]: 0 transactions replayed
Checking internal tree..finished
Comparing bitmaps..finished
Checking Semantic tree:
finished
No corruptions found
There are on the filesystem:
        Leaves 1
        Internal nodes 0
        Directories 1
        Other files 0
        Data block pointers 0 (0 of them are zero)
        Safe links 0
###########
reiserfsck finished at Tue Feb 10 09:58:06 2009
###########

the key info there is the line : No corruptions found
Which means there are no Bad blocks on the device.
So now I proceed to mount the device and then access it like any other folder on the system
mount -t auto /dev/sda1 /mnt/BACKUP-DRIVE/
in this case I had already made a folder called BACKUP-DRIVE in my /mnt directory.
now If I run:


df

I get

/dev/sda1            312559096     32840 312526256   1% /mnt/BACKUP-DRIVE

That tells me the drive is ready to go, I can cd /mnt//BACKUP-DRIVE and start writing files.
it my case I was to rsync my work files into the backup device I use this command


rsync -vbruz /work /mnt/BACKUP-DRIVE

This will check any only update the files that have changed since the last backup, and go recursively.. in this case, it will copy everything over and may take awhile.
When this is complete.. I run
umount /dev/sda1

and I can safely unplug the device until the next backup.
For the next backup I simply

  1. Plug device in and turn on
  2. mount -auto /dev/sda1 /mnt/BACKUP-DRIVE
  3. rsync -vbruz /work  /mnt/BACKUP-DRIVE ( where /work is the source of the files I want to backup )

ReiserFs comes with a whole bunch of great tools, in case the drive does become corrupted.. or it’s starts to age and gets bad blocks.

You can also automate alot of this ( I have yet to do this ) so that when you plugin the device it automatically calls your backup scripts or something.

Everytime we launch a new application in a social network, after a few weeks it’s important to know if we have upward growth.

The only thing I can think that demonstrates this is more installs per day. In our databases we capture full timestamps of the new installed user.

To turn this into something I can look at and understand, I have to run this query.

SELECT date_format( date_added, ‘%Y-%m-%d’ ) , count( * )
FROM fb_user
GROUP BY date_format( date_added, ‘%Y-%m-%d’ )
ORDER BY date_format( date_added, ‘%Y-%m-%d’ ) ASC

I am going to try to make a graph to view this in flex… first time Flex graphing :) I’ll post an update when it works..

Recently had to install wordpress and Drupal on our shared server.

I wasn’t seeing any errors, just a status 500 Server Error.

So after poking around and trying some things. I had to make a .htaccess file with the following settings :

php_flag display_startup_errors on
php_flag display_errors on
php_flag register_globals off
php_value memory_limit 16M
php_value zend.ze1_compatibility_mode Off

This allowed me to see the errors and also to avoid a brutal compatibility bug our provider has setup in their version of PHP5 install. After these were set… no problems :)

Flash Bootstrapping

December 12, 2009

This blog posting is an excellent introduction to the boostrapping process the flash player takes as it start an Adobe Flex compiled application.

  • Flash Player
    System Manager
    PreLoader

etc.. etc..

iamdeepa on flex

ruminations on technology

Linux performance tuning

November 15, 2009

I grabbed this from a page, I haven’t confirmed any of it yet.

TUNING HINTS

1) If you are tuning a heavy Apache compiled with a script interpreter (perl, php, python…) and lots of preloaded scripts (this is the case where lingerd comes the most useful), make sure you serve your images and other static content separately, from another server (running on the same machine or not).

This can be a lightweight Apache configured without any scripting, or even better, a copy of thttpd (http://www.acme.com/software/thttpd/) or boa (http://www.boa.org). Just put the image server on another IP address or port, and change your IMG tags to point to the right hostname (statically or dynamically).

2) If you’ve been able to offload image serving to a separate server, turn off KeepAlives on the dynamic page server. KeepAlives tie an Apache process to a specific client for a few seconds, which is long enough to increase the server’s load considerably, and short enough to be useless now that your images are coming from a separate server.

More importantly, KeepAlives and lingering_close are the main slowdown points for Apache processes; getting rid of one will speed up Apache a bit, whereas getting rid of both will have a much more dramatic effect.

3) Increase your kernel’s tcp/ip write buffers so that most, if not all generated pages can be written without blocking. If the page that Apache generates fits in this buffer, then Apache’s write() call returns instantaneously, then Apache hands the socket over to lingerd, logs the hit, and is immediately free for more work. If the page doesn’t fit, then write() blocks until the client has acknowledged part of the data, which can take several seconds.

To change this, use the SendBufferSize directive from httpd.conf. However, this directive cannot increase the buffer size past the kernel limit. Changing this kernel limit is OS-specific.

Under Linux you can set it by echo’ing a larger number (eg. 131072) into /proc/sys/net/core/wmem_max, before starting Apache. If you change wmem_default as well as wmem_max, then the SendBufferSize directive is not needed.

4) If you’re handling extremely high loads (500 connections per second and above on a single machine), make sure that the hard limit on open descriptors for the lingerd process is high enough (it should be at least twice the peak number of connections per second).

On Linux, the hard limit for a given process can be set (eg. to 2048) by running the bash command “ulimit -H -n 2048″ as root, and the system-wide total of available descriptors can be set by echo’ing a number into /proc/sys/fs/file-max.

Lingerd regularily sends some statistics to syslog, including the number of open file descriptors in use.

FIXME: instructions for FreeBSD, OpenBSD, Solaris?