tag:blogger.com,1999:blog-45580594450291382342024-03-08T06:50:47.147-08:00Share KnowledgeGreeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-4558059445029138234.post-42300235979370503852015-01-06T03:38:00.000-08:002015-01-06T03:38:11.248-08:00PHP: The Right Way<div dir="ltr" style="text-align: left;" trbidi="on">
There’s a lot of outdated information on the Web that leads new PHP users astray, propagating bad practices and insecure code. PHP: The Right Way is an easy-to-read, quick reference for PHP popular coding standards, links to authoritative tutorials around the Web and what the contributors consider to be best practices at the present time. Know where to find good information!
<br /><br />
<a href="http://www.phptherightway.com">
<img src="http://www.phptherightway.com/images/banners/lg-rect-386x280.png" alt="PHP: The Right Way"/>
</a>
</div>
Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-28422940734599365572015-01-02T01:35:00.000-08:002015-01-02T01:35:17.474-08:00Bookmarks for Javascript Timers<div dir="ltr" style="text-align: left;" trbidi="on">
Some useful bookmarks for JavaScript Timers: <br />
<br />
<a href="http://ejohn.org/blog/accuracy-of-javascript-time/">http://ejohn.org/blog/accuracy-of-javascript-time/</a> <br />
<a href="http://codingjohnson.com/javascript-precision-timing">http://codingjohnson.com/javascript-precision-timing</a><br />
<a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance">https://developer.mozilla.org/en-US/docs/Web/API/Performance</a></div>
Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-39389505763307286292013-06-13T21:54:00.000-07:002013-06-13T21:54:06.386-07:00Align image vertically middle<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<a name='more'></a>I'm here again after a long interval :)<br />
<br />
I can't stop to share this knowledge because I have been searching for long time to find a solution to this problem.<br />
<br />
I have faced many situations where I had to vertical align middle an image in a container. I had only 2 choices:<br />
<br />
1) Using a table as suggested here: <a href="http://css-tricks.com/snippets/css/absolute-center-vertical-horizontal-an-image/">http://css-tricks.com/snippets/css/absolute-center-vertical-horizontal-an-image/</a> which will increase the amount of HTML and in turn increase the size of the page and make the page load slow. This could be too expensive if we have many images to be placed like this in the same page.<br />
<br />
2) Set image as the background of the container like this:
<b></b>
<div style="background-image: url(img.jpg);">
</div>
<b>
</b> <br />
<span style="color: #3d85c6;"><div style="background-image:url(img.jpg)" ></div></span><br />
<div style="background-image: url(img.jpg);">
</div>
<b>
</b> <br />
and add the style<br /><br />
<div style="color: #3d85c6;">
<span class="cssPropName editable ">"background-position</span><span class="cssColon ">: </span><span class="cssPropValue editable ">50% center</span><span class="cssSemi ">;". </span></div><br />
<span class="cssSemi ">Since it is not a good practice to give inline style, this idea was also not good.</span><br />
<span class="cssSemi "><br /></span>
And finally, I found a better and easy solution to this problem :)<br />
<br />
<b>Solution:</b><br />
<br />
Set the <span style="color: #38761d;">height</span> and <span style="color: #38761d;">line-height </span>of the container to same value (the maximum possible height of the image). <br />
And add the style <span style="color: #38761d;">vertical-align: middle</span><b> </b>to the image.<br />
<br />
Eg:<br />
<br />
(Assume that image height will not increase 100px)<br />
<br />
<u><b>HTML</b></u>:<br />
<div style="color: #38761d;">
<div class="img_container">
<br />
<div class="img_container">
<div class="img_container"><br /> <img alt="image" src="img.jpg" /><br /></div></div>
</div>
</div>
<br />
<b><u>CSS</u></b>:<br />
<div style="color: #38761d;">
.img_container<br />
{<br />
height: 100px; // set height as the maximum possible height of the image<br />
line-height: 100px; // set line-height same as height<br />
}<br />
.img_container img<br />
{<br />
vertical-align: middle;<br />
}</div>
<br />
This worked for me like a charm.<br />
<br />
Idea reference: <a href="http://www.htmlforums.com/showpost.php?s=9ee122c4e95aff284a6da4fe681b4791&p=471958&postcount=2">http://www.htmlforums.com/showpost.php?s=9ee122c4e95aff284a6da4fe681b4791&p=471958&postcount=2</a><br />
<br />
Hope you enjoyed the post.<br />
Thanks for reading :)</div>
Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-47940305278607465322013-02-15T01:25:00.002-08:002013-02-15T01:25:39.328-08:00Function to get the last day (saturday) of current week<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
/**<br />
* Function to get the last day (saturday) of current week<br />
*<br />
* @return string<br />
*/<br />
function get_week_end_date()<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$format = 'M d, Y';<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// if today is saturday, return today's date<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (date('N') === 7)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return date($format);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// return next saturday's date<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return date($format, strtotime('next saturday'));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
}<br />
</div>
Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-25413581586760967952012-09-06T04:34:00.000-07:002012-09-06T04:34:11.207-07:00Get Days of the Week<div dir="ltr" style="text-align: left;" trbidi="on">
This function can be used to get the days of the week:<br />
<br />
<code>
function get_week_days()<br />{<br /> $timestamp = strtotime('monday this week');<br /> $week_days = array();<br /> for ($i = 1; $i <= 7; $i++)<br /> {<br /> $day = array();<br /> $day['name'] = strftime('%A', $timestamp);<br /> $day['short_name'] = strftime('%a', $timestamp);<br /> $week_days[$i] = $day;<br /> $timestamp = strtotime('+1 day', $timestamp);<br /> }<br /><br /> return $week_days;<br />}<br />
</code>
<br />
<br />
Output of this function will be:<br />
<br />
<pre style="color: #38761d;">Array
(
[1] => Array
(
[name] => Monday
[short_name] => Mon
)
[2] => Array
(
[name] => Tuesday
[short_name] => Tue
)
[3] => Array
(
[name] => Wednesday
[short_name] => Wed
)
[4] => Array
(
[name] => Thursday
[short_name] => Thu
)
[5] => Array
(
[name] => Friday
[short_name] => Fri
)
[6] => Array
(
[name] => Saturday
[short_name] => Sat
)
[7] => Array
(
[name] => Sunday
[short_name] => Sun
)
)</pre>
<pre style="color: #38761d;"> </pre>
<pre style="color: #38761d;"> </pre>
<div style="color: #38761d; text-align: left;">
<span style="color: black;">Hope this function will be useful to list the days of the week somewhere in your projects.</span></div>
<div style="color: #38761d; text-align: left;">
<span style="color: black;">Happy coding..:) </span> </div>
<div style="text-align: left;">
<br /></div>
</div>
Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-38867677753729200312012-04-16T02:27:00.004-07:002012-04-16T02:42:17.370-07:00Date Range Checking Using PHP<span style="font-weight: bold;">1)</span><br />/**<br /> * Function to check if a date is within a date range<br /> * Returns true if date falls within startDate and startDate<br /> *<br /> * @param timestamp $date<br /> * @param timestamp $startDate<br /> * @param timestamp $startDate<br /> *<br /> * @return boolean<br /> */<br /> public function isDateInRange($date, $startDate, $endDate)<br /> {<br /> return (($date >= $startDate) && ($date <= $endDate));<br /> }<br /><br /><span style="font-weight: bold;">2)</span><br /><br />/**<br /> * Function to check if a date range falls within another date range<br /> *<br /> * @param timestamp $startDate1 first date range startDate<br /> * @param timestamp $endDate1 first date range endDate<br /> * @param timestamp $startDate2 second date range startDate<br /> * @param timestamp $endDate2 second date range endDate<br /> *<br /> * @return boolean<br /> */<br /> public function isDateRangeInDateRange($startDate1, $endDate1, $startDate2, $endDate2)<br /> {<br /> return ($this->isDateInRange($startDate2, $startDate1, $endDate1) ||<br /> $this->isDateInRange($endDate2, $startDate1, $endDate1));<br /> }Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-35582820657934795252012-03-16T00:34:00.002-07:002012-03-16T00:42:14.703-07:00Get First and Last Date of the Current Week - The MySql Way<span style="font-weight: bold;">First Day of the Week</span><br /><br />SELECT DATE_ADD(current_date, INTERVAL(1-DAYOFWEEK(current_date)) DAY) FIRST_DAY_OF_WEEK;<br /><br /><span style="font-weight: bold;">Last Day of the Week</span><br /><br />SELECT DATE_ADD(current_date, INTERVAL(7-DAYOFWEEK(current_date)) DAY) LAST_DAY_OF_WEEK;Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-27779283997267808482011-06-06T22:54:00.000-07:002011-06-06T23:01:33.915-07:00URL RewritingFound a really nice and simple article on URL rewriting using .htaccess. Thought of sharing it :)<br />Here is it:-<br /><a href="http://www.sicanstudios.com/how-to-remove-php-html-htm-extensions-with-htaccess/">http://www.sicanstudios.com/how-to-remove-php-html-htm-extensions-with-htaccess/</a>Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com1tag:blogger.com,1999:blog-4558059445029138234.post-21722910124055251672011-01-10T02:42:00.000-08:002012-11-29T22:18:10.689-08:00How to check if script tags are entered in a field<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<span class="Apple-style-span"><i></i></span><br />
<div>
</div>
<span class="Apple-style-span"><i><code style="color: #38761d;"><div>
<span class="Apple-style-span" style="font-style: normal;"><span style="font-style: italic;">jQuery.validator.addMethod("disableScript", function(text, element) {</span><br /><span style="font-style: italic;">return (text.match(/\<\bscript\b/i) || text.match(/\<\/\bscript\b/i))?false:true;</span><br /><span style="font-style: italic;">}, "Script tags are not allowed");</span></span></div>
</code><div>
</div>
</i></span><br />
<br />
And how to use it?? It's very simple.<br />
<br />
Just add this method to the list of rules to validate the particular input field.<br />
<br />
Example:-<br />
<br />
<div style="color: #38761d;">
<span style="font-style: italic;">rules: {</span></div>
<div style="color: #38761d;">
<span style="font-style: italic;"> first_name: {required: true, disableScript: true},</span></div>
<div style="color: #38761d;">
<span style="font-style: italic;"> comment: {disableScript: true}</span></div>
<div style="color: #38761d;">
<span style="font-style: italic;">}</span></div>
<br />
Note:<br />
The JQuery validator plugin js file should be included in the page for this to work.</div>
</div>
Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-52856535045355888382010-11-09T00:49:00.000-08:002010-11-09T00:54:25.818-08:00How to reset a form using JQueryA little bit JQuery too..To reset the input field values of a form to its default values, the following code can be used. This is similar to using the reset button of HTML.<br /><br /><span style="font-style: italic; color: rgb(0, 102, 0);">$("form")[0].reset();</span>Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-72799804236429682912010-05-03T23:18:00.001-07:002010-05-20T22:33:13.451-07:00Regex negationWe can use <span style="color: rgb(0, 102, 0);">^[\/]*$</span> to match all strings that contain <span style="color: rgb(0, 102, 0);">"/"</span>.<br />Similarly, we can use <span style="color: rgb(0, 102, 0);">^[^\/]*$</span> to match all strings that do not contain <span style="color: rgb(0, 102, 0);">"/"</span>.<br />Notice the difference- We just need to add a <span style="color: rgb(0, 102, 0);">^</span> at the starting of the pattern inside the brackets.<br /><br />To check for either / or \, the regex <span style="color: rgb(0, 102, 0);">^[^\/|\\\\]*$ <span style="color: rgb(0, 0, 0);">can be used.</span></span> This will negate both / and \.<br /><br />For more information on regex:-<br /><br /><a href="http://weblogtoolscollection.com/regex/regex.php">http://weblogtoolscollection.com/regex/regex.php</a><br /><a href="http://www.zytrax.com/tech/web/regex.htm">http://www.zytrax.com/tech/web/regex.htm</a>Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-21420733806311419702010-05-03T05:14:00.000-07:002010-05-06T23:29:15.000-07:00Alphanumeric validation in Cake PHP not working in CentOSToday we got a bug.<br />Alphanumeric checking for first and last name fields were not working in the server and in my team member's systems. But it was working without in fault in my local system. Finally our team lead found the cause for the problem and fixed it.<br /><br />Any guess what the problem was..<br /><br />It was because of the operating system they had. They had Centos, and mine was Ubuntu. The version of centos that they had, doesn't support alphanumeric validation.<br /><br />And the fixed code is:-<br /><span style="color: rgb(0, 102, 0); font-style: italic;">var $validate = array(</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> 'first_name' => array(</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> 'notEmpty' => array(</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> 'rule' => 'notEmpty',</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> 'message' => 'First Name cannot be left blank',</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> 'last' => true ),</span><br /> <br /><span style="color: rgb(0, 102, 0); font-style: italic;"> 'alphanumeric' => array(</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> 'rule' => array('custom', '/^[a-z0-9]*$/i'), //this is the solved portion</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> 'message' => 'First Name must only contain letters and numbers' ),</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> )</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;">);</span>Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-18719711686219079522010-05-03T02:46:00.001-07:002010-05-03T04:33:18.854-07:00Cake PHP Pagination - SEO friendly URLToday I was searching for SEO friendly Cake PHP Pagination URL.<br />I found the following link:-<br /><a href="http://www.sakic.net/blog/changing-cakephp-pagination-urls">http://www.sakic.net/blog/changing-cakephp-pagination-urls</a><br /><br />But there was not much explanation about handling sort and pagination numbers.<br />I tried some modifications of the code given, and finally........ I got it!<br /><br />Here's it:-<br /><span style="color: rgb(51, 0, 153);"><br />Controller-</span><br /><br />Before cleaning URL:-<br /><span style="color: rgb(0, 102, 0); font-style: italic;">function index() {</span> <span style="color: rgb(0, 102, 0); font-style: italic;"><br />$data = $this->paginate('User'); // User is the model name</span> <span style="color: rgb(0, 102, 0); font-style: italic;"><br />$this->set('data', $data);</span> <span style="color: rgb(0, 102, 0); font-style: italic;"><br />}</span><br /><br />After cleaning URL:-<br /><span style="color: rgb(0, 102, 0); font-style: italic;">function index($page='', $sort='', $dir = '') {</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;">if (is_numeric($page)) {<br /> </span> <span style="color: rgb(0, 102, 0); font-style: italic;"> $this->passedArgs['page'] = $page;</span> <span style="color: rgb(0, 102, 0); font-style: italic;"><br />$this->passedArgs['sort'] = $sort;</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;">$this->passedArgs['direction'] = $dir;</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> }</span> <span style="color: rgb(0, 102, 0); font-style: italic;"><br />$data = $this->paginate('User'); // User is the model name</span> <span style="color: rgb(0, 102, 0); font-style: italic;"><br />$this->set('data', $data);</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;">}</span><br /><br /><br /><span style="color: rgb(51, 0, 153);">View-</span><br /><br />Before cleaning URL:-<br /><span style="font-style: italic; color: rgb(0, 102, 0);">echo $paginator->sort('First name', 'first_name', array('class'=> $paginator->sortDir())) </span><span style="color: rgb(0, 153, 0);">//sort</span><br /><span style="font-style: italic; color: rgb(0, 102, 0);">if ($paginator->counter('%pages%') > 1):</span><br /><span style="font-style: italic; color: rgb(0, 102, 0);"> echo $paginator->numbers();</span><br /><span style="font-style: italic; color: rgb(0, 102, 0);">echo $paginator->prev('previous', null, null, array('class' => 'disabled'));</span><previous'); echo=""><next');><br /><span style="font-style: italic; color: rgb(0, 102, 0);">echo $paginator->next('next', null, null, array('class' => 'disabled'));</span><br /><span style="font-style: italic; color: rgb(0, 102, 0);">endif;</span><br /><br />After cleaning URL:-<br /> <br /> <span style="color: rgb(0, 102, 0); font-style: italic;"> $replace_arr = array("page:", "sort:", "direction:"); // strings to be replaced from the pagination links<br /><br /></span><span style="color: rgb(0, 102, 0); font-style: italic;"> echo str_replace($replace_arr, '', $paginator->sort('First Name', 'first_name', array('class'=> $paginator->sortDir()))); //sort </span><br /><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> if ($paginator->counter('%pages%') > 1): </span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> $prev_link = str_replace($replace_arr, '', $paginator->prev('previous', null, null, array('class' => 'disabled')));</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> $prev_link = preg_replace('/\/1"/', '"', $prev_link);</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> $next_link = str_replace($replace_arr, '', $paginator->next('next', null, null, array('class' => 'disabled')));</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> echo preg_replace('/\/1"/', '"', str_replace($replace_arr, '',$paginator->numbers()));</span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> echo $prev_link; </span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> echo $next_link; </span><br /><span style="color: rgb(0, 102, 0); font-style: italic;"> endif; </span><br /></next');></previous');>Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com0tag:blogger.com,1999:blog-4558059445029138234.post-40351570987689270592010-05-03T01:01:00.000-07:002010-05-06T22:32:42.659-07:00About My BlogHi Viewers,<br /><br />I was thinking of a blog where I can share my knowledge.<br /><br />What can we loose by sharing the knowledge that we have..? Nothing at all...<br />After long hours of searching and thinking, when I find a solution to a problem, I think of sharing it.<br />Now I can't wait any more..<br /><br />Since I'm a PHP programmer, I'll be focusing in that area. Anyone who is interested in PHP, is welcome.<br />This is my first blog. So please support..Greeshma A. R.http://www.blogger.com/profile/04907293622679560321noreply@blogger.com6