Compiling php-python on Fedora Linux

Posted by Daniel | Posted in Development, Operating Systems, PHP, Software | Posted on November 12, 2012

0

<rambling>

So, I haven’t posted in a while, and I felt it was about time to get some fresh content up here so what follows is the result of some research and testing I did as a result of re-visiting a question on SuperUser that I responded to over a year ago that was never fully resolved.

I enjoy research and testing new things that I don’t fully understand yet, to learn something new and hopefully gain a more complete knowledge of concepts and technology that I haven’t had either the time to research, or haven’t wanted to learn more about previously. I have a personal goal to constantly learning something new to keep from becoming complacent or self-assured of what I’ve learned.

</rambling>

So, you want to run python code in PHP, eh? Why you might ask? Well, I’m not quite sure. I haven’t run in to a use case for it myself, but I can see where you might need to do some heavy-duty maths or maybe there is a python library that you require for some custom algorithm or something.

Good news! There is a PECL library you can use for this task: http://pecl.php.net/package/python
Bad news! It hasn’t been updated in over 4 years at the time of this writing and was in alpha at the time of the last release.
Good news! The maintainer appears to still be working on the package, but over a GitHub: https://github.com/jparise/php-python
Bad news! It still doesn’t compile on PHP 5.4 (in Fedora at least)
Good news! I got it to work with some minor tweaks.

Here is the process that works for me with the current PHP version (5.4.8 at the time of this writing) linking to python 2.7:

Install build tools and minimum deps:

1
2
yum groupinstall "Development Tools"
yum install php-common php-pear php-devel python python-devel wget

Get a copy of the latest version of php-python:

1
git clone https://github.com/jparise/php-python.git php-python

Apply the patch to fix C syntax errors. Note that this patch is likely to be broken and/or not necessary some time in the future when php-python is updated. But the changes are simple so you can apply them manually if they are still needed in future versions.

1
2
wget http://www.dandev.com/other/post_content/php-python_20121112.diff
patch -p0 < php-python_20121112.diff

Build the module

1
2
3
4
5
cd php-python
phpize
./configure
make
make install

After this is complete you need to edit your php.ini to enable the new module. Add a line like this:

1
extension=python.so

Once php.ini is updated you should be able to see the “python” module listed in the “php -m” modules list, and you should be able to use the python functions. . Restart Apache if you are using mod_php to load the updated php.ini file. The examples folder on GitHub has some code you can use to see the python features in action: https://github.com/jparise/php-python/tree/master/examples

Good luck!

Displaying the version number in Adobe AIR

Posted by Daniel | Posted in AIR, Development, Flex, Software | Posted on October 12, 2011

0

In the Adobe AIR application descriptor file there are many options you can set. One of which is the tag(or in Flex SDK v4.1 and below), which lets you differentiate your release as well as utilize the Adobe AIR updater library.

It can be useful to display your version number inside of your app to inform the user as well as help with bug reports among other reasons. In order to prevent you from having to update the version number in multiple places you can use AS3 to grab it from the application descriptor and update your text for your app on the fly, as it loads. Here is an example of how to do that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!--?xml version="1.0" encoding="utf-8"?-->
 
		<![CDATA[
			import mx.events.FlexEvent;
 
			protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
			{
				var appXML:XML = flash.desktop.NativeApplication.nativeApplication.applicationDescriptor;
				var ns:Namespace = appXML.namespace();
				versionLabel.text = 'v' + appXML.ns::versionNumber;
			}
		]]>
 
		<!-- Place non-visual elements (e.g., services, value objects) here -->

Flex Builder Project

Add a click event to a BitmapImage in Adobe Flex/AIR

Posted by Daniel | Posted in Development, Flex, Software | Posted on October 5, 2011

0

You may have noticed MouseEvent.Click is not an event available to be set on the BitmapImage Spark primitive(in the current Flex SDK). But, there is a simple workaround for this. All you have to do is place it inside of a Graphic primitive wrapper. In MXML it would look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx">
 
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
 
			protected function graphic1_clickHandler(event:MouseEvent):void
			{
				Alert.show('Nope!', 'Click Event');
			}
		]]>
	</fx:Script>
 
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
 
	<s:HGroup id="container">
		<s:Graphic click="graphic1_clickHandler(event)">
			<s:BitmapImage source="path/to/image.jpg" 
						   smooth="true" 
						   smoothingQuality="high" />
		</s:Graphic>
	</s:HGroup>
 
</s:Application>

Flex Builder Project

In AS3 it looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   creationComplete="application1_creationCompleteHandler(event)">
 
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.events.FlexEvent;
 
			import spark.primitives.BitmapImage;
			import spark.primitives.Graphic;
 
			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				var myBI:BitmapImage = new BitmapImage();
				myBI.source = 'path/to/image.jpg';
				myBI.smooth = true;
				myBI.smoothingQuality = 'high';
 
				var myG:Graphic = new Graphic();
				myG.addElement(myBI);
				myG.addEventListener(MouseEvent.CLICK, graphic1_clickHandler);
 
				container.addElement(myG);
			}
 
 
			protected function graphic1_clickHandler(event:MouseEvent):void
			{
				Alert.show('Nope!', 'Click Event');
			}
		]]>
	</fx:Script>
 
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
 
	<s:HGroup id="container">
	</s:HGroup>
 
</s:Application>

Flex Builder Project

SSHD Error: buffer_get_ret: trying to get more bytes 4 than in buffer 0

Posted by Daniel | Posted in Operating Systems, Software | Posted on October 2, 2011

0

If you have run in to an error similar to this one while setting up SSH key-based authentication in your /var/log/secure log file:

1
2
Oct  2 21:12:05 phptest sshd[31998]: error: buffer_get_ret: trying to get more bytes 4 than in buffer 0
Oct  2 21:12:05 phptest sshd[31998]: fatal: buffer_get_int: buffer error

Check to make sure your public key in ~/.ssh/authorized_keys or ~/.ssh/authorized_keys2 is on one line. The prefix “ssh-rsa” followed by a space and then your key should all be on one line. You may also have a comment after that describing the key on another line, but the whole prefix and key have to be on the same line or you will get an error similar to the above in your /var/log/secure log file. I see people running in to this problem frequently when copying a public key out of PuttyGen, which only has “ssh-rsa” on the first line of the output key.

VerifyError: Error #1014: Class IIMEClient could not be found.

Posted by Daniel | Posted in Development, Flex, Software | Posted on July 11, 2010

14

If you have run across this error recently: VerifyError: Error #1014: Class IIMEClient could not be found.

You may be wondering what it means, and more importantly how to fix it. What appears to be the sole cause of this error is your versions not matching up between your Flex/AIR SDK and the AIR application descriptor file. This can happen after you update/reinstall Flash Builder, or the SDK folder manually.

The fix is pretty easy: Just open your AIR descriptor file(generally the only XML file in the project src folder) and change the xmlns to the current version of the SDK you are using(1.5.3 => 2.0 for instance). See screenshot below for an example(warning: it’s big):

Windows Installer has stopped working

Posted by Daniel | Posted in Operating Systems, Software | Posted on July 5, 2010

0

If you have been unfortunate enough to run into this issue, here are a few things you can try to resolve it. These are for Windows 7 only – there are already solutions available for older versions of Windows if you search. You need a physical copy of the DVD to do a manual restore of the files.

  1. (Re)start the Windows Installer service
    1. Right-click on Computer
    2. Click Manage
    3. Expand Services and Applications
    4. Select Services
    5. Scroll down to “Windows Installer”
    6. Right-click or double-click on it and make sure it is started and NOT disabled
  2. Run “sfc /scannow” from a command prompt as Administrator
    1. Should see something like: windows resource protection found some corrupt files but was unable to fix them
      1. Check the log to see if the problem is a corrupt file such as “msi.dll”
        1. Do this by searching for “cannot repair”
      2. If that is the case you can restore this file from the Windows DVD by:
        1. Insert the Windows DVD in the drive, cancel the autorun if it pops up
        2. Open 7-zip and browse to “install.wim” in the DVD:\Sources folder (open it)
        3. Inside you will find numbered folders corresponding to the windows version, open yours:

          1=Home Basic

          2=Home Premium

          3=Professional

          4=Ultimate

        4. Browse to the folder for the version you have installed, and you can copy/extract the file(s) you need. In my case I needed “msi.dll” in the #\Windows\System32 folder
        5. Note that if you are restoring a sensitive file such as this that you have to take ownership of the original file to rename/remove it before you can restore this file from the DVD, and ideally set the restored file back to the original owner and permission.
        6. Also note that the “msi.dll” file is owned by “TrustedInstaller”, so if you are getting a security error you need to take ownership of the file to replace it and then restore TrustedInstaller as the owner. If you can’t find it when you “check” the name use “NT SERVICE\TrustedInstaller”
  3. Restore an earlier restore point(not verified to work but try it..)
  4. Run the repair option from the installer DVD
  5. Reinstall Windows

Hope this helps someone. :)

Flex HDividedBox/VDividedBox divider double-click event oddity

Posted by Daniel | Posted in Development, Flex, Software | Posted on December 1, 2009

7

I ran across an interesting case today while looking into an issue for someone else related to capturing the double-click event on the divider for a HDividedBox. It’s a little tricky to get the event to be captured by Flex. A quick search of the interwebs turned up nothing but people with the same issue. There is even an open bug in the Adobe Flex bug tracker(you have to login) that seems to be the exact issue, but there is no resolution named. Through some quick experimentation I figured out you can get it to work like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute"
    width="600" height="588"
    applicationComplete="start()">
    <mx:HDividedBox id="divBox" 
    	height="100%" width="99%"
    	liveDragging="true"
    	doubleClickEnabled="true">
          <mx:Canvas width="50%">
          		<mx:Text text="Some example text" />
          </mx:Canvas>
          <mx:Canvas width="50%">
          		<mx:Text text="Some example text" />
	      </mx:Canvas>
     </mx:HDividedBox>
     <mx:Script>
          <![CDATA[
               private function start():void {
                    divBox.getDividerAt(0).addEventListener(MouseEvent.DOUBLE_CLICK, handleDoubleClick);
               }
 
               private function handleDoubleClick(e:MouseEvent):void {
                    Alert.show('Event captured!');
               }
          ]]>
     </mx:Script>
</mx:Application>

The specific resolution was to enable liveDragging and add the event to the divider itself(most people try to set it on the doubleClick property of the DividerBox).

Hopefully this post will be helpful to some people out there with the same issue!

GAIQ Certified!

Posted by Daniel | Posted in Development, Software | Posted on November 15, 2009

0

So, I took the GAIQ certification test the other day and passed. It was a little harder than I expected, but not too crazy. I definitely recommend you watch all of the Google Conversion University videos about GA and be ready to look things up if you aren’t sure. A lot of the questions were common sense, but there were a few tricky ones that required some advanced knowledge.

Flex Tip: Accessing your AS functions/properties from imported classes

Posted by Daniel | Posted in Development, Flex | Posted on May 25, 2009

1

Every once in a while you might run across a case where you need to access a property or method from the parent application, and you don’t have the ability to pass the value you need to the class. Or, for example, you’re debugging and you don’t want to write a bunch of code that you’ll have to remove later just to test the value of a variable.

So, with that said the process is fairly simple. The following is a hypothetical example of a class you have imported into your application:

package com.example.scope
{
    private var myVar:String = "This is NOT the value we're trying to get";
 
    public class scopeExample
    {
        public function scopeExample()
        {
            // Flex 4
            import mx.core.FlexGlobals; // make "FlexGlobals" available in the current scope
            trace(FlexGlobals.topLevelApplication.myVar); // outputs the value of myVar in the main application
 
            // Flex 3
            import mx.core.Application; // make "Application" available in the current scope
            trace(Application.application.myVar); // outputs the value of myVar in the main application
        }
    }
}

You could also use:

trace(parentDocument.myVar); // if the component is a child of the main application

I ran across a post on Holly Schinsky’s blog the other day that had good descriptions of the various scope keywords, and a few tips. All of which is good knowledge to possess, so check it out.

PunkBuster Invalid O/S Error on Vista

Posted by Daniel | Posted in Games, Life, Software | Posted on March 20, 2009

4

Just a quick note, for anyone having trouble playing games that have Punkbuster integrated with it. If you’re getting an “Invalid O/S Error” when you try to join a server, this is related to the game not having enough permissions to  open/alter certain files. There have been several fixes suggested, and some work for some people… some work for others. The one that seems to solve most people’s problem is running the game as an administrator. Simply being logged in as an administrator isn’t enough because your programs are still executed with limited privileges. You just have to confirm it when they’re needed(if you have UAC enabled).

To run as administrator you have a couple of options.. if you’re running a home version of Vista, you might not have some of them:

  1. Right-click on the Shortcut or game executable and click Run as Administrator
  2. Right-click on the game executable and Click Properties->Compatibility->Check the “Run as Administrator” box, Apply
  3. Right-click on the Shortcut, Click the “Shortcut” tab->Advanced, Check the “Run as Administrator” box, Apply

Now, with that said, none of these would work properly for me. The only solution I could find that would work is downloading this update from PunkBuster, adding my game, and hitting Update. Once updated the game ran fine without giving it extra privileges.

Good luck!