Thursday, May 5, 2011

Firefox Setting Google As Default Search Engine using about:config

If Searching in the main address bar redirects you to a search engine other than Google, that means some firefox add-on is controlling your search options. You can check your add-on preferences for correcting it. There should be some option in a nice add-on but there are some add-ons which don't even ask!

So for Changing the settings type about:conifg in the address bar. about:config is a advanced settings section of firefox. If you're not sure what to do Don't change the default settings. This may make your browser unstable.


In the about:config page search for keyword.url. If you see the value of the term other than google.com click on the value to toggle vaules. when you have got google.com leave it there and test searching in your address bar and Google should be your default search enging now!

Some Facts:


You can see the mozilla book verse typing about:mozilla

For Chrome browser There is no about:config pag. But there are some about pages which you can see by typing about:about.

about:about is not supported in mozilla firefox 3.6

Tuesday, May 3, 2011

JavaScript Find all Elements of an object

To find All functions and variables of a Javascript class or object you can use the following function. It's a silly little Function

function getObj(obj){ 

  var html = '';  

  for (var key in obj){

  html +=   (key + '  -- > '+ typeof obj[key]); 

  
}        

 return html;  

  }

You Can test the function here. Select a default Object and you will see the object elements. If You are using firefox you may seem nothing when you select the document object.






Tuesday, April 5, 2011

[SOLVED] WP-PageNavi, wp_pagenavi for custom query

WP-Pagenavi is a great plugin for paginating your WordPress Pages. Many people find it not working for custom queries like

get_posts, query_posts or for WP_Query. Today we'll solve the mystery.

Previously I edited the plugin to work for the custom queries but now the latest version has a built in feature to add your custom query object.

Suppose we make a custom query for getting some specific posts. The post ids are 1,5,8,9,10,34

$my_query = new WP_Query(
 array(
 'post_in' =>array(1,5,8,9,10,34)
 )

);

//If the total page number > 1 we will show the pagination

if($my_query->max_num_pages>1)
if(function_exists('wp_pagenavi'))
wp_pagenavi(array(
   'query' =>$my_query   
   ));

//note how  $my_query has been passed to wp_pagenavi  



You should set your posts_per_page to lower than the total page number to see the pagination. You should see the Pagination now but Wait Sailor, We are not done Yet!

You see that when you click on the second page you actually see the contents from the first page. So the solution is here.

Check your WordPress version before trying the solution


//Revised code to show posts from all pages

// page no from query

$paged = get_query_var ('paged'); 


// pass the paged value to the WP_Query

$my_query = new WP_Query( array(
 'post__in'  =>  array(1,5,8,9,10,34) ,
 'paged' => $paged
 
) );


//If the total page number > 1 we will show the pagination

if($my_query->max_num_pages>1)
if(function_exists('wp_pagenavi'))
wp_pagenavi(array(
   'query' =>$my_query   
   ));

//note how  $my_query has been passed to wp_pagenavi  



And you can use wp_pagenavi for get_posts,query_posts providing a paged value. If you're having any problem implementing, you can post your problem here. I will try to solve your problem.

Monday, March 28, 2011

wordpress cron wp_schedule_single event

In my previous post I wrote how to use
the wp_schedule_event. This post is about wp_schedule_single_event.

wp_schedule_single_event is for scheduling a single event but you can use it to execute a function more than once.

wp_schedule_single_event( $timestamp, $hook, $args = array())

$timestamp is the timestamp when we want to execute our function

$hook is the hookname(a string) that we will attach our function with.

$args is optional parameter WordPress uses to make a md5 hash string to make the schedule unique

If you want to execute your function 'my_cron_function' at the timestamp= 'timestamp' follow the code

add_action('my_hook','my_cron_func');

function my_cron_func(){
//do something here
} 

wp_schedule_single_event('timestamp', 'my_hook') 
you can use different timestamps with your hook 'my_hook' , but remember that
WordPress checks if an identical event is to be executed in 10 minutes, if so WordPress won't execute the current event.

if you use
wp_schedule_single_event(time(), 'my_hook')
wp_schedule_single_event(time()+20, 'my_hook');
WordPress will discard the second one because it's scheduled to execute to in 10 minutes of the previous identical one.
see the code the the wp-includes/cron.php

if ( $next && $next <= $timestamp + 600 )
  return;
Executing the function more than once using wp_schedule_single_event! if you use some dynamic value in the $timestamp you can make this execute more than once. for example If you use this code
wp_schedule_single_event(time()+60, 'my_hook')
when you first activate the plugin the code schedules to execute the function 1min after the current time if any visitor visits the page if you use
wp_schedule_single_event(time(), 'my_hook')
it will execute the function immediately. If you refresh your page in one minute WordPress won't execute the cron job as WordPress has set the default time interval between two cron jobs to 1 minute look for the code the wp-includes/cron.php
/*
 don't run if another process is currently running it or more
 than once every 60 sec.
*/
 if ( $flag + 60 > $local_time )
  return;
so if you want any cron job to execute maximum time you can use
wp_schedule_single_event(time(), 'my_hook');
another way to do this is to use
wp_schedule_event(time(),'every_minute','my_hook');
you have make the 'every_minute' schedule yourself see the example Here

Thursday, March 24, 2011

Synchronizing Firefox and emacs

I am loving Emacs. Actually I am writing from emacs now. Synchronizing between firefox and emacs has been a piece of cake due to the "It's all text/textarea firefox add-on".

You can download the addon from here

After installing this addon go the Tools>add-ons>It's all Text! preference. In the 'editor textfield' add the emacs location. You can add any text editor executable location here.
You can add a shortuct key for opening emacs.It will save you some clicks.


how it works
The credits goes the addon. when there is a textarea in the webpage you will see a edit button created by the firefox add-on. You can open emacs by clicking on that button or you can choose in which mode you want to edit by right-clicking.

when emacs has opened up write something and save(C-xC-s) the text and see how the text has been imported the the webpage textarea automatically. You can also visualize how this code will look when you're writing by (C-cC-v)

About Me

Web Developer From Dhaka, Bangladesh.