Tuesday, May 28, 2013
Saturday, May 18, 2013
Using Hiphop for PHP static analysis
1. Install hiphop on Ubuntu ( I just got an AWS EC2 instance) following these steps :
https://github.com/facebook/hiphop-php/wiki/Prebuilt-Packages-on-Ubuntu-12.04
2. Then run the hiphop command for static code analysis :
hhvm --hphp --target hhbc --input-list /tmp/files.list --output-file hhvm.hhbc.sq3
https://github.com/facebook/hiphop-php/wiki/Prebuilt-Packages-on-Ubuntu-12.04
2. Then run the hiphop command for static code analysis :
hhvm --hphp --target hhbc --input-list /tmp/files.list --output-file hhvm.hhbc.sq3
Building hiphop php on Centos 6.3(Didn't succeed)
I tried to follow the instructions here : http://stackoverflow.com/a/8132054/49560.
There were few things missing, which I am mentioning here.
1. Path of the third party patches has changed in the hiphop repo. So, find the correct path and then proceed. For me it was :
cp /home/ec2-user/hiphop/hiphop-php/hphp/third_party/libevent-1.4.14.fb-changes.diff .
cp /home/ec2-user/hiphop/hiphop-php/hphp/third_party/libcurl.fb-changes.diff .
There were few things missing, which I am mentioning here.
1. Path of the third party patches has changed in the hiphop repo. So, find the correct path and then proceed. For me it was :
cp /home/ec2-user/hiphop/hiphop-php/hphp/third_party/libevent-1.4.14.fb-changes.diff .
cp /home/ec2-user/hiphop/hiphop-php/hphp/third_party/libcurl.fb-changes.diff .
2. The version/location of tbb has changed.
Get it from : wget http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20130425oss_src.tgz
3. Before doing cmake .
A. yum install subversion
B. install google glog
C. install libunwind-1.1, https://github.com/facebook/hiphop-php/issues/563
D. yum install elfutils-libelf-devel
E. get libdwarf
git clone git://libdwarf.git.sourceforge.net/gitroot/libdwarf/libdwarf
cd libdwarf/libdwarf
./configure
make
sudo cp libdwarf.a /usr/lib64/
sudo cp libdwarf.h /usr/include/
sudo cp dwarf.h /usr/include/
cd ../..
4. Now you do cmake . and then make. You may get an error saying that lock_guard is not a member of boost. So you need to replace boost::lock_guard with std::lock_guard in ThreadLocalDetail.h.
5. Now do make again. I got some errors which were beyond me - so giving up.
Saturday, May 4, 2013
Set up hadoop cluster on EC2
I followed : http://blog.cloudera.com/blog/2012/10/set-up-a-hadoophbase-cluster-on-ec2-in-about-an-hour/
There are few things missing here and there but it's a great help otherwise.
Here are the missing parts :
1. Get the EC2 command line tools : wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip.
Your EC2_HOME will point to the place where the above file will be unzipped.
2. Here are all the lines you will put in your ~/.bash_profile :
export AWS_ACCESS_KEY_ID=BKIAISLDPUEUJN2ILNTP
export AWS_SECRET_ACCESS_KEY=n+v7BZhFy5CwUqpC27C/q8/vJiz5+vy0YH4Z8yyV
export EC2_PRIVATE_KEY=/mnt/aws/aws-pk.pem
export EC2_CERT=/mnt/aws/aws-cert.pem
export EC2_HOME=/mnt/aws/ec2-api-tools-1.6.7.3/
export JAVA_HOME=/usr
3. After you launch your ubuntu instance - you need to go to AWS console and the corresponding security group - add rule for SSH - so that you can login to the box.
4. On the ubuntu box : put these 2 lines in .bashrc :
export AWS_ACCESS_KEY_ID=BKIAISLDPUEUJN2ILNTP
export AWS_SECRET_ACCESS_KEY=n+v7BZhFy5CwUqpC27C/q8/vJiz5+vy0YH4Z8yyV
5. Here is your hadoop.properties file for whirr :
whirr.cluster-name=whirrly
whirr.instance-templates=6 noop
whirr.provider=aws-ec2
whirr.identity=${env:AWS_ACCESS_KEY_ID}
whirr.credential=${env:AWS_SECRET_ACCESS_KEY}
whirr.cluster-user=huser
whirr.private-key-file=${sys:user.home}/.ssh/id_rsa
whirr.public-key-file=${sys:user.home}/.ssh/id_rsa.pub
whirr.env.repo=cdh4
whirr.hardware-id=m1.large
whirr.image-id=us-east-1/ami-1db20274
whirr.location-id=us-east-1
Friday, April 26, 2013
jquery autocomplete source function
For e.g., if the user types john smith in the inputBox, and you want to return all the elements which contain either john or smith or both, then use the following code :
$( "#inputBox" ).autocomplete({
source: function (request,response) {
var terms = request.term.trim().replace(/\s+/g,' ').split(" "); //Now terms is an array ['john','smith']
var respData = {};
terms.forEach( function(term) {
lookUpArray.forEach( function (lookUpElem) {
var regexp = new RegExp(term, "gi");
if(lookUpElem.match(regexp)) {
respData[lookUpElem] = 1;
}
});
});
var results = [];
for(var k in respData) results.push(k);
response(results);
}
});
lookUpArray is a global variable here - if it contains ['john dao' ,'smith dao', 'john smith', 'singh bone'] - then the first 3 elements will be returned for the query john smith.
Friday, April 19, 2013
How can you not love PHP?
1. Once I wanted to set up something like Wikipedia on my own. I got hold of MediaWiki - written in PHP/MySql. Dumped it on my shared host. In less than an hour I was up and running.
2. Once I wanted to run an e commerce site. I sifted through half a dozen e commerce engines - all written in PHP/MySql. Dumped in on my shared host. In a couple of days I was up and running.
3. Once the mighty Google Reader closed down - for once and for all. I dumped Tiny Tiny RSS Reader on my shared host. In a couple of hours I was up and running.
How can I not love PHP after all this and more?
Tiny Tiny RSS Reader : This XML Document is Invalid
I just came across this problem for this feed : http://techcircle.vccircle.com/feed/
The problem being the whitespaces at the beginning of the xml.
So we have to trim the response.
Here is the solution :
1. Open the file lib/simplepie/simplepie.inc
2. Somewhere around the line #1342 - You will find :
// Loop through each possible encoding, till we return something, or run out of possibilities
foreach ($encodings as $encoding)
{
// Change the encoding to UTF-8 (as we always use UTF-8 internally)
if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
Add the following line as the first statement in the foreach loop :
$this->raw_data = trim($this->raw_data);
Now the code should look like :
// Loop through each possible encoding, till we return something, or run out of possibilities
foreach ($encodings as $encoding)
{
$this->raw_data = trim($this->raw_data);
// Change the encoding to UTF-8 (as we always use UTF-8 internally)
if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
Subscribe to:
Posts (Atom)