All in one Ubuntu commands

apt-get install vim lamp-server^ phpmyadmin kate php-pear php5-curl thunderbird ssh rar unrar gimp wine chromium-browser opera zip unzip aptitude php5-sqlite php5-memcache php5-apc php5-pgsql

Posted in Ubuntu | Tagged , | Leave a comment

Custom Paging in WordPress

It is sometimes required in WordPress that you need to include your own paging.This is how i have done it.

$rss = fetch_feed($feed_url);
if (!is_wp_error( $rss ) ) {
$limit = 15;

$page = $_GET['page'];
if ((!$page) || (is_numeric($page) == false) || ($page < 0)) {

$page = 1; //default

}

$set_limit = $page * $limit - ($limit);

$prev_page = $page-1;

$next_page = $page+1;

$total_item=$rss->get_item_quantity(); //PUT HERE YOUR TOTAL NUMBER OF RESULTS

$total_pages = ceil($total_item / $limit);

if ($total_item == 0) {
$content_start = 0;
} else {
$content_start = $set_limit +1;
}

$content_end = (($limit*$page)>=$total_item)?$total_item:($limit*$page);
$start_page = ($page<9)?1:($page-5);
$end_page = (($start_page+9)<$total_pages)?($start_page+9):$total_pages;
$rss_items = $rss->get_items($set_limit, $limit);
$array = array();// now we can iterate through all results
$main_array = array();
$page_result = 1;
$start_limit = $limit * ($page - 1) + 1;
$end_limit = $start_limit + $limit;

//PUT YOUR CODE HERE

if ($total_pages > 1) { ?>
<div style="padding-bottom:20px;">
<span>Page <?php echo $page;?> of <?php echo $total_pages; ?></span> <?php
if ($page != 1) { ?>
<a href="?page=<?=$prev_page?>"><<</a> <?php
}
for ($count=1; $count<=$total_pages; $count++) {
if ($count == $page) { ?>
<span><?php echo $count; ?></span> <?php
} else { ?>
<a href="?page=<?=$count?>" ><?php echo $count; ?></a> <?php
}
}
if ($page != $total_pages) { ?>
<a href="?page=<?php echo $next_page; ?>">>></a> <?php
} ?>
</div> <?php
} else {
echo "No result found.";
}
Posted in WordPress | Tagged , | Leave a comment

Case Sensitive Mysql Query

By default Mysql queries are case insensitive.If we want to make it case sensitive then syntax will be

SELECT *  FROM  table  WHERE  BINARY column = ‘value’
We just need to add keyword Binary.
Posted in Mysql | Tagged , | 2 Comments

Password Protect a folder or page using apache

Make sure you have AllowOverride All

First Create any dummy file at any location.For eg i have created pass.txt in /ete/ folder

touch /etc/pass.txt

In .htaccess write this code

AuthName "Restricted"
AuthType Basic
AuthUserFile /etc/pass.txt
Require valid-user

Then Write this command
htpasswd -mc “path to file” username(any username)

For eg htpasswd -mc “/etc/pass.txt” admin

Then it will prompt for password.Give any password.

If we want to give permission on a particular file in that case we need to write this code

<FilesMatch “admin.php$”>
AuthName “Restricted”
AuthType Basic
AuthUserFile /etc/pass.txt
Require valid-user
</FilesMatch>

Posted in Apache, Ubuntu | Tagged , , | Leave a comment

Custom Atom rss elements

To show custom fields in atom rss we need to thing

(1) first define xmlns:eg=”http://example.org&#8221; in <fee xmlns

(2) use tags with the defined name for eg <eg:pagename>value</eg:pagename>

Posted in Uncategorized | Tagged , | Leave a comment

Solution of numeric keypad not working on Ubuntu

I have a Microsoft Keyboard and i don’t know what happened all of a sudden numeric keypad wasn’t working so i though there was some issue in my keyboard so i changed the keyboard but i was surprised to see problem was same again this time.

So i searched on Google and found that there was some Keyboard settings in Windows and Ubuntu.

In Ubuntu here it is how can we change it

Go to

1) System
2) Preferences
3) Keyboard (Tab: Mouse Keys)
4) Uncheck (Allow to control pointer using the keyboard).

Posted in Ubuntu | Tagged , | 2 Comments

Setup Cron on Ubuntu

.---------------- minute (0 - 59)
|   .------------- hour (0 - 23)
|   |   .---------- day of month (1 - 31)
|   |   |   .------- month (1 - 12) OR jan,feb,mar,apr ...
|   |   |   |  .----- day of week (0 - 7) (Sunday=0 or 7) OR sun,mon..
|   |   |   |  |
*   *   *   *  *  command to be executed

If we want to setup a cron using curl then syntax will be
0 */6 * * * /usr/bin/curl http://SCRIPT_PATH.php
So this cron will run every 4 hours

This script will run every 5 minutes
*/5 * * * * /usr/bin/curl http://SCRIPT_PATH.php

Posted in Ubuntu | Tagged , | Leave a comment