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

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
IP Messenger for Linux: 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(";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
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:

More emulators:

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.