Categories
Coding Unix

PHP not fully recognizing php.ini

OK, here’s an odd one I encountered on one of my older servers running Apache2 and PHP 5.2.5

I had php scripts failing and generating “500” errors on the browser because they were running too long, or sometimes because a large file was being uploaded. I spent time playing with php.ini variables, only to find out that PHP wasn’t processing some of them!

Using phpinfo(), I noticed that the vars were not being set via php.ini, which I had set properly when it was compiled, ala:

‘./configure –with-apxs2=/opt/apache2/bin/apxs –with-mysql=/opt/mysql –with-zlib –with-config-file-path=/etc/php.ini –with-curl=/usr/lib64 –with-pear=/usr/share/pear –libdir=lib64 –with-pdo-mysql –with-gettext –enable-bcmath –with-oci8=instantclient,/home/instantclient10_1’ ‘–enable-sigchild –with-pdo-oci=instantclient,/home/instantclient10_1,10.1.0.5’

I didn’t want to risk affecting the system by re-installing PHP, so instead I found the workaround was to create a .htaccess file that contained:

php_value upload_max_filesize 8M
php_value max_execution_time 600

and this did the trick! So hopefully that helps anyone who is running this version of php and encountered this problem.

Categories
Coding Poker

Inline Poker Cards

I created a WordPress plugin to display small poker cards in blog posts. Once you install the plugin you can use the nomenclature of:

[Ac]

to show the card of Ace of Clubs for example. You use a two-letter code that is Rank and Suit to show a card. The ranks/suits are as follows:

Ranks: 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A

Suits: c, d, h, s, x

where c=Clubs, d=Diamonds, h=Hearts, s=Spades, and x=Unknown

So go ahead and tell people how you had your [Ad][Ah] cracked by a donkey with [5c][8c] !

Download the plugin here

Categories
Coding Hardware

Tips Using Amazon EC2

When I started using Amazon’s EC2 service, I found it hard to gather all the info I needed. There was no easy guide that provided all the steps in an easy format. So, here are some tips I hope some might find helpful. I am interacting with EC2 from a Linux system, so my tips are from that viewpoint.

I assume you have already done the basics, like created your developer account (and know your secret key), and installed the command line tools.

Note that you will need Java installed on your system for the tools to function.

You can find the official EC2 docs here.

Now, on to my tips!

Find A Starter Image

You can browse the images at Amazon via the command :

% ec2-describe-images

You’ll see a bunch of images that are out there, in different UNIX flavors, and some with LAMP already installed. I found that whatever you pick, you’ll want to do your own package installs anyway, so just pick a baseline that you like, i.e. Ubuntu or Redhat or whichever you feel comfortable.

Note that you need the AMI string of your choice to continue. Not only will you see a number of Amazon created AMI’s, but other folks have created some public AMIs that you can choose from. Here are some AMIs for Ubuntu you can check out.

Choose A Server Size

Note that EC2 provides a small, large, and extra-large version your can use. I’ve found that the small instances are incompatible with the the large and XL, so be careful! You should start with the large if you plan on any expansion whatsoever.

So when you are ready to create an instance, you’ll need to specify the size (m1.large or m1.xlarge) on the command line otherwise it will default to small, i.e.:

% ec2-run-instances ami-20b65349 -k gsg-keypair -t m1.large

You’ll need to create a gsg-keypair file first of course. This is described nicely in the command line docs, you’ll use “ec2-create-keypair”.

Note that you can apply a firewall to your instance via the “-g <name>” option, where you define a group with the name of “<name>”. You can see what groups you have via:

% ec2-describe-group

You can create these groups using commands like:

% ec2-authorize mygroup -P tcp -p 22 -s 0.0.0.0/0

Access Your Instance

After you run an instance, you can check on the progress via:

% ec2-describe-instances

And you can provide the instance name also, e.g.

% ec2-describe-instances i-be9237aaa

Then you can SSH into it when it is ready by using the domain name it returns, e.g.

% ssh -i gsg-keypair root@ec2-67-200-1-123.z-1.compute-1.amazonaws.com

Customize Your Instance

You should now make sure your instance has all the packages you want, and configure them how you like. I install the latest Apache, MySQL, PHP, Perl, etc, and edit all the configuration files to my liking.fone

Make sure you stay in “/”, and do not use “/mnt” since this will go away if you reboot and won’t be saved when you save your instance.

If you need more space, you can use the extra storage service from Amazon although I have not done that at this point.

When you have everything the way you like it, you should save your instance. You will use ec2-bundle-vol to create the image, and ec2-upload-bundle to upload it to Amazon’s storage service.

You’ll need your secret key, access key, cert key, user id and a sample command set is as follows. You will run these from your Amazon instance (where real keys and numbers are replaced by X’s and fake numbers):

amazon% ec2-bundle-vol -d /mnt -k pk-XXXXXXX.pem -c cert-XXXXXXX.pem -u 432132132132 -s 1536
amazon% ec2-upload-bundle -b my_image_name -m /mnt/image.manifest.xml -a XXXXXXX -s XXXXXX

Once it is uploaded, you will need to now register it as an AMI image you can access later. You need to do this command from your local host:

% ec2-register my_image_name/image.manifest.xml

This will output your AMI string that you need to note so you can use it later to use your new instance on new Amazon servers.

Cleanup When Done

Don’t forget to make sure you terminate instances you don’t need to use anymore, or you will continue to be charged for them! Run “ec2-describe-instances” to see what you are running, and then you can use “ec2-terminate-instances” with the instance string as an argument to remove them.

Categories
Flex

Passing State with a Timer

Early on in my Flex work I found many cases where I needed the function after a timer event to have some more information. In other words, I really needed to pass state of variables to the next function. You could do this by using global variables, but a cleaner way is to create a subclass of the Timer class and pass along an object.

To do this, you can create this actionscript class in your main mxml directory (or get fancy and name it within subdirectories) as ” ObjTimer.as” and the contents are simply:

// ActionScript file
// ObjTimer is just a timer that can hold an object of variables to pass along
package {
    import flash.utils.Timer;
    public class ObjTimer extends Timer {
        public var obj:Object = new Object;
        public function ObjTimer(delay:Number, repeatCount:int = 0) {
             super(delay, repeatCount);
        }
    }
}

and then you can access it from within your mxml like so for example:

var newTimer: ObjTimer = new ObjTimer(900,1);
newTimer.obj["myvar1"] = "test";
newTimer.obj["firstname"] = "joe";
newTimer.obj["count"] = 10;
newTimer.addEventListener(TimerEvent.TIMER, handleFunction);
newTimer.start();

private function handleFunction(e:Event):void{
    var value:String = e.target.obj["myvar1"];
    var fn:String = e.target.obj["firstname"];
    var count:int = parseInt(e.target.obj["count"]);
}

This example is really quick-n-dirty, you can make it nicer by adding setters and getters in the new class, but for an easy implementation this should get you going.

Categories
FaceBook

FaceBook Applications

I’ve been developing some applications on FaceBook and like what they’ve built as their API framework. It’s a work in progress, but is growing and getting better. My FaceBook profile is here, and I’ve built the following applications so far:


Ujogo Poker
: This is a more condensed version of the official Ujogo.com website, and allows the FB avatars to be shown, adding friends, seeing user’s profiles inside the app, and various alerts to users based on performance, etc. The backend code is done in J2EE using the Java API.


Confessions:
This is a game to let users create confessions that are put in front of their group of friends for judgement. The backend is done in PHP using the FaceBook PHP API.


The Driving Test
: A test-taking game where you can add your own questions into the database. The backend is in PHP. It is a good thing I have an approval process function for when people submit their own questions, some of the stuff people submit is crazy! Perhaps I’ll post some of it someday.

All the applications are Flash (SWF) developed in Flex, communicating with standard backend services.

Categories
Flex

DataGrid with Multiple Pulldowns

Here is an example that illustrates how you need to add some additional logic when you add ItemRenderers into a DataGrid. The way I came across this problem is I noticed that when I had ItemRenderers doing things like checkboxes or pulldowns, the choices that they were set to on a row basis would CHANGE whenever I scrolled or sorted a column.

I struggled with finding a way, as I talk about in another posting, and found that using the dataChange event does the trick, and I always create the ItemRenderer as a separate component instead of trying to put all the logic in the main mxml. The component gets the initial setting of the value for that cell via “.data” and then you need to maintain and check it within the component. This can end up with the coder doing some hacking, and my example is only that — an example. I’m sure there are more elegant ways to achieve this. But that’s one of the things I think Flex shares with Perl — there are always multiple ways to get something done!

Take a look at the first flash example, where I DON’T use the dataChange — then see how it works nicely on the 2nd example.

First example (Try sorting columns and see it randomizes each time):

This movie requires Adobe Flash Player — Download at www.adobe.com

Second example (Works!):

This movie requires Adobe Flash Player — Download at www.adobe.com

Download my code sample here.

Categories
Flex

Flex2 -> Flex3 font size issue

I switched to Flex3 the other day and found that the font sizing for the default font has changed! So on most of my applications where I
painstakingly sized buttons so that they exactly fit the text label, I now see the text does NOT FIT anymore and has “…” at the end!

The Flex folks have some good solutions, see more on Flexcoders.

Categories
Flex

Doesn’t seem like normal behaviour for DataGrid!

I ran into a problem the other day trying to create a DataGrid that had voting buttons as an itemRenderer. When an action was taken in that cell, the buttons would change, i.e., gray out or light up to show a click occurred. The problem that would happen is that, when I scrolled the list up or down, that column would randomize!

I found posts that talked about solutions for very simple things like a checkbox in a column that did not have any elaborate actionscript behind it, but not to address a component that sat behind the itemRenderer. I figured it out though, and the answer is pretty simple.

I had to add a dataChange function call in the component’s main tag so it would force the cell to rethink it’s status when the grid would scroll.

The main mxml:

<mx:DataGrid id="userGrid" dataProvider="{userData}" sortableColumns="true"
    draggableColumns="false" width="100%" height="100%">
  <mx:columns>
    <mx:DataGridColumn dataField="Topic" width="100" />
    <mx:DataGridColumn id="votecol" dataField="status" headerText="Vote" sortable="true"
        itemRenderer="castVote" width="120" />
    </mx:columns>
</mx:DataGrid>

The castVote component:

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" dataChange="gridMoved()"
    width="100%" height="100%">
<mx:Script>
        <![CDATA[
        import mx.core.Application;
        import mx.events.ListEvent;

        private var myStatus:int = 0;

        private function gridMoved():void{
                if (data != null) {
                        myStatus=data.status;
                }
                doShow(myStatus);
        }

        private function doShow(n:int):void {
                // 0 means already voted, 1 is for, 2 is against
                if (n==0) {
                        buttons.visible=true;
                        v1.visible = v2.visible = false;
                        return;
                }else if (n==1) {
                        v1.visible=true; v2.visible=false;
                        myStatus = n;
                        buttons.visible=false;
                }else if (n==2) {
                        v2.visible=true; v1.visible=false;
                        myStatus = n;
                        buttons.visible=false;
                }
        }

        private function doClick(n:int):void {
                data.status = myStatus = n;
                doShow(n);
        }

        ]]>
</mx:Script>

        <mx:Label id="v1" text="You voted FOR this resolution" visible="false" />
        <mx:Label id="v2" text="You voted AGAINST this resolution!" visible="false" />
        <mx:HBox id="buttons">
                <mx:Button label="YES" click="doClick(1);" />
                <mx:Button label="NO" click="doClick(2);" />
        </mx:HBox>

</mx:Canvas>