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.