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() 
{
    $activityDate=bp_get_activity_date_recorded();
    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

http://sltaylor.co.uk/blog/customizing-new-user-email-pluggable-function/

http://codex.wordpress.org/Pluggable_Functions

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.

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

Using at and crontab

http://www.cyberciti.biz/tips/howto-shutdown-linux-box-automatically.html

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

http://www.stringcat.com/company_blog/2012/10/13/complete-php-low-level-mailer-script-with-to-replyto-cc-bcc-and-attachments/

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

change

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

to

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

Thursday, 21 November 2013

The buddypress bp global object

http://codex.buddypress.org/developer/the-bp-global/

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

http://en.wikipedia.org/wiki/Solution_selling

Running an Android VM in Linux

http://www.cnx-software.com/2013/03/01/how-to-run-android-apps-in-linux-with-androvm/

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:

http://www.microsoft.com/en-in/download/details.aspx?id=15011

Cloning a disk on Linux

https://wiki.archlinux.org/index.php/Disk_Cloning

Create a tar archive preserving all attributes

tar --selinux --acls --xattrs  -cvf file.tar /var/www
 
http://www.cyberciti.biz/faq/linux-tar-rsync-preserving-acls-selinux-contexts/ 

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

http://stackoverflow.com/questions/984204/shell-command-to-tar-directory-excluding-certain-files-folders

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

http://www.davidjrush.com/blog/2012/09/renaming-your-wordpress-theme/

PHP: put printed data into a variable

http://stackoverflow.com/questions/4798142/php-capture-print-require-output-in-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:

bp_get_displayed_user_nav();

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();
  ob_start();
 bp_get_displayed_user_nav();
 $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

<span>$messages_count</span>
</a></li>\n\n"


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 

<span>$messages_count</span>
</a></li>\n\n";

      $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
      ob_start();
      bp_get_displayed_user_nav();
      $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]";
ob_start();
bp_get_displayed_user_nav();
$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 http://192.168.42.20/members/, 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>
</a></li>\n\n";
//print $messages_code;
ob_start();
bp_get_displayed_user_nav();
$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));
}
else
{
bp_get_displayed_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>
</a>

Tuesday, 12 November 2013

PHP if alternative syntax

http://php.net/manual/en/control-structures.alternative-syntax.php

Monday, 11 November 2013

Disable selinux temporarily

sudo setenforce 0

To check the status of selinux:

/usr/sbin/getenforce


Apache .htaccess directives not working

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

http://httpd.apache.org/docs/current/mod/core.html#allowoverride

Apache location of configuration file in Fedora

The httpd.conf file is located in

/etc/httpd/conf

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

http://docs.fedoraproject.org/en-US/Fedora_Core/5/html/Software_Management_Guide/sn-yum-proxy-server.html

Monday, 21 October 2013

Tuesday, 1 October 2013

Voice Recording Software

http://www.abyssmedia.com/mcrs/

http://www.voicetronix.com/logger.htm

http://en.wikipedia.org/wiki/Call-recording_software

International Standard Industrial Classification

http://unstats.un.org/unsd/cr/registry/isic-4.asp

An alternative is S&P's MSCI

http://www.msci.com/resources/pdfs/MK-GICS-DIR-3-02.pdf

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\

or

c:\Program Files\Microsoft Ofice\Office15


Then run OSPPREARM.EXE

http://www.howtogeek.com/148347/how-to-extend-your-office-2013365-trial-to-180-days/

Configuring Remote Desktop XRDP

http://sigkillit.com/category/linux/fedora-18/

if it doesn't work, try

https://mknowles.com.au/wordpress/2013/02/15/installing-xrdp-on-fedora-18-with-mate-desktop/

Saturday, 7 September 2013

Thursday, 5 September 2013

Godaddy subdomain on different server

http://support.godaddy.com/groups/domains-management-and-services/forum/topic/external-dns-subdomain-linked-to-my-gd-hosting/?pc_split_value=1
A free open source project management application:

http://www.projectforge.org

Mysql database and table character set

http://stackoverflow.com/questions/367711/what-is-the-best-collation-to-use-for-mysql-with-php

Counting the number of rows affected by Php Mysql PDO

http://stackoverflow.com/questions/883365/count-with-pdo

Domain Transfer Procedure

http://www.quackit.com/domain-names/how_to_transfer_a_domain_name.cfm

StepLosing RegistrarCustomerGaining Registrar
1 Customer purchases a Domain Transfer 
2
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

http://archive.icann.org/en/transfers/policy-12jul04.htm
Google Docs vs Office 365

http://www.techrepublic.com/blog/the-enterprise-cloud/google-apps-v-office-365-head-to-head-comparison-of-features/
Creating text files in php

http://www.latestcode.net/2010/03/how-to-create-text-file-in-php.html
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:

http://www.yougetsignal.com/tools/open-ports/

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:

http://codex.wordpress.org/Changing_The_Site_URL

CSS font stacks

http://cssfontstack.com/

http://gbtech.wordpress.com/2007/06/28/web-safe-font-list/

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.

count($var)

http://www.php.net/manual/en/function.count.php
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


http://php.net/manual/en/function.array-search.php
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.

http://jquerybyexample.blogspot.com/2013/01/all-you-need-to-know-about-jquery-source-maps.html

@font-face kit generator

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

http://www.font2web.com/

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.


http://stackoverflow.com/questions/1592702/mysql-varchar-size-limit

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

http://rimuhosting.com/support/settingupemail.jsp?mta=postfix

http://en.kioskea.net/contents/300-intranet-installing-a-mail-server

http://ithelpblog.com/os/linux/redhat/fedora/howto-install-and-configure-postfix-mail-server-on-fedora-18/

Tuesday, 20 August 2013

CMS Market Share

http://trends.builtwith.com/cms
To set the time zone correctly before putting data into a database:

http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/

http://www.php.net/manual/en/timezones.asia.php


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

   
    //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:
http://www.rackspace.com/knowledge_center/article/how-to-add-linux-user-with-document-root-permissions

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
https://github.com/scottjehl/Respond
To check whether a phone number field is valid, use:


bool is_numeric ( mixed $var )

Note that leading '+' or '-' signs are allowed.
http://php.net/manual/en/function.is-numeric.php

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.
http://in3.php.net/manual/en/function.empty.php
Linux: Check Ram Speed and Type
$ sudo dmidecode --type 17

Friday, 2 August 2013

To create a full window iframe:

<iframe src="http://192.168.0.1/login.php" 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";


http://stackoverflow.com/questions/217424/create-a-csv-file-for-a-user-in-php
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 ]] )

http://php.net/manual/en/function.array-keys.php
Add elements to the beginning of an array

http://php.net/manual/en/function.array-unshift.php

HTML email

Info about initial-scal

http://tech.bluesmoon.info/2011/01/device-width-and-how-not-to-hate-your.html
  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 ] )

http://api.jquery.com/jQuery.post/
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');