Archive for July, 2008

Flash Ball Collision Prevent Stick and Rotate

Recently I have found that many people bump into the same problem when making multiple ball collision with random movement in Flash using ActionScript – when 2 balls collide, they will often stick to each other (especially when ed is < 1) and spin around orbiting each other, rotate.

The reason is because the hit detection doesn't always come in time and may also caused by the fact that a few balls are too close to each other. There is a fix to detect the overlap and correct the problem, update the position when overlap's found:

var absV:Number = Math.abs(vel0.x) + Math.abs(vel1.x);
var overlap:Number = (ball0._width / 2 + ball1._width / 2) – Math.abs(pos0.x – pos1.x);
pos0.x += vel0.x / absV * overlap;
pos1.x += vel1.x / absV * overlap;

By using the roll-back kind of collision solver code above, which acts like a sweep test, searches for the earliest collision in the real time frame and puts all balls back to that time, solves the collision and carry on with the simulation until the next collision happens.

In the above example, you can see that balls don't clutch together. and they let each other go when collide.

The source code can be downloaded at:
http://www.lab.highub.com/flash/physics/collision/ball_collision.fla

8 Comments

Install and Configure Tomcat on Ubuntu

To install and configure Tomcat on Ubuntu Feisty or Hardy can be easily done.

1. Download and install the Java packages need for Tomcat to work (run in terminal):

sudo apt-get install sun-java6-bin sun-java6-jdk sun-java6-jre

2. Download and install the Tomcat packages (run in terminal):

sudo apt-get install libapache2-mod-jk libservlet2.4-java libtomcat5.5-java tomcat5.5 tomcat5.5-admin tomcat5.5-webapps

3. Open the .bashrc file (run in terminal):

sudo gedit ~/.bashrc

4. Add the following line in the opened file:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

save and close the file

5. make the logs directory writable (run in terminal):

sudo chmod -R 777 /var/lib/tomcat5.5/logs

6. if your terminal is opened, close it and open up again

7. to start the tomcat, run the following command:

sh /usr/share/tomcat5.5/bin/startup.sh

8. now you can test to see if it’s working, point your browser at:

http://localhost:8180/

you should be able to see the tomcat splash page :)

9. to shutdown tomcat, use the following command:

sh /usr/share/tomcat5.5/bin/shutdown.sh

6 Comments

Ubuntu Upgrade From Gutsy to Hardy Problem Fix

If you have attempted to upgrade Ubuntu from Gutsy to Hardy using Ubuntu’s update manager, you may have encountered the problem that after downloading the packages while installed, everything went fine until the “Generating locales” portion, at which point the process froze. It displays this:

Generating locales...
en_AU.UTF-8...

And the following way happen:

It freezes and if you tried logging out, which froze before seeing the login screen. When you restarted and logged in again, it froze right afterwards, mouse and keyboard inputs are not locked out, but it just sits there and does nothing.

If that’s the case for you, don’t worry, here is the fix:

1. Reboot your computer, and before it loads Ubuntu desktop, press ESC to enter the GRUB menu
2. Select the previous version of the kernel xxx.14 rather than xxx.15 (sorry I can’t recall the exact version numbers) – don’t select the fail-safe mode.
3. Log-in as your admin user into recovery mode
4. Manually (re)start the upgrade via a terminal session: dpkg –configure -a

1 Comment

Ubuntu Hardy Broadcom Wireless Setup

After searching through online documentations and forums, below is the collected step by step guide to setup Broadcom wireless on Ubuntu Hardy.

Step 1 (run in terminal one by one)
echo ‘blacklist bcm43xx’ | sudo tee -a /etc/modprobe.d/blacklist
sudo apt-get install ndiswrapper-utils-1.9
mkdir ~/bcm43xx; cd ~/bcm43xx

Step 2 (run in terminal one by one)
sudo apt-get install cabextract
ftp://ftp.compaq.com/pub/softpaq/sp34001-34500/sp34152.exe
cabextract sp34152.exe

Step 3 (run in terminal one by one)
sudo ndiswrapper -i bcmwl5.inf
ndiswrapper -l
sudo depmod -a
sudo modprobe ndiswrapper
sudo cp /etc/network/interfaces /etc/network/interfaces.orig
echo -e ‘auto lo\niface lo inet loopback\n’ | sudo tee /etc/network/interfaces
sudo ndiswrapper -m
echo ‘ndiswrapper’ | sudo tee -a /etc/modules
echo ‘ENABLED=0′ | sudo tee -a /etc/default/wpasupplicant

Step 4 (run in terminal one by one)
sudo aptitude remove b43-fwcutter

Step 5 (run in terminal one by one)
sudo gedit /etc/init.d/wirelessfix.sh

Step 6
Paste the followings in the opened file(wirelessfix.sh)and make sure you save it before continuing Step 7

#!/bin/bash
modprobe -r b44
modprobe -r b43
modprobe -r b43legacy
modprobe -r ssb
modprobe -r ndiswrapper
modprobe ndiswrapper
modprobe b44

Step 7 (run in terminal)
cd /etc/init.d/ && sudo chmod 755 wirelessfix.sh

Step 8 (run in terminal)
sudo update-rc.d wirelessfix.sh defaults

Step 9 (run in terminal)
Restart your machine

Now your wireless should be working! :) hope it helps :)

,

3 Comments

JavaScript Convert CSV to Array

Using JavaScript, it’s not only possible but also very easy to convert csv – comma seprated values into array. Using JavaSctipt’s build-in string function ’split’, it can be easily done. Below is an example of retrieve comma separated value from a div block, convert it into an array and redisplay it by writing an array loop.

<html>
<head>
</head>
<body>
<div id="arrayDiv">Windows, Mac, Linux</div><br />
The array is:<br />
<script>
var myTxt = document.getElementById('arrayDiv').innerHTML;
var myArr = myTxt.split(',');
for (var i=0; i<myArr.length; i+=1) {
	document.writeln(myArr[i]+'<br />');
}
</script>
</body>
</html>

,

3 Comments

Install Configure Apache Localhost Perl on Linux Ubuntu

This article teaches those who want to run Perl scripts from browser on Ubuntu Linux with Apache HTTP Server.

1. First, you need to install apache2 by executing the following command from the terminal:

sudo apt-get install apache2

2. Now you can install mod_perl by executing the following command from the terminal:

apt-get install libapache2-mod-perl2

3. If you know how to set up a local server directory to let files like example.html running from browser like http://localhost/example.html or you previously installed LAMP, then you can read on, if not, please read this article first before continue.

4. Now you may need to edit Apache Configuration file in order to tell Apache Perl where your .pl script is located, so that the server can execute it as Perl script. So let’s say if you put your Perl script example.pl inside a folder located at your defined local server directory for instance /home/shi/Documents/Host/perl/example.pl, you need to open apache2.conf:

sudo gedit /etc/apache2/apache2.conf

add in the code:

Alias /perl/ /home/shi/Documents/Host/perl/

PerlModule ModPerl::Registry

<Location /perl/>
   SetHandler perl-script
   PerlHandler ModPerl::Registry
   #PerlHandler ModPerl::PerlRun
   Options +ExecCGI
   #PerlSendHeader On
</Location>

(change the line /home/shi/Documents/Host/perl/ to your server directory name)

And now restart your server by running the following command in terminal:

sudo /etc/init.d/apache2 restart

Now write a test.pl file with the test script below:

#!/usr/bin/perl
use CGI;
my $query= new CGI;
print $query->header;
print "hello people in my head\n";

set the test.pl file permission to 755 and put it in your local server directory and type the url path in the browser and you should see the message: ‘hello people in my head’.

Feel free to post a comment to let me know if you need any help!

,

12 Comments

PHP Regex Extract Directiory from Full Path

This code snippet uses PHP Regex – ereg(), which is based on the extended POSIX regular expression implementation. It extracts directory from pull path.

<html>
<head><title>Extracting directiories from full paths</title></head>
<body>
<form action="<?= $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="value" value="<? print $_POST ['value']; ?>"/><br/>
<input type="submit" value="Submit" /><br/><br/>
<?php
if ( $_SERVER['REQUEST_METHOD'] == "POST" ) {
    $mystr = $_POST['value'];
    if ( ereg( '^\/(.*)\/([^\/]+$|$)', $mystr, $matches ) ) {
        echo "The directory is: /$matches[1]";
    }
}
?>
</form>
</body>
</html>

Regular Expression Explanation:

^

the beginning of the line, followed by

\/

a slash, then

(

the beginning of the group that captures

.

any character

*

found zero, one, or many times

)

the end of the group, followed by

\/

a slash, then

(

the beginning of a group that contains

[

a character class

^

that doesn't include

\/

a slash

]

the end of the character class

+

found at least one time, followed by

$

the end of the line

|

or

$

the end of the line (without the [^\/]+ stuff).

No Comments