Macbook Pro, the missing keys

After purchasing the Macbook Pro on July, 2010 I noticed that some keys that I use most frequently, are missing on the keyboard. After passing more than 1 month, I also noticed my coding speed drastically reduced due to missing of those keys. So, I started Goolaptop keyboardgling for help. Though I did not like the solutions but still better than unavailability. The reason of my dislike is the combination of multiple keys! Here, I write how to perform some tasks whose keys are missing.

Home/End of Line
These two keys are used very frequently during programming. We can go home / end of the line using the following combination: Continue reading →

Tips for WordPress Cron functions

WordPress provides some nice APIs for executing unattended scheduled tasks without relying on any external cron! Usually, we need to create a cron from our control panel / systems! However, if you implement built in cron features of WordPress, you gain better portability of your WordPress site!

However, it has a great limitation! This cron fully relies on site hits! WordPress triggers its cron functions after someone visits the site! When anyone visits your site, WP checks if any cron are supposed to be executed on or earlier of that moment! If no one visits your site, WordPress will fail to execute your tasks!

In this blog, I am going to show two tips that may be helpful while you work with wp-cron functions!

Continue reading →

Toggling ASC/DESC sorting using Animated table sort plugin for jQuery

Just few mins ago, from a tweet of Tareq Hasan, I came to learn about Animated Table Sort plugin for jQuery. Seeing the demo I was stunned and decided to implement on a project I was working right then!

After implementing, I see it can sort in one way. Either ascending or descending. If we set the parameter to

sortDesc: true

it sorts the table in descending order, otherwise ascending order. But, I wanted in both way. I mean, after clicking on the header, it should toggle between order. Suppose, on first click, it sorted ascending order. However, the second click should sort in descending order.
Continue reading →

Recaptcha with AJAX application, get new challenge using JavaScript

Currently, I am working on a commercial project (for me) that will be dedicated to the soul of Michael Jackson. I have used some AJAX based interface where I have used reCaptcha challenges to fight spamming. The form where I have used reCaptcha, will be submitted through AJAX calls. As the page won’t reload, the same captcha challenge exists even the user makes a mistake during filling the form.  I wanted to show a new challenge each time he/she makes a mistake. I thought, I will be in trouble in this part! However, I have seen it is extremely easy to get a new challenge. Continue reading →

Converting Youtube videos to MP3!

Yesterday I have downloaded two fantastic songs from Youtube. Later, I wanted to move them to my mobile as MP3. As the downloaded vidoes are in FLV format, I would need to convert them to MP3. I thought, no problem, I have ffmpeg install in my LinuxMint :).

I hit the following command:

Continue reading →

Passing filename arguments to PHP from shell and space issue…

Today, while working with a project to import thousands of articles from text files to wordpress,  I had faced a trouble while I am executing a shell script to iterate through all text files and call a PHP script with sending the filename as argument. The PHP script would then process the file as our requirement. The shell script looked like:

for i in `find . -type f -name '*.txt'`;

do

php import_posts.php $i

done

Here, $i would be the filename and it is passed to PHP script for processing. But the problem is that, when the filename (including directory name) consists any whitespace in its name, the script would broken. For example, some files path looked like
/home/user/articles/Internet Business/Web Hosting/how_to_start_your_company.txt

Here, notice the space after Internet and Web. The shell script was breaking just after Internet. It was sending /home/user/articles/Internet as argument to PHP script and obviously PHP script was failed to find this file.

After searching a lot, finally I found a solution.

It was really simple. I am quoting from his blog:

If none of your files or folders have spaces in their names, then this isn’t a problem, but that is increasingly unlikely nowadays.  If your songs do have spaces in their filenames, then the solution is to change how the shell splits that output.  This is controlled by the variable $IFS, which is set to spaces, tabs, and newlines by default.  We’d like it set to just newlines, so we do:

So, here is the solution. I just put the following line at the top of my shell script.

export IFS=$'\n'

After that everything is fine. The script is running exactly how I intended it to run.

Thanks for Anthony for his solution.

Articlesnatch.com scraping tutorial, getting full article

In my last three tutorials I have discussed how to scrap contents from www.articlebase.com. In this part, I will show how to scrap contents from www.articlesnatch.com. However, unlike the previous tutorials, I will not use DOMDocument in this part. I will not use regular expressions either.

I will show how to get full article. I won’t show how to get articles/links under any category as articlesnatch.com offers feed for each category. So it is easy to get article summary and links of any category. As the feed does not include full text, I will just show how to get it.

Getting Article Body

$html = file_get_contents($link);

We need the contents that is within the div with a class named “KonaBody”. That mean, our target contents are within:

<div class="KonaBody">

......

......

</div>

So, we may remove anything before this div.

$desc = strstr($html,'<div class="KonaBody">');

Continue reading →

Articlebase.com scraping tutorial – part 3, getting full article

In the first part, I have shown how to get links under any category. In the second part, I have shown how to get links for any search term.  In this part, I will show how to fetch a full content.

Le’ts get the html.

$link = ‘artcile_base_article_link’;

$html = file_get_contents($links);

Now, create the objects.

$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);

Continue reading →

Articlebase.com scraping tutorial – part 2, getting search links

In the first part, I have shown how to get links under any category. Now, we will get links when you search articlebase.com with a search term.

Getting HTML

$keyword = ‘beauty’;

$page = intval($page);
$url = “http://www.articlesbase.com/find-articles.php?q=”.strtolower(urlencode($keyword)).”&page=”.urlencode($page);

$html = file_get_contents($url);
if(!$html) return false;

Initialize objects

$dom = new DOMDocument();
@$dom->loadHTML($html);
$dom = new DOMXPath($dom);

Continue reading →

Articlebase.com scraping tutorial – part 1, getting links under category

Recently I have worked with several web scraping projects. I though I can write my tips so that it comes to usages of others. I am also writing a library for grabbing contents from a few popular article resources like www.articlesnatch.com, www.articlebase.com, www.ezinearticles.com.

Initially I have used simple html dom for traversing the html. It is easy and nice but the script is memory hog. I even sometime would failed to work under 256MB allocated RAM for PHP, specially when you run such traversing in a few (loop) cycles. So, I totally dropped using that and used PHP’s DomDocument.
In my projects I have used cURL for getting contents from remote URL. But here I will show by using simple function file_get_contents().

Getting Articles’ Links under any Category

The category page of article page lists a number of links to articles with a few lines of excerpts. We will fetch the links only.

First of all retrieve contents from remote URL:

//prepare URL

$category = 'Marketing';

$page = 1;

$url = "http://www.articlebase.com/".strtolower($category)."-articles/$page/";

Continue reading →