Fix upside down camera image on openSuse 11.4 64-bit

May 10th, 2011 | posted in Linux, blog | No Comments »

This quick fix applies to owners of Asus laptops mostly with uvcvideo driver on openSuse 11.4 64 bit. The main point is to flip the camera image to be ok on Skype. First check if you have libv4l-32bit package installed (with the required dependencies). Then create or edit an application launcher and in the Application tab  for command enter:

 export LIBV4LCONTROL_FLAGS=3 && LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype

That’s it. Here is a screenshot for better view.

 

Set mysql password after install

March 23rd, 2011 | posted in Tips & Tricks, blog | No Comments »
mysqladmin -u root password new-password

Formatting date values returned from MYSQL table to more readable format including time

March 1st, 2011 | posted in PHP, Tips & Tricks, blog | No Comments »
echo date("d-m-Y : G-i",strtotime('2011-02-26 09:47:11');

List All Hooked Functions in WordPress

February 18th, 2011 | posted in PHP, Wordpress, blog | No Comments »
function list_hooked_functions($tag=false){
 global $wp_filter;
 if ($tag) {
 $hook[$tag]=$wp_filter[$tag];
 if (!is_array($hook[$tag])) {
 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
 return;
 }
 }
 else {
 $hook=$wp_filter;
 ksort($hook);
 }
 echo '<pre>';
 foreach($hook as $tag => $priority){
 echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag</strong><br />";
 ksort($priority);
 foreach($priority as $priority => $function){
 echo $priority;
 foreach($function as $name => $properties) echo "\t$name<br />";
 }
 }
 echo '</pre>';
 return;
}
[/php]

source: http://www.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/

List All Hooked Functions

Easiest “check all” with jQuery

January 13th, 2011 | posted in Tips & Tricks, blog, jQuery | No Comments »

The jquery code:

<script type="text/javascript">
$(function () {
    $('.checkall').click(function () {
        $('.chk').attr('checked', this.checked);
    });
});
</script>

The html:

<input type="checkbox" class="checkall"/>
<input type="checkbox" value="1" class="chk"/>
<input type="checkbox" value="2" class="chk"/>
<input type="checkbox" value="3" class="chk"/>
<input type="checkbox" value="4" class="chk"/>

Get subcategories of a category in WordPress

December 26th, 2010 | posted in Wordpress, blog | No Comments »

Due to a bug in WordPress 3.0 this returns empty array:

$cats = get_categories("child_of=1");

So you can use this code instead:

$parent = 1;// your category parent ID
$where = "AND tt.parent = '$parent'";
$in_taxonomies = "'category'";
$orderby = 't.name';
$order = 'ASC';
$limit = 'LIMIT 0,1000';
$query = "SELECT t.name FROM $wpdb->terms AS t INNER JOIN
    $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id
    WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $limit";
$categories = $wpdb->get_results($query);

Detect Ajax Request in PHP

December 22nd, 2010 | posted in PHP, blog | No Comments »
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
 echo "yes";
 exit;
}

Adding a class to first and last menu items to WordPress menu

December 13th, 2010 | posted in PHP, blog | No Comments »

Add this code to your functions.php file:

function addFirstLastClass($pageList) {

 // pattern to focus on just lis
 $allLisPattern = '/<li(.*)<\/li>/s';
 preg_match($allLisPattern,$pageList,$allLis);
 $liClassPattern =  "/<li[^>]+class=\"([^\"]+)/i";

 // first let's break out each li
 $liArray = explode("\n", $allLis[0]);

 // count to get last li
 $liArrayCount = count($liArray);

 preg_match($liClassPattern, $liArray[0], $firstMatch);
 $newFirstLi = str_replace($firstMatch[1], $firstMatch[1] . " first-menu-item", $liArray[0]);

 if($liArrayCount > 1){
 $lastLiPosition = $liArrayCount - 1;

 preg_match($liClassPattern, $liArray[$lastLiPosition], $lastMatch);
 $newFirstLi = str_replace($firstMatch[1], $firstMatch[1] . " first-menu-item", $liArray[0]);
 $newLastLi = str_replace($lastMatch[1], $lastMatch[1] . " last-menu-item", $liArray[$lastLiPosition]);
 }

 // replace first and last of the li array with new lis
 // rebuild newPageList
 // set first li
 $newPageList = $newFirstLi . '';
 $i = 1;
 while ($i < $lastLiPosition) {
 $newPageList .= $liArray[$i];
 $i++;
 }
 // set last li
 $newPageList .= $newLastLi;

 // lastly, replace old list with new list
 $pageList = str_replace($allLis[0], $newPageList, $pageList);
 return $pageList;
}
add_filter('wp_nav_menu', 'addFirstLastClass');

Thanks to Eliot Kristan

No sound in Pidgin in openSuse 11.2

August 3rd, 2010 | posted in Linux, Tips & Tricks, blog | 1 Comment »

If none of the options available produce sound in Pidgin, choose command and enter aplay %s.



Add Facebook chat to Pidgin

June 6th, 2010 | posted in Linux, blog | 1 Comment »

Want to keep in touch with your Facebook friends through Pidgin?  Here I’ll show you how to easily add Facebook chat to this popular multi-protocol chat client.

1. First, make sure you have a username for your Facebook account, it’s http://facebook.com/your.username

2. Open Pidgin, go to Accounts->Manage Accounts and click Add.

3. From the Protocol list select XMPP

4. For the username field enter your Facebook username (without the “http://facebook.com/”)

5. For the domain field enter chat.facebook.com

6. Leave the Resource field empty

7. Enter your facebook password Read the rest of this entry »