How to Show hide content using core JavaScript ?

Today I was working on another website and had very long text/content and thought to use Jquery, there are several examples given on internet. I tried to use some of them of course they are very simple but because of some reason it didn’t work for me either in IE and chrome.
So decided to compile my own show hide JavaScript which is based on DOM!
Here is very simple code and it works everywhere, Firefox, Internet Explorer, Chrome, Safari etc.

Steps are self explanatory.
A. Use JavaScript code
B. Use Css Class
C. See the example and compile your own!




This is first paragraph of my big content. Click to See more.

Here is your hidden text which you want to hide!! Copy your text here!

Click to hide this content.

Share

How to upgrade Drupal ?

Drupal is always releasing security updates every now and then.
PHP communality called it patches!
So here are the steps you can use to patch your Drupal and lock down security hole in Drupal web application.
1. Download latest release of Drupal package from Drupal site.
2. Put your PHP Drupal site in maintenance mode (offline)
3. Take a database backup/export using any MYSQL tools, like phpmyadmin (I use it in MAMP environment ). Same thing you can do by command line if you want to do so.
(mysql –u ROOT –p YOURPASSWORD yourdatabasename > exporteddbname.sql)
4. Make backup of your Drupal application folder.
5. Now it is time to copy all files – untar or unzip your downloaded new Drupal patch package.
6. Copy all files and folders Except “Site folder”, “.htaccess” file and “robot.txt”, you can have custom configuration and setting to these files and folder so it is good not to overwrite these files and folder.


7. Run CRON in your Drupal application.
8. Run update.php it will detect automatically type of database and schema you are using and update it. It takes few seconds, so please don’t halt upgrading process.
http://localhost/drupal/update.php
9. If above process is successful, put back your site in (Online mode) live mode.
10. See status report and you will notice your Drupal is updated.

Your Drupal application is safe now !

Share

What is difference between setInterval () and setTimeout () ?

setTimeout execute javascript statement AFTER x interval.
For example – setTimeout(“execute_something();”, 2000);
This is execute function execute_something() after 2 seconds.

setInterval execute javascript statement EVERY x interval.
For example – setInterval(“execute_something();”, 2000);
This is execute function execute_something() in every 2 seconds.

Share

How to use Firebug within Google Chrome?

Google Chrome does not support plug-ins, there is Firebug-like too already available built within Google Chrome. That is called “Inspect element” just right click on page anywhere and click on “Inspect element” menu command. It will open a new panel like firebug. It works well for CSS debugging and you can change CSS in real time like firebug but JavaScript debugging is not very good supported.

Share

How to change date formate of twitter field “created_at”?

php coder who is reading twitter API for latest tweets want to change date/ timestamp format which is returned by ‘created_at’ key. Most of the times I use JSON based request. e. i. http://search.twitter.com/search.json?q=phpmind

These are the fields returned by above request.

Hope fully you understand how json string looks like.

Now it is time to convert date time stamp in more readable format.

echo date("l M j \- g:ia",strtotime($object->returns[0]->created_at));

Please change the date parameters if you want to play with different date formats.

If you want to use javaScript way to format dates here is very cool function.
Returned by twitter – Wed, 09 Feb 2011 02:44:36 +0000

Returned by this javaScript function, TwitterDateConverter ($object->returns[0]->created_at);
Output will be for Example “14 minutes ago”

See Image Below!


function Convert_Datetime($datetime)
{
    define("SECOND", 1);
    define("MINUTE", 60 * SECOND);
    define("HOUR", 60 * MINUTE); define("DAY", 24 * HOUR);
    define("MONTH", 30 * DAY); $delta = time() - strtotime($datetime);

    // convert

    if($delta < 1 * MINUTE)
    {
        return $delta == 1 ? "one second ago" : $delta." seconds ago";
    }
    if($delta < 2 * MINUTE)
    { return "a minute ago";
    }
    if($delta < 45 * MINUTE)
    {
        return floor($delta / MINUTE)." minutes ago";
    }
    if($delta < 90 * MINUTE)
    {
        return "an hour ago";
    }
    if($delta < 24 * HOUR)
    {
        return floor($delta / HOUR)." hours ago";
    }
    if($delta < 48 * HOUR)
    {
        return "yesterday";
    }
    if($delta < 30 * DAY)
    {
        return floor($delta / DAY)." days ago";
    }
    if($delta < 12 * MONTH)
    {
        $months = floor($delta / DAY / 30); return $months <= 1 ? "one month ago" : $months." months ago"; }
    else
    {
        $years = floor($delta / DAY / 365); return $years <= 1 ? "one year ago" : $years." years ago";
    }

echo Convert_Datetime("2015-04-1 22:10:00"); // one year ago

Share

How to auto refresh a page through JavaScript?

Here is the small JavaScript example that tells how you can use setTimeout() to auto refresh page content. You can utilize this script in games site or stock sites or anywhere you can think of.




PHPMIND – Javascript Tutorials



JavaScript Auto Refresh Page

This code will refresh you page in 6 seconds. We have used OnLoad() Event function to call our function. Note : Please don’t use a lot of auto refresh page because it is kind of annoying and your sever bandwidth will be decreasing, one way you are increasing hits to server.

Share

How to Enable CURL in WAMP?

CURL is not enabled by default in WAMP. Every php programmer have to use CURL to make remote connection.

The steps are as follows :

1) Close WAMP (if running)
2) Navigate to WAMP\bin\php\(your version of php)\
3) edit php.ini
4) Search for curl, uncomment extension=php_curl.dll
5) Navigate to WAMP\bin\Apache\(your version of apache)\bin\
6) edit php.ini
7) Search for curl, uncomment extension=php_curl.dll
8 ) Save both
9) Restart WAMP

That will solve your Curl issues.
Enjoy!

Share

Perl Interview Questions?

What is use of ‘strict’ in perl ?
The module strict restricts ‘unsafe constructs’, according to the perldocs
When you enable the strict module, the three things that Perl becomes strict about are:
• Variables ‘vars’
• References ‘refs’
• Subroutines ‘subs’
Strict variables are useful. Essentially, this means that all variables must be declared, that is defined before use. Furthermore, each variable must be defined with my or fully qualified

What is scalars in perl ?
The most basic kind of variable in Perl is the scalar variable. Scalar variables hold both strings and numbers, and are remarkable in that strings and numbers are completely interchangable. For example, the statement
$priority = 9;
sets the scalar variable $priority to 9, but you can also assign a string to exactly the same variable:
$priority = ‘high’

Perl difference between lists and arrays ?
A list is a fixed collection of scalars. An array is a variable that holds a variable collection of scalars.
Array operations, which change the scalars, reaaranges them, or adds or subtracts some scalars, only work on arrays. These can’t work on a list, which is fixed. Array operations include shift, unshift, push, pop, and splice.
You can change an array element, but you can’t change a list element.

What is the use of ‘defined’?
defined EXPR
defined

Returns true if EXPR has a value other than the undef value, or checks the value of $_ if EXPR is not specified.
If EXPR is a function or function reference, then it returns true if the function has been defined.

Return Value
• 0 if EXPR contains undef
• 1 if EXPR contains a valid value or reference

#!/usr/bin/perl
$var1 = "This is defined";
if( defined($var1) ){
  print "$var1\n";
}
if( defined($var2) ){
  print "var2 is also defined\n";
}else{
  print "var2 is not defined\n";
}
This will produce following result
This is defined
var2 is not defined
Share