Tuesday, 10 December 2013

Buddypress show date and time of post instead of elapsed days and hours

In the themes functions.php add this (the 19800 is 5:30 hours in seconds for IST) :

function format_activity_date() 
    return date("M j, Y G:i", strtotime($activityDate)+19800);
add_filter('bp_activity_time_since', 'format_activity_date');

Note: This does not affect comments

Friday, 6 December 2013

Wordpress - Create a plugin to override a pluggable function



Thursday, 5 December 2013

Change the version of a wordpress javascript file

Search for wp_enqueue_script and change the version number in the argument.


Using at and crontab


List of all users and groups

To view all users:

cat /etc/passwd | cut -d: -f1

To view all groups:

cat /etc/group |cut -d: -f1

Saturday, 30 November 2013

Low-level PHP Mail Script

How to send an email with PHP without using the built-in mail() function


Tuesday, 26 November 2013

Buddypress Message Auto-complete, inclusion of Non-friends

You have to edit the file wp-content/plugins/buddypress/bp-messages/bp-messages-loader.php

on line 92


        $this->autocomplete_all = defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL');


        $this->autocomplete_all = define( 'BP_MESSAGES_AUTOCOMPLETE_ALL','true' );

Thursday, 21 November 2013

The buddypress bp global object


Increasing the php file upload size limit

The default file upload size limit specified in php.ini is 2MB and the post size limit is 8MB. You can increase both to 25MB by modifying the appropriate lines to this:

upload_max_filesize = 25M
post_max_size = 25M

Location of php.ini

In the terminal type

php --ini

To view the locations and names of all the ini files that were parsed.

Solution Selling - A sales method


Running an Android VM in Linux


Installing Microsoft Fuzzy Lookup

You need a Windows 7 system with Office 2010 or higher. You also need .net framework 4, and Visual Studio 2010 Tools for Office Runtime.

.net 4 framework: www.microsoft.com/en-in/download/details.aspx?id=17718

VS 2010 tools for office runtime: http://www.microsoft.com/en-us/download/details.aspx?id=40790

To download MS Fuzzy Lookup for Excel:


Cloning a disk on Linux


Create a tar archive preserving all attributes

tar --selinux --acls --xattrs  -cvf file.tar /var/www

Wednesday, 20 November 2013

Backup entire installed OS

sudo rsync -aAXv /* /mnt/backup_vol --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}

The above command will backup all the OS files with the regular attributes and SELinux attributes. rsync also allows the backups to updated. The backup path should be to a Linux filesystem.

To restore the OS from the backup, and more details see: https://wiki.archlinux.org/index.php/Full_System_Backup_with_rsync

Create tar archive and exclude files and directories


Linux: How to create a filesystem in a file

There are two steps. One should create a large empty file. Then that file should be partitioned and formatted.

To create the empty file on a Linux filesystem, use fallocate:

fallocate -l 10G path/to/file/image.img

This won't work in non-Linux file systems such as FAT32. For those you can used the dd command to create a file full of zeroes.

dd if=/dev/zero of=/path/to/file/image.img -bs=10M -count=20480

The above command will create a 200gb file. The calculation is 204800 / 10 = 20480. The block size should be the size of the storage device's buffer. The speed of creation of the file depends on the size of the block size.

After creating the file, the filesystem should be created. mke2fs will give a warning but you can proceed after entering 'y'.

mke2fs -t ext4 /path/to/file

To mount the filesystem of the file, create a directory in the /mnt directory, and then mount it using the mount command. The filesystem won't show up as a device in the file manager but will function as a separate filesystem when you navigate to the mount directory.

sudo mkdir /mnt/backup_vol
sudo mount -o loop /path/to/disk_image /mnt/backup_vol

The filesystem can be accessed from /mnt/backup_vol

To unmount the filesystem:

sudo umount /mnt/backup_vol

Reference: http://freecode.com/articles/virtual-filesystem-building-a-linux-filesystem-from-an-ordinary-file

Friday, 15 November 2013

Renaming a wordpress theme


PHP: put printed data into a variable


PHP get the current URL

To get the actual URL (non necessarily the one shown in the address bar because of URL rewriting):

$actual_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
To get the URL shown in the address bar:

$displayed_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Manually creating a Buddypress menu

The simplest method:


But this works only when the current page is a member page (url is http://host/members/username). Because the function generates a menu with relative links.

The below code will replace the relative links with absolute ones:

$bp_user_link = bp_loggedin_user_domain();
 $the_user_nav = ob_get_clean();
 print str_replace('Profile</a></li>','Profile</a></li>'.$messages_code,str_replace('href="','href="'.$bp_user_link,$the_user_nav));

bp_loggedin_user_domain gives the url http://host/members/username/

Since bp_get_displayed_user_nav directly prints the code, to capture the code in a variable we have to use ob_start();

One odd thing is that this command will not output the Messages menu in non-member pages. Therefore this has to be obtained separately.

  $bp_user_link = bp_loggedin_user_domain();
  $messages_count = messages_get_unread_count();
  $messages_code = "<li><a id='user-messages' href='{$bp_user_link}messages/'>Messages


Putting it together:

$bp_user_link = bp_loggedin_user_domain();
$messages_count = messages_get_unread_count();
$messages_code = "<li><a id='user-messages' href='{$bp_user_link}messages/'>Messages 


      $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
      $the_user_nav = ob_get_clean();
      print str_replace('Profile</a></li>','Profile</a></li>'.$messages_code,str_replace('href="','href="'.$bp_user_link,$the_user_nav));

$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$the_user_nav = ob_get_clean();
print str_replace('Profile','Profile'.$messages_code,str_replace('href="','href="'.$bp_user_link,$the_user_nav));
This code works on a stand-alone page. However, when the code should be modified when putting it in a template. Because the same template is used in member and non-member pages.

$current_url_part = "$_SERVER[REQUEST_URI]";
$current_url_part_9 = substr($current_url_part,0,9);

if(!($current_url_part_9 == "/members/" && $current_url_part != "/members/")) // the second check is because the members page is simply, it doesn't have the username after it
 /* put an if over here where you check wether the url is under members. if so, show the regular bp_get_displayed_user_nav */
$bp_user_link = bp_loggedin_user_domain();
$messages_count = messages_get_unread_count();
$messages_code = "<li><a id='user-messages' href='{$bp_user_link}messages/'>Messages<span> $messages_count</span>
//print $messages_code;
$the_user_nav = ob_get_clean();
print str_replace('Profile</a></li>','Profile</a></li>'.$messages_code,str_replace('href="','href="'.$bp_user_link,$the_user_nav));
For the message count to be dynamically updated, the following html structure should be used since there is jquery that keeps the count updated:

<a id="user-messages">

<span><?php echo messages_get_unread_count(); ?></span>

Tuesday, 12 November 2013

PHP if alternative syntax


Monday, 11 November 2013

Disable selinux temporarily

sudo setenforce 0

To check the status of selinux:


Apache .htaccess directives not working

check the following settings in /etc/httpd/conf/httpd.conf


Apache location of configuration file in Fedora

The httpd.conf file is located in


Monday, 4 November 2013

Monday, 28 October 2013

Friday, 25 October 2013

Formatting a usb drive

sudo fdisk -l

to find all the filesystems and storage devices

sudo umount /dev/sdb1

to unmount the device sdb1

sudo mkfs.vfat /dev/sdb1

to format as fat 32

Thursday, 24 October 2013

Configuring yum to use a proxy


Monday, 21 October 2013

Tuesday, 1 October 2013

Voice Recording Software




International Standard Industrial Classification


An alternative is S&P's MSCI


Extend Office 2013 trial to 180 days

In the command prompt:

Go To:

 C:\Program Files\Common Files\Microsoft Shared\

or to (in case of 64 bit)

 C:\Program Files (x86)\Common Files\Microsoft Shared\


c:\Program Files\Microsoft Ofice\Office15



Configuring Remote Desktop XRDP


if it doesn't work, try


Saturday, 7 September 2013

Thursday, 5 September 2013

Godaddy subdomain on different server

A free open source project management application:


Mysql database and table character set


Counting the number of rows affected by Php Mysql PDO


Domain Transfer Procedure


StepLosing RegistrarCustomerGaining Registrar
1 Customer purchases a Domain Transfer 
Customer must unlock the domain and receive an Authorization Code from the Losing Registrar.Depending on your old registrar, you can do this via your control panel or by contacting support. 
3  Gaining Registrar sends an email to the Customer. This email contains an ID number, a Key Code, and a link to confirm the transfer.
4 Customer confirms the transfer with the ID and Key Code from the email. If the domain being transferred requires one, the Authorization Code from the Losing Registrar will also need to be entered. 
5  Gaining Registrar sends notification to the old registrar to transfer the domain.
6Losing registrar sends confirmation for release of domain.  
7 Customer confirms release with Losing Registrar. 
8Losing Registrar releases domain to Gaining Registrar.  
9  A "transfer success" email is sent to notify the customer that the domain is now located in their account.
10 Customer now has control over the domain at the new Registrar. 

ICANN Domain Transfers Policy

Google Docs vs Office 365

Creating text files in php

To open a port permanently in Fedora 19:

sudo firewall-cmd --zone=public --permanent --add-port=80/tcp

Check if port is open

To check if a port is open:


Making wordpress links relative

Add the following lines in the beginning of functions.php ( of your theme):

update_option('siteurl','http://' . $_SERVER['SERVER_ADDR']);
update_option('home','http://' . $_SERVER['SERVER_ADDR']);

More info:


CSS font stacks



Saturday, 31 August 2013

count returns the number of elements in an array. If mode is set to COUNT_RECURSIVE (or 1), count() will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array.


Will return the key of the searched value.

mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )

strict matches the type of the data also

Remove a single or multiple trailing or leading characters from a string using rtrim:

rtrim($string, ",") would cut trailing commas.
trim($string, ",") would cut trailing and prefixing commas.

Without the second argument rtrim will remove trailing and and trim will remove leading and trailing whitespace.

JQuery Source maps

JQuery Source maps allows javascript debugging even when using minified javascript.


@font-face kit generator

If font squirrel doesn't work (if the font is blacklisted, for example), you can use


Don't use http://convertfonts.com/

Wednesday, 28 August 2013

MySQL Varchar size limit is in bytes

When the length limit of a mysql field is specified, the limit is not on the number of characters but on the number of bytes. The Latin-1 character set takes one byte per character, the UTF-8 takes up to 3 characters.


PHP Functions optional parameters

In PHP, an optional parameter of a function can be defined by giving it a default value of null.

function some_function($optional=null) { }

Monday, 26 August 2013

Bulk Emailing using a PHP application http://swiftmailer.org/
IP Messenger for Linux: Iptux: https://github.com/iptux-src/iptux

Setting up a mail server in Linux




Tuesday, 20 August 2013

CMS Market Share

To set the time zone correctly before putting data into a database:



        $DBH = new PDO("mysql:host=hostedresource.com;dbname=somedb", "dbusername", "dbpassword");
    catch(PDOException $e)
        print "db error db_connection_10";
        file_put_contents('PDOErrors.txt', "\ntesting 10 " . $e->getMessage() . "\n", FILE_APPEND);       
    define('TIMEZONE', 'Asia/Kolkata');

    //SET time_zone='offset';
    $now = new DateTime();
    $mins = $now->getOffset() / 60;     // for India this will be +5.5hrs or +330 mins (Returns the timezone offset from GMT)
    $plus_or_minus = ( $mins < 0 ? -1 : 1 );     // find out if the country is behind or ahead
    $mins = abs( $mins );     // remove the sign
    $hrs = floor( $mins / 60 );     // floor just rounds down to the integer (so for India you will get 5 instead of 5.5)

    $mins = $mins - ( $hrs * 60 ); // this gives the minutes component of the timezone offset
    $offset = sprintf('%+d:%02d', $hrs*$plus_or_minus, $mins); // sprintf formats the string so that it can be used in the mysql command
    $DBH->exec("SET time_zone='$offset';");

Saturday, 17 August 2013

Installing MS Core Fonts in Fedora

Run the commands with sudo

cd /tmp
wget http://corefonts.sourceforge.net/msttcorefonts-2.5-1.spec
yum install rpm-build cabextract ttmkfdir
rpmbuild -bb msttcorefonts-2.5-1.spec
yum install /root/rpmbuild/RPMS/noarch/msttcorefonts-2.5-1.noarch.rpm

Then go to the home folder of root and execute the rpm.

Fedora 19 mate Subpixel font rendering

After enabling rpm fusion, install freetype-freeworld

Right click, the desktop,  go to Change Desktop Background and enable slight hinting and rgb antialiasing.

Iphone tester: http://iphonetester.com/

More emulators: http://www.webdesignerdepot.com/2012/11/6-free-mobile-device-emulators-for-testing-your-site/

Fedora 19: installing Apache, PHP, MySQL

In Yum Extender, select httpd, community-mysql-server, php, php-pecl-apc php-cli php-pear php-pdo php-mysqlnd  php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml, phpmyadmin

Run these commands after that:

service httpd start ## use restart after update

## Fedora ##
systemctl enable httpd.service

Then open port 80 to outside connections. Create a text file in /etc/sysconfig/iptables containing:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

service iptables restart

MySQL configuration:

systemctl start mysqld.service
systemctl enable mysqld.service
mysql -u root

set password for root@localhost=password('password');

set password for root@localhost=password('password');

#delete anonymous user
delete from mysql.user where user='';

Fedora Web Root Folder Permissions

You should add your account to the 'apache' group:

sudo usermod -a -G apache chetan

and then change the group for the /var/www/html folder to 'apache':

sudo chgrp -R apache /var/www/html
More info:

Tuesday, 6 August 2013

For IE 8 media queries support, use respond.js
It supports only min-width and max-width. The script tag should come after the link element
To check whether a phone number field is valid, use:

bool is_numeric ( mixed $var )

Note that leading '+' or '-' signs are allowed.

To replace all excess whitespace (new lines etc) use:

preg_replace("/\s+/", " ", $string);

To remove all leading and trailing spaces (but not extra spaces between words) use:

string trim ( string $str [, string $charlist = " \t\n\r\0\x0B" ] )

If you are using the "empty" function to detect blank fields, you must use trim to prevent spaces from being considered non-empty.
Linux: Check Ram Speed and Type
$ sudo dmidecode --type 17

Friday, 2 August 2013

To create a full window iframe:

<iframe src="" style="border: 0; position:absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%">
Get database field names:

while($row = $STH->fetch(PDO::FETCH_ASSOC))
$data[] = $row;
$colNames = array_keys(reset($data));
PHP: Create a downloading csv file

header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo "record1,record2,record3\n";

PHP: Return all the keys of an array or only keys containing a particular string or number.

array array_keys ( array $input [, mixed $search_value = NULL [, bool $strict = false ]] )

Add elements to the beginning of an array


HTML email

Info about initial-scal

  1. DO use the viewport meta tag
  2. DO use media queries to render your page appropriately for various widths ranging from under 200px to 1024px or more
  3. DO use width=device-width,initial-scale=1 in your viewport meta tag OR use width=device-width alone12.
  4. DO NOT use maximum-scale=1 or user-scalable=no
  5. DO NOT use width=<specific width>
  6. DO NOT use @media all and (*-device-width: xxx)
For mobile web sites, it is better to use em widths in your media queries. The advantage is the site will be compatible with different base font sizes or different zooms.

However, when a user zooms in or out, the page layout doesn't adjust automatically, the user has to refresh the page.

For media queries based on width to work on mobiles, you need to add the following meta tag to the html file:
<meta name="viewport" content="width=device-width">
In Internet Explorer 8, CSS adjacent sibling selectors don't work with javascript. Example, dynamically added classes in CSS selectors will be ignored by IE8.

Friday, 26 July 2013

To validate email addresses in PHP 5.2 and above:

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { // invalid emailaddress }
More info here: Stack Overflow
Note: Godaddy uses PHP 5.3
To create a new record in a mysql database:

INSERT INTO table_name VALUES (value1, value2, value3,...)
If one or more fields are auto update, put NULL in the values list.
Else, use this syntax
INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)
To submit a form using POST in jQuery (ajax), use the post method:
jQuery.post( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

In Javascript, to redirect the browser to another page:
window.location.href = "http://site.com/new_url";

Thursday, 25 July 2013

PHP Error Reporting

Put this code on the top of the php page to get error messages. Disable before going live.

error_reporting(E_ALL); ini_set('display_errors', '1');