Tuesday, August 29, 2006
Hardware issues in ubuntu/xubuntu
Posted by
code pirate,
on
5:09 PM
Recently i was trying xubuntu. I was facing some issues with my 4 year old PC. My realtek ethernet card and onboard sound card was not detected. Even `lspci` returned nothing. After banging my head against the wall for a few hours and searching on the net revealed that i have to add "pci=noacpi" to my kernel arguments(in grub press 'e' and at the end of the string append this).
After that everything worked like a charm. I dont know why this happens but it did gave me some problems cause i had to reinstall some distros cause my hardware was not getting detected properly.
After that everything worked like a charm. I dont know why this happens but it did gave me some problems cause i had to reinstall some distros cause my hardware was not getting detected properly.
Friday, August 25, 2006
Open standards
Posted by
code pirate,
on
2:26 PM
Recently i was reading an article about ODF. Clearly open standards are what we should be looking for. Binding ourselves to a proprietary is going to harm us in the future. For example if i have a document i would want it to be accesible to me for eternity. Just because the software it was created in is no longer available or for a price shouldnt mean anything.
Heck i "own" that data. So the bottom line is softwares (like Open office) which support open document standards need to be encouraged.
Heck i "own" that data. So the bottom line is softwares (like Open office) which support open document standards need to be encouraged.
Tuesday, August 22, 2006
Very nice thought
Posted by
code pirate,
on
2:52 PM
I was for a long time anguished by my peers who used to rubbish PHP as a "hacking" language. Fit only for write once forget afterwards kinda scripts.
I always believed that if you have some self-descipline you can do pretty much anything* with your chosen language.
*Conditions apply
Heres a link to an interesting article from lesscode.org
I always believed that if you have some self-descipline you can do pretty much anything* with your chosen language.
*Conditions apply
Heres a link to an interesting article from lesscode.org
Monday, June 12, 2006
Parsing large log files with PHP
Posted by
code pirate,
on
1:45 PM
Today i was struggling to parse huge log files with PHP. Problem was the log file was huge in size and the new entries were being appended at the end. So PHP was taking forever to parse this file and extract last few records.
The solution? use AWK. Shell programmers swiss army knife :)
I knew every line had a unique time stamp (well almost) and i would store the timestamp of last line parsed. So i wrote a small command in AWK:
exec (" awk '/Jun 12 00:13:01/ {line_fnd = NR; }END {print NR,line_fnd}' OFS='=' /var/log/huge.log ", $arg1);
This returns the line number found and total number of lines separated by '=' symbol.
Then its quite easy to parse the output of this command and find the total new lines to grab. Then you can tail that many lines and redirect the output to a temporary file and parse the file line by line and do whatever you want with it and at last store the timestamp of the last line you parsed.
This shaved off quite a huge time of my script execution time :)
Anyone facing this problem might use this technique or if there is a better solution then please do let me know.
The solution? use AWK. Shell programmers swiss army knife :)
I knew every line had a unique time stamp (well almost) and i would store the timestamp of last line parsed. So i wrote a small command in AWK:
exec (" awk '/Jun 12 00:13:01/ {line_fnd = NR; }END {print NR,line_fnd}' OFS='=' /var/log/huge.log ", $arg1);
This returns the line number found and total number of lines separated by '=' symbol.
Then its quite easy to parse the output of this command and find the total new lines to grab. Then you can tail that many lines and redirect the output to a temporary file and parse the file line by line and do whatever you want with it and at last store the timestamp of the last line you parsed.
This shaved off quite a huge time of my script execution time :)
Anyone facing this problem might use this technique or if there is a better solution then please do let me know.
Tuesday, April 18, 2006
New company
Posted by
code pirate,
on
4:34 PM
Just joined my new company and it is a religious experience for me :0.
After working at my previous employers for more than two years, i feel like a religious convert here at my new company. Like a convert i feel fascinated about everything here ;-)
I am especially fascinated by the way this company works, every thing is planned. We were formally inducted and the process went like a ceremony :P, as u can see i am happy for my self (what a sod you might say haan ;) )
Okay would make it a habit to post atleast once a week, so bye for now.
After working at my previous employers for more than two years, i feel like a religious convert here at my new company. Like a convert i feel fascinated about everything here ;-)
I am especially fascinated by the way this company works, every thing is planned. We were formally inducted and the process went like a ceremony :P, as u can see i am happy for my self (what a sod you might say haan ;) )
Okay would make it a habit to post atleast once a week, so bye for now.
Tuesday, February 28, 2006
Simply the best PHP framework
Posted by
code pirate,
on
8:11 PM
My search has ended. I think i have found the best PHP application development framework. After so many hours of searching, installing, configuring so many frameworks from sourceforge, freshmeat etc, i have found the best solution for my problems. Ok let me explain a few things here. I wanted a framework which:
Using it is extremely simple. You can even use it with your existing applications. It doesnt forces itself on you. This framework in my opinion is the ideal for my needs. It makes so many day to day tasks so simple that it makes u think "why didnt i think of it".
I would rate it above some other frameworks i tried. For one its footwork is so small, you can strip it of unwanted functionality and it comes to around 800K.
Basic usage is like this:
I would look into it more thoroughly but whatever time i have spent on it has made me cry with joy. OSS rules.
- Is flexible.
- Is easy to use.
- Doesnt force a design pattern.
- Dont overdo the MVC, Ajax etc.
- Provides a stable base for my applications.
Using it is extremely simple. You can even use it with your existing applications. It doesnt forces itself on you. This framework in my opinion is the ideal for my needs. It makes so many day to day tasks so simple that it makes u think "why didnt i think of it".
I would rate it above some other frameworks i tried. For one its footwork is so small, you can strip it of unwanted functionality and it comes to around 800K.
Basic usage is like this:
- U define a config file to suite your needs.
- U include this file in any file you make.
- Import classes u plan to use (Forms, templaes etc....)
- initialise the classes and provide it with details and you are done.
I would look into it more thoroughly but whatever time i have spent on it has made me cry with joy. OSS rules.
Saturday, February 18, 2006
PHP and SOAP
Posted by
code pirate,
on
5:15 PM
I mentioned in one of my previous posts how i accessed the betfair api. The reason i am mentioning it again is because of this site. I owe quite a lot of things to this site. When i was banging my head against the wall to find a solution to my problems i found pattemplate to be quite helpful. Not that it has anything to do with SOAP.
Here is a summary of my problem, i needed to access the api through PHP and the documentation on their site was not helpful. Then i came across some code which used NuSOAP library. The response was very slow, and also the class i used was not sufficient to handle all the operations allowed in the API. To complicate matters further the Betfair people switched to a new version of their api and i was left on my own to find a solution. Then in one of the Perl forums i found a snippet where somebody (god bless him!) showed some code on how to send a raw request to a soap server.
I latched onto that chance and digged in PHP to find equivalent solution. Here is what i did. I converted the XML request data into templates and used Pat-template system to fill-in the values. Then i used the excellent Curl library to send raw POST request to the betfair SOAP server and tada! we got response.
//function to execute curl calls
function call_curl($xml)
{
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, API_URL ); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // times out after 1 min
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml ); // add POST fields
if( LOCAL )
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$header[] = "SOAPAction: ". API_URL;
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: text/xml; charset=utf-8";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch); // run the whole process
if (curl_errno($ch))
{
print curl_error($ch);
return 0;
}
else
{
//now that we have got a result, parse this soap packet and return the XML doc
$parser = new soap_parser($result,'UTF-8','',TRUE);
$result = $parser->get_response();
//print_R($result);
curl_close($ch);
if($result["Result"]["header"]["errorCode"] != "NO_SESSION" )
{
update_session_key($result["Result"]["header"]["sessionToken"] );
}
return $result;
}
}//function ends
The rest as they say was history ;-) Btw if u dont know anything about Curl library i would advise u to give them a visit. It is an excellent tool. I have used it in various projects and here are a few of the uses i could find in my experience:
Here is a summary of my problem, i needed to access the api through PHP and the documentation on their site was not helpful. Then i came across some code which used NuSOAP library. The response was very slow, and also the class i used was not sufficient to handle all the operations allowed in the API. To complicate matters further the Betfair people switched to a new version of their api and i was left on my own to find a solution. Then in one of the Perl forums i found a snippet where somebody (god bless him!) showed some code on how to send a raw request to a soap server.
I latched onto that chance and digged in PHP to find equivalent solution. Here is what i did. I converted the XML request data into templates and used Pat-template system to fill-in the values. Then i used the excellent Curl library to send raw POST request to the betfair SOAP server and tada! we got response.
//function to execute curl calls
function call_curl($xml)
{
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, API_URL ); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // times out after 1 min
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml ); // add POST fields
if( LOCAL )
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$header[] = "SOAPAction: ". API_URL;
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: text/xml; charset=utf-8";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch); // run the whole process
if (curl_errno($ch))
{
print curl_error($ch);
return 0;
}
else
{
//now that we have got a result, parse this soap packet and return the XML doc
$parser = new soap_parser($result,'UTF-8','',TRUE);
$result = $parser->get_response();
//print_R($result);
curl_close($ch);
if($result["Result"]["header"]["errorCode"] != "NO_SESSION" )
{
update_session_key($result["Result"]["header"]["sessionToken"] );
}
return $result;
}
}//function ends
The rest as they say was history ;-) Btw if u dont know anything about Curl library i would advise u to give them a visit. It is an excellent tool. I have used it in various projects and here are a few of the uses i could find in my experience:
- Form POSTing
- Downloading a file and saving it to disk
- Uploading files to a FTP server with authentication
- Spidering!
- Loggin in to a site and navigating through password protected areas and downloading feeds etc.
- Telnet
- Data transfer between servers
Tuesday, February 07, 2006
I need RAM
Posted by
code pirate,
on
9:04 PM
I need RAM and lots of it :-) Just installed Kanotix and my system takes a dive every time i run XAMMP. For those of you came late, XAMMP is a all in one solution for a web server. So if you dread compiling and configuring Apache + MySQL + PHP and rest u need to take a look at this. It works on most systems.
So where was i?? Yes i need RAM My current rig runs AMD(what else ;-) ) duron 1.2 Ghz with 128Mb RAM. It was fine until i upgraded my distro to kanotix that i noticed my machine was thrashing while working. This made me search for distros which were not hard on configuration and would run fine with old systems. This took me to SLAMPP which is based on SLAX but comes with XAMPP preinstalled..
Lets see if it works otherwise i have to buy some RAM for my old PC. If you are interested in finding the right distro for u may i suggest distrowatch it lets you search on so many parameters.
BTW linux is the way to go if u want to learn about real computing. How things work underneath. And running linux is cool too. For developers it is the best, unless ofcourse you work on Micro$oft technologies. If u work on .NET u might be interested in MONO. This project makes it possible to run .NET on apache
hey did u visit my site on zeeblo. You should cause i have just installed JAWS CMS on it and it rocks. See my site:
So where was i?? Yes i need RAM My current rig runs AMD(what else ;-) ) duron 1.2 Ghz with 128Mb RAM. It was fine until i upgraded my distro to kanotix that i noticed my machine was thrashing while working. This made me search for distros which were not hard on configuration and would run fine with old systems. This took me to SLAMPP which is based on SLAX but comes with XAMPP preinstalled..
Lets see if it works otherwise i have to buy some RAM for my old PC. If you are interested in finding the right distro for u may i suggest distrowatch it lets you search on so many parameters.
BTW linux is the way to go if u want to learn about real computing. How things work underneath. And running linux is cool too. For developers it is the best, unless ofcourse you work on Micro$oft technologies. If u work on .NET u might be interested in MONO. This project makes it possible to run .NET on apache
hey did u visit my site on zeeblo. You should cause i have just installed JAWS CMS on it and it rocks. See my site:
Tuesday, January 10, 2006
Evolution of a PHP programmer
Posted by
code pirate,
on
8:11 PM
Ok lets see what i did when i first "learned" how to hack PHP. Wrote some (lot!) scripts which said 'hello world' then did some counting then print some pyramids and what not. The next step was 'i was told' to make it show dynamic content. That is the good old print the date and time on some lame html.
Next came the file handling. PHP rocks on that one too. Its quite easy to work with files in PHP.
Then i guess came the guestbook and DB connectevity. After making lots of stray pages you realise its no good ;-) and you start to do "require header.php" etc. After lots of projects you realise HTML sucks. What with lots of inline coding. It becomes tedious to changel logic.
Then u realise u should separate the two of them. That is the presentation logic and the business logic. see: http://www.sitepoint.com/forums/showthread.php?t=123769&page=1&pp=25
This is when you pick up a template engine or two. BTW checkout pattemplate, it rocks IMHO. So you go back and realise its cool to use tempates and switch themes with changing the template folder.
After some point of time you get tired of the omnipresent FORMS. You say what the #$@#. These things suck up my whole time. Then u start to scratch your head and say "i need a method to my madness ©". You start to use form generators and stuff like that. Then time passes like a quiet river. And then bang you are back to the square one. Your project is a mess of classes (your own and some stolen). You find it hard to make new changes.
Then you decide to take things in your own hand. You start to look for a framework!!. After going through sourceforge.net and freashmeat you download a few of them and install them. After a few wasted days you realise all of them are total crap :-(. Not what you have imagined.
Then you think what every other serious php programmer thinks, why not my own web framework. This leads to another entry in the sourceforge and freashmeat etc. And you loose interest after some time and go back to the square one.
After some time u rediscover that frameworks can be good too:
http://stevenf.com/mt/2005/05/cake_is_good.php
Heck i cant help it, it seems to be my story. So please dont hold anyone responsible for my rants ;-).
See u soon.
Next came the file handling. PHP rocks on that one too. Its quite easy to work with files in PHP.
Then i guess came the guestbook and DB connectevity. After making lots of stray pages you realise its no good ;-) and you start to do "require header.php" etc. After lots of projects you realise HTML sucks. What with lots of inline coding. It becomes tedious to changel logic.
Then u realise u should separate the two of them. That is the presentation logic and the business logic. see: http://www.sitepoint.com/forums/showthread.php?t=123769&page=1&pp=25
This is when you pick up a template engine or two. BTW checkout pattemplate, it rocks IMHO. So you go back and realise its cool to use tempates and switch themes with changing the template folder.
After some point of time you get tired of the omnipresent FORMS. You say what the #$@#. These things suck up my whole time. Then u start to scratch your head and say "i need a method to my madness ©". You start to use form generators and stuff like that. Then time passes like a quiet river. And then bang you are back to the square one. Your project is a mess of classes (your own and some stolen). You find it hard to make new changes.
Then you decide to take things in your own hand. You start to look for a framework!!. After going through sourceforge.net and freashmeat you download a few of them and install them. After a few wasted days you realise all of them are total crap :-(. Not what you have imagined.
Then you think what every other serious php programmer thinks, why not my own web framework. This leads to another entry in the sourceforge and freashmeat etc. And you loose interest after some time and go back to the square one.
After some time u rediscover that frameworks can be good too:
http://stevenf.com/mt/2005/05/cake_is_good.php
Heck i cant help it, it seems to be my story. So please dont hold anyone responsible for my rants ;-).
See u soon.
Wednesday, December 14, 2005
Why i love php?
Posted by
code pirate,
on
6:24 PM
Some people (stupid?) ask me why i love php so much. Hmm.. one would expect me to say
Some things which i hate about PHP? Naah... lets not start on this ;-)
- it supports so many databases natively.
- Its quite easy to learn.
- You can do pretty much anything in PHP (except multi-threading?).
- Not feel guilty about using MS product (lol).
- Its Free.
- Good documentation.
Some things which i hate about PHP? Naah... lets not start on this ;-)
Saturday, November 26, 2005
Accessing latest Betfair API through PHP
Posted by
code pirate,
on
2:33 AM
Got succesful in accessing betfairs latest api in php. At first i tried using NuSoap webservice package but couldnt pull it off.
Then i saw someone do it in Perl by sending (Post?) Raw XML to http://www.betfair.com/publicapi/BFService/
This is when i gave it a try in php and voila success! Here is what i did:
Then i saw someone do it in Perl by sending (Post?) Raw XML to http://www.betfair.com/publicapi/BFService/
This is when i gave it a try in php and voila success! Here is what i did:
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, API_URL ); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // times out after 1 min
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml ); // add POST fields
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$header[] = "SOAPAction: ". API_URL;
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: text/xml; charset=utf-8";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch); // run the whole process
if (curl_errno($ch))
{
print curl_error($ch);
return 0;
}
else
{
//now that we have got a result, parse this soap packet and return the XML doc
$parser = new soap_parser($result,'UTF-8','',TRUE);
$result = $parser->get_response();
//print_R($result);
curl_close($ch);
if($result["Result"]["header"]["errorCode"] != "NO_SESSION" )
{
update_session_key($result["Result"]["header"]["sessionToken"] );
}
return $result;
} To this end i used the PatTemplate system to stuff values into the XML templates, and got the raw XML back. If anyone needs it i can supply the soap parser class i stole ;-). It was one of the class in NuSoap and just changed a few bits here and there.
Friday, November 25, 2005
i hate crons
Posted by
code pirate,
on
7:07 AM
Just when i thought i had cron jobs in control i lost it :-( , still banging my head...
Presto, its working again.... i forgot to send query string to a page you need to add "--get" in curl request. Basicaly i was calling a php script in cron and passing it parameters. One thing i thought would work was passing the query string in the URL itself which curl calls.
My mistake, now its fixed you call it with /usr/bin/curl -d "var1=adfdafs&var2=xyz" --get http://someurl.com/somefile.php
hurray,
Presto, its working again.... i forgot to send query string to a page you need to add "--get" in curl request. Basicaly i was calling a php script in cron and passing it parameters. One thing i thought would work was passing the query string in the URL itself which curl calls.
My mistake, now its fixed you call it with /usr/bin/curl -d "var1=adfdafs&var2=xyz" --get http://someurl.com/somefile.php
hurray,
Wednesday, November 23, 2005
Mysql fulltext indexing
Posted by
code pirate,
on
10:38 AM
Just compiled sphinx, the mysql fulltext indexer. Compiling it was a breeze. And when i was stuck at a point, the original developer ( Andrew Aksyonoff, shodan [at] shodan.ru ) helped me out.
Must say OSS makes the world a better place to live in, Red Hat notwithstanding ;-)
Okay on sphinx, i indexed my table which had close to 700,000 rows of data (Blob), and it indexed it in under 100 secs!!. The provided api is good too (PHP and perl at the moment). But one thing it lacks, which i think should be there to make it a worthy replacement to mysql fulltext indexing itself is that you can not say +findme -leaveme in a search query.
Nevertheless it did show pretty neat results and it is one utility to watch out for. For more info visit: www.shodan.ru/projects/sphinx/
Must say OSS makes the world a better place to live in, Red Hat notwithstanding ;-)
Okay on sphinx, i indexed my table which had close to 700,000 rows of data (Blob), and it indexed it in under 100 secs!!. The provided api is good too (PHP and perl at the moment). But one thing it lacks, which i think should be there to make it a worthy replacement to mysql fulltext indexing itself is that you can not say +findme -leaveme in a search query.
Nevertheless it did show pretty neat results and it is one utility to watch out for. For more info visit: www.shodan.ru/projects/sphinx/
Subscribe to:
Posts
(
Atom
)