2010
07.03
Category:
HPHP /
Tags: no tag /
well compiling hiphop wasnt the quickest thing, but then again Im using a pretty old computer, it took around 2h30m just to get it running.
So now I wrote my hello world and am ready to give it a try:
< ?php
echo "starting program";
sleep(2);
echo "...ending program";
?>
Pretty basic… so I followed the instructions here and 12m8s later the hellow world was running
wonder how long it’ll take to compile phpfox…theres only one way to find out!
oh heres how the resulting cpp looks like:
#include
#include
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
/* preface starts */
/* preface finishes */
Variant pm_php$test_php(bool incOnce /* = false */, LVariableTable* variables /* = NULL */) {
{
DECLARE_GLOBAL_VARIABLES(g);
bool &alreadyRun = g->run_pm_php$test_php;
if (alreadyRun) { if (incOnce) return true;}
else alreadyRun = true;
if (!variables) variables = g;
}
PSEUDOMAIN_INJECTION(run_init::test.php);
DECLARE_GLOBAL_VARIABLES(g);
LVariableTable *gVariables __attribute__((__unused__)) = get_variable_table();
echo(LITSTR(0, "test program started"));
LINE(4,x_sleep(toInt32(2LL)));
echo(LITSTR(1, "...ending test program"));
return true;
} /* function */
///////////////////////////////////////////////////////////////////////////////
}
2010
07.02
Back in february we were moving into a new apartment and on the day we were moving we found a computer on the communal garbage. It looked rather decent from the outside so I took it to our new home.
A couple of nights ago thanks to mr Natio and his generosity we got it working one more time. Its a pretty old computer but hey, its free! here are the specs
- Motherboard AMD Sapphire, socket 939
- Video integrated Radeon x200
- Processor Athlon 64, 2Ghz, single core.
- RAM 1GB DDR
During the last couple of nights Ive also gotten around having it working with a mobile internet stick from telenor which turned out to be quite easy on ubuntu 10.04.
Today I got the phpfox script installed along with memcached, have to say it still struggles to render a single page, even with memcache, with page generation times around the 7 seconds.
Again, it sure is not a computer meant for everyday use but will take it for testing experiments, for example HipHop + Phpfox is interesting for the learning experience, or Node.js + WebSockets, things that I wouldnt want to risk using my main computer for in case I have to wipe and start again
2010
04.09
I was working on customizing an applet for displaying chess games, using a normal drawImage was giving me a hard time, for some reason still unknown to me whatever was drawn second (from a drawRect and a drawImage), was blanking the first one, tried using threads, made sure image was loaded, tried with icons and other ways but no avail, the one that did work for me was extending a Panel like this:
/**
*
* @author Purefan
*/
public class PanelImage extends Panel
{
private Image hImage;
private MediaTracker tracker = null;
private Color bgColor;
public PanelImage(Image hImage, Color bgColor)
{
tracker = new MediaTracker(this);
tracker.addImage(hImage, 0);
this.hImage = hImage;
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
int iWidth = hImage.getWidth(this);
int iHeight = hImage.getHeight(this);
this.setSize(iWidth, iHeight);
this.bgColor = bgColor;
}
@Override
public void paint(Graphics g)
{
this.setBackground(this.bgColor);
System.out.println("in paint");
if (tracker != null)
{
try
{
tracker.waitForAll();
if (tracker.isErrorAny())
{
System.out.println("Loading image there was an error");
}
g.drawImage(this.hImage, 0, 0, this);
} catch (InterruptedException ex)
{
Logger.getLogger(PanelImage.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("Exception");
}
}
}
@Override
public void update(Graphics g)
{
paint(g);
}
}
The constructor receives an Image and a Color, since Panels (AWT) cant do setOpaque because they’re defined as RGB containers this trick simulates background transparency, tough luck if you need a gradient but for the most part this would work. Im using setCursos so I can addMouseListener when this class is instantiated and use this image as a link in an applet. Hope it helps someone
2010
04.05
Stupid MySql Workbench OSS created my tables with a column order not my liking, found this statement which worked just fine:
ALTER TABLE TableName MODIFY COLUMN ColumnNameToMove longtext AFTER ColumnNameToPutAfter
ALTER TABLE TableName MODIFY COLUMN ColumnNameToMove longtext BEFORE ColumnNameToPutBefore
ALTER TABLE TableName MODIFY COLUMN ColumnNameToMove longtext FIRST
2010
04.03
Flash has had its share of problems, for one end has been a good tool for easy gaming development, but its nice gifts have been widely misused and without Macromedia’s fault, it has derived into a clog for web browsing, one too many times has my browser crashed because either a lot of flash items in the page exhaust memory, or simply one really poorly coded ad decided it was time to mess with things it wasnt supposed to.
HTML5 could be delayed until 2022 according to what Ive read (having the first RC around 2012), but Google decided to show the capabilities of it already Google shows HTML5 with Quake2)
Im actually excited about this because I for one am not a fan of flash, at all… I used to do java but was discouraged by the lack of protection for our source code, apparently theres always an easy way to de-compile something and really useful frameworks like JMF were simply discontinued…
One thing I dont understand is why does it take so long to come up with a new version of a standard, granted it is A LOT of work, but there is a team dedicated to it, its not one person, and they have been working on it for years now, I dont think it should take another 12 years from now to expect a solid standard protocol, it takes a few months for web browser companies to implement the changes, say 18 months to have it stable, not 12 years…
2010
04.02
took me a while but finally figured out a function to get a php array out of an html table, working fine for my purposes:
/**
* Takes an html table and returns an array where the first row is taken as the keys
* in the array
* @example
<table>
<tbody>
<tr>
<td>header1</td>
<td>header2</td>
</tr>
<tr>
<td>value11</td>
<td>value12</td>
</tr>
<tr>
<td>value21</td>
<td>value22</td>
</tr>
</tbody>
</table>
returns array(
array('header1'=>'value11', 'header2'=>'value12'),
array('header1' => 'value21','header2'=>'value22'))
* @param string $sSource
* @return array
*/
public function tableToArray($sSource)
{
preg_match_all('/ (\s*?)(.*?)(\s*?)(.*?)(\s*?)< \/tr>/',$sSource,$aRows);
$aArray = array();
$aHeader = array();
foreach($aRows[0] as $iKey => $sRow)
{
// get the contents of every td
$xTds = '/ (.*?)< \/td>/';
preg_match_all($xTds, $sRow, $aTds);
if (empty($aHeader))
{
$aHeader = $aTds[0];
continue;
}
foreach($aTds[0] as $iSubKey => $sValue)
{
$sHeader = $aHeader[$iSubKey];
$aArray[$iKey][''.$sHeader.''] = $sValue;
}
}
return $aArray;
}
2010
03.24
Ive also been playing with some regex in C++ trying to get the most out of a chess parser Im writing, but boy has it been difficult to implement a simple regex match… first the Boost library, everybody referred me to Boost, compiling was easy in Ubuntu (apt-get) but including it in the project was another thing, for a good while I kept getting linker problems because something (according to the compiler) wasnt set up fine, took me a couple of posts at cplusplus.com but got that fixed, then other problems came… more cplusplus.com helped, when it finally compiled it wouldnt find any match! regex was tested by #regex at IRC and on other tools online, it just wouldnt work with the Boost.Regex snippet I had…
Got tired of it all and last night took a look at the TR1 Regex, surprisingly (even though its not supposed to be standard yet) it was available from the beginning with my default install, and setting a small program with it took me 1 hour (with the learning curve and all), Im having a little bit of a problem fetching the results now but the code compiles and finds a match so thats much farther than Boost was able to take me
2010
03.24
Yesterday we started testing the memcached and MySql replication support in phpfox. Gotta say memcache was extremely easy to set up, something like:
sudo apt-get install memcached
did the trick, then for phpfox it was like adding a line in the server.sett and editing another, bingo!
But MySql was playing hard ball with us, took a good 3 hours to get it set up to run on the same machine. That was just for the learning experience as for a real test think we will use two boxes and a third one to run Apache AB.
Oddly enough, the latest problem with MySql was that if we told the Slave to listen only for a specific database it would not UPDATE or DELETE, only INSERT. Removed the filter and everything worked, of course it meant we were also replicating unneeded databases but like I said, this was for the learning experience.