WordPress LTR/RTL

Hello,

I found your website on a WordPress forum. Currently I am rebuilding a website in wordpress that is in English and Farsi. I am using the Qtranslate and a theme called suffusion which supports RTL. The theme does come a rtl.css which moves everything to the right which is great. The problem I am having is switching from my LTR Style Sheet to RTL stylesheet when the language is switched. If you could be of any assistance on this it would be greatly appreciated.

Thank You – Chris

Continue reading “WordPress LTR/RTL”

PHP with IMAP on CentOS

I was playing with Drupal 6 and some UberCart ticket module when I came across an error message where Drupal told me that it needed the IMAP PHP extension to be installed.

Because I’m a nice guy I will share this command with you:

[me@it ~]# yum install php-imap

Now it’s installed, proof:

[me@it ~]# php --ri imap

imap

IMAP c-Client Version => 2004
SSL Support => enabled
Kerberos Support => enabled
[me@it ~]#

If it wasn’t installed it would have shown you:

[me@it ~]# php --ri imap
Extension 'imap' not present.

But of course it isn’t working… yet, untill you restart the Apache server daemon

[me@it ~]# service httpd restart

And because I’m a nice guy I will tell you where I found the first command before even you ask: http://www.php.net/manual/en/imap.setup.php

The PHP manual is always a good place to start, oh… and don’t underestimate comments.

Error writing the value’s new contents (Windows Registry Editor)

I got this error when trying to change some configuration settings for my anti-virus (TrendMicro WFBS on Windows Server 2003)

'Cannot edit LocalServerPort:
Error writing the value's new contents'

As usual, when something I don’t like happens on my computer or on other parts of my life, I ask my friend Google about it, the suggested solutions were :

  • Open the Registry Editor using the command “Regedt32.exe”
  • Set or review permissions (Edit->Permissions…)

Of course none of these worked for me, all I had to do is to close the anti-virus program, or to be more specific unload server/client security agent (lol).

I’m not much on Windows, so I can’t explain that behavior, if you know something about it, please share it on the comments section, I will be very pleased to add it here on this very same post.

Get current URL in PHP

Here is a function for getting the URL of the page being processed in PHP, the function accepts one optional parameter $ignore_port_80 (boolean) to tell it whether it should ignore the port part of the url if the port used is 80:

# Function
function get_current_url($ignore_port_80 = true) {
  $is_https = $_SERVER['HTTPS'] === 'on';
  $show_port = $_SERVER['SERVER_PORT'] !== '80' || !$ignore_port_80;

  $url = ''
    . 'http'
    . ($is_https ? 's' : '')
    . '://'
    . $_SERVER['SERVER_NAME']
    . ($show_port ? (':'.$_SERVER['SERVER_PORT']) : '')
    . $_SERVER['REQUEST_URI'];
  return $url;
}

# Examples
echo get_current_url();       # http://kadimi.com/en/some-title-123
echo get_current_url(true);   # same as above
echo get_current_url(false);  # http://kadimi.com:80/en/some-title-123

vsftpd: 500 OOPS: unrecognised variable in config file

Question

When I start vsftpd on my CentOs machine I get this error:

Starting vsftpd for vsftpd: 500 OOPS: unrecognised variable in config file:  anonymous_enable

How can I fix it?

Answer

The option “anonymous_enable” is a valid vsftpd option, but as you can see on the error message, there is an extra white space before the variable definition, I suspect that the line was there, commented, and that when you uncommented it you forgot to remove the white space after the “#”, check your vsftpd.conf file make sure that “anonymous_enable=YES” or “anonymous_enable=NO” stands on a single line without any preceding spaces then start vsftpd:

service vsftpd start

MySQL statement terminators

There is the semicolon “;” that every one knows, and “g” which is just the same:

mysql > SELECT * FROM wp_links;
mysql > SELECT * FROM wp_links\g

Those are exactly the same, and will produce the same result, here is an example:

mysql> select * from wp_links \g
+---------+-----------------------+--------------+------------+-------------+---------------+------------------+--------------+------------+-------------+---------------------+----------+------------+-----------------------+
| link_id | link_url              | link_name    | link_image | link_target | link_category | link_description | link_visible | link_owner | link_rating | link_updated        | link_rel | link_notes | link_rss              |
+---------+-----------------------+--------------+------------+-------------+---------------+------------------+--------------+------------+-------------+---------------------+----------+------------+-----------------------+
|       1 | http://www.ar-wp.com/ | WP arabic    |            |             |             0 |                  | Y            |          1 |           0 | 0000-00-00 00:00:00 |          |            | http://www.ar-wp.com/ |
+---------+-----------------------+--------------+------------+-------------+---------------+------------------+--------------+------------+-------------+---------------------+----------+------------+-----------------------+
1 row in set (0.01 sec)

\G is another valid statement terminator, it tells MySQL to produce vertical output, this comes in handy when the result has too much columns, here is the same statement again but with the \G terminator:

mysql> select * from wp_links\G
*************************** 1. row ***************************
link_id: 1
link_url: http://www.ar-wp.com/
link_name: WP arabic
link_image:
link_target:
link_category: 0
link_description:
link_visible: Y
link_owner: 1
link_rating: 0
link_updated: 0000-00-00 00:00:00
link_rel:
link_notes:
link_rss: http://www.ar-wp.com/
1 row in set (0.00 sec)

As you can see this is a more user friendly fashion for displaying data.

Install Symfony Without PEAR

A lot of web hosts have limited or nonexistent support for PEAR, the pear command will throw errors on most commands or not work at all, in order to install Symfony on such hosts you will need to download the Symfony package, copy Symfony files to your home directory and make them easily accessible from PHP scripts by modifying the include_path directive setting.

In order to complete these steps faster, we will prefer using SSH to download or edit files and to create folder instead of using FTP, FTP will take a lot of time compared to SSH… Let’s start.

1 – Download and Install Symfony

Login to your account using SSH, if you are already logged in make sure your current working directory is your home directory (~), then create a “php” folder where you will download the symfony package, we will use the same directory structure used on the Symfony documentation, this will allow you to follow the documentation examples without changing directory names etc.

Before issuing the following commands, grab the link of the latest symfony version from Symfony website, for the purposes of this tutorial you will have to download the  source .tgz file, the text  written in red font will be different depending on the Symfony version:

you@yourdomain.com [/tmp]# cd
you@yourdomain.com [~]# mkdir php
you@yourdomain.com [~]# mkdir php/lib
you@yourdomain.com [~]# mkdir php/lib/vendor
you@yourdomain.com [~]# cd php/lib/vendor
you@yourdomain.com [~/vendor]# wget http://www.symfony-project.org/get/symfony-1.4.1.tgz
--06:15:44-- http://www.symfony-project.org/get/symfony-1.4.1.tgz
=> `symfony-1.4.1.tgz.2'
Resolving www.symfony-project.org... 217.174.222.79
Connecting to www.symfony-project.org|217.174.222.79|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3,210,838 (3.1M) [application/x-gzip]100%[===================================================================>] 3,210,838 1.34M/s
06:15:48 (1.34 MB/s) - `symfony-1.4.1.tgz.2' saved [3210838/3210838]
you@yourdomain.com [~/vendor]# tar zxpf symfony-1.4.1.tgz
you@yourdomain.com [~/vendor]# mv symfony-1.4.1 symfony
you@yourdomain.com [~/vendor]# rm -fr symfony-*

2 – Test your Symfony installation

You can test your installation and display the symfony version:

you@yourdomain.com [~]# php -q  php/lib/vendor/symfony/data/bin/symfony -V
symfony version 1.4.1 (/home/you/php/lib/vendor/symfony/lib)

3 – Tell PHP where to find Symfony files

Symfony files are now available in your server, but you still need to tell php where to find them easily. For that you need to modify your PHP include_path and add the “php” folder.

We need to know the php folder absolute path, for this we will “cd” to the “php” directory and issue the “pwd” command:

you@yourdomain.com [~]# cd ~/php
you@yourdomain.com [~]# pwd
/home3/you/php

-or-

you@yourdomain.com [~]# find ~/php -name php
/home3/you/php

There are different solutions for altering your PHP include_path, you will choose the one that meets your needs.
[See: How to modify PHP include_path]

In this tutorial, I will assume that you are relying on a global php.ini file .

Open you php.ini file for edit

you@yourdomain.com [~]# nano /x/y/z/php.ini

Look for the include_path directive setting, something like this:

include_path = ".:/usr/lib/php:/usr/local/lib/php"

you can find it easily by using nano’s search featrure:

  • Press CTRL+W
  • Type the search string and press RETURN, we are interested in the string include_path
  • Press CTRL+W then RETURN until you find something that resembles the code above.

Add the php absolute path to your php include_path like this

include_path = ".:/usr/lib/php:/usr/local/lib/php:/home3/you/php"

Conclusion

At this point you can use symphony almost as if you installed it using the PEAR pear command. You can use the same method to install other PEAR packages. One more thing you can do is to alter your shell PATH to add the symfony command:

Open .bash_profile add the following line AT THE END OF THE FILE:

PATH=$PATH:$HOME/php/lib/vendor/symfony/data/bin/
export PATH

Firefox crashes: How to detect bogus extensions

Today, whenever I used the built in Firefox search function and as soon as I typed the first letter of my phrase, Firefox suddenly crashed and displayed the well known Mozilla Crash Reporter window (image below).

Mozilla Crash Reporter

Sending a crash report to complain about my issue won’t help me (specially), and won’t help Mozilla people too much, unless they know more about my system (OS, FF version, installed extensions, latest visited websites), so I’d better try to solve this issue by myself.

1st try

I restarted Firefox, it still crashes when i type the first letter of my search string…

2nd try

I rebooted my computer… I wasted 2 minutes for nothing.

3rd try

I scanned my computer using Avira Antivir Personal, nothing found as usual.

4th try, what I should have done from the beginning

I started firefox in safe mode and disabled all installed extensions (more than 15).
By the way, the command for starting Firefox in safe mode is:

firefox -safe-mode

Guess what, it worked now, I can use the search function again, but all my extensions are disabled, I enabled them 3 or 4 at a time, restarted Firefox, and tested the search function at each time until I spotted the bogus extensions which was nothing but YSlow 2.0.5.

So what?

Now I can send a descent report to Mozilla and be helpful, I will have to wait until YSlow is updated again or I will install the extension Google Speed which is very similar and even better than YSlow IMO.

Detect WordPress version

How can I detect the current WordPress version?

Log in to your admin Dashboard and scroll to the bottom of the page, you’ll find your version number on the rightmost spot of the footer.

WordPress version

Or you can view the source of one of the pages of your blog and look for the meta generator tag:

<meta name="generator" content="WordPress 2.9.1" />

WordPress upgrade error (Allowed memory size of 33554432 bytes exhausted)

The problem

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2516315 bytes) in /home/mydomain/public_html/blog/wp-includes/http.php on line 1370

This can happen at any line and with any file, not only http.php at line 1370!

Explanation

Don’t worry if you get this error, there is nothing wrong with your server or hosting plan etc. Whenever a new version of WordPress is released, new features are added, thus more calculations, so logically more memory is needed.
In older versions of WordPress (before 2.7… I think), the memory limit was set to 32M, if you are upgrading WordPress, you will probably get that error, you will have to edit the wp-settings.php file and set (I should say change) the constant WP_MEMORY_LIMIT value to 64M, giving PHP more memory to play with.

The solution

  • Open the remote file wp-settings.php file located on the base directory where you installed your WP blog
  • find this code (probably at line 13)

    define('WP_MEMORY_LIMIT', '32M');

  • Replace with

    define('WP_MEMORY_LIMIT', '64M');

  • Run the upgrade process again
  • Enjoy your updated WP blog

Opera: CSS rotation and other transformations

After the release of Opera 10.5 Alpha, it’s now be possible to rotate elements, this new release includes support for CSS3 rotation and other transitions and transforms, we may not longer need JavaScript for some basic transformations, have a taste:

The demonstration doesn’t show rotation, so the CSS for rotation under Opera is:

-o-transform:rotate(90deg);

FYI

When you install Opera 10.5 Alpha, your previous installation of Opera (Stable) is not removed, giving you the chance to test and compare…

Read

Find more about Crossbrowser CSS rotation at hakoniemi’s blog.

Clear Firefox cache – the fastest way

Firefox creators made things really user friendly IMO

You can clear Firefox cache by following these three steps:

  1. Press Ctrl+Shift+Del
  2. Choose the time range and tick the part of your history you wanna get rid of (Browsing and Download History, Forms & Search Data, etc…), you may need to click the arrow to show those details
  3. Click “Clear Now”

After doing your first experiment, you will see that it takes only a few seconds to clear firefox cache.

Firefox clear cache

JavaScript Tween function

This is a small library I wrote for creating simple and complicated easing effects without using JQuery, MooTools or other JS libraries.

The library is small 13.4 KB or 5.6 KB compressed,

The function can be called as follows:

tween(element, property, from, to, duration, [optional] function)

Parameters

element: The id  of the HTML element you want to animate like  “my_div”, “left_sidebar”, DOM objects are also accepted

property: The CSS property that you want to animate like “color”, background-color”, “left”, “margin-top”…

from: The initial value, like 0px, top, none, 0.5…

to: The final value

duration: the animation duration in ms

function (optional): the easing function to use, by default the tween function uses the linear tween, there are nine other functions included (easeInBack, easeOutBack, easeInOutBack, easeInCirc, easeOutCirc, easeInOutCirc, easeInBounce, easeOutBounce & easeInOutBounce)

Examples

Demos available here

Minified version

Function available here

Full version

var fps = 40;
var debugging = 0;
var tw = [];
var rand_str = generatePassword();
var float_pcre = new RegExp("(\+|-)?(\d*\.)?\d+", 'g');
var color_at_end = new RegExp("[Cc]olor$");

function tween(element, property, from, to, duration) {

    if (arguments.length = 0.75) {
        for (var i = 0; i < tw.length; ++i) {
            if (tw[i]["status"] === "playing") break;
            if (i == tw.length - 1) {
                tw = [];
            }
        }
    }

    var tw_id = tw.length;
    tw[tw_id] = [];
    tw[tw_id]["f"] = (Boolean(arguments[5])) ? arguments[5] : "linear";
    tw[tw_id]["ez"] = 0; // defined here to avoid collisions on simultaneous tw
    tw[tw_id]["status"] = "playing"; // playing, aborted, complete
    tw[tw_id]["element"] = resolve_element(element);
    tw[tw_id]["property"] = resolve_property(property);
    if (Boolean(tw[tw_id]["property"].match(color_at_end))) tw[tw_id]["is_color_tween"] = true;
    tw[tw_id]["duration"] = duration; //ms
    tw[tw_id]["step"] = 0;
    tw[tw_id]["interval"] = 1000 / fps; //ms
    tw[tw_id]["steps"] = Math.ceil(duration / tw[tw_id]["interval"]);
    tw[tw_id]["from_orig"] = from; //  '', 'current', '1', '30%' ...
    tw[tw_id]["to_orig"] = to;
    tw[tw_id]["timer"] = false;

    // Stop simultaneous
    for (var kounter = 0; kounter < tw_id; ++kounter) {
        if (tw[kounter]["status"] !== "playing") continue;
        if (tw[kounter]["element"] !== tw[tw_id]["element"]) continue;
        if (tw[kounter]["property"] !== tw[tw_id]["property"]) continue;
        // We arrived here! that means 2 tw on the same element with the same property, keep the newest tween..
        tw[kounter]["status"] = "aborted";
        clearInterval(tw[kounter]["timer"]);
    }


    if (tw[tw_id]["from_orig"] === 'current') {
        tw[tw_id]["from"] = getStyle(tw[tw_id]["element"], tw[tw_id]["property"]);
        if (tw[tw_id]["from"] === '' || tw[tw_id]["from"] === 'NaN' || typeof (tw[tw_id]["from"]) === "undefined") tw[tw_id]["from"] = tw[tw_id]["element"].style[tw[tw_id]["property"]];
        if (tw[tw_id]["from"] === '' || tw[tw_id]["from"] === 'NaN' || typeof (tw[tw_id]["from"]) === "undefined") {
            if (tw[tw_id]["is_color_tween"]) tw[tw_id]["from"] = "#7F7F7F";
            else tw[tw_id]["from"] = '0';
        }
        // Format the color array
        if (tw[tw_id]["is_color_tween"]) tw[tw_id]["from"] = resolve_color(tw[tw_id]["from"]);
    }


    if (tw[tw_id]["is_color_tween"]) {
        if (tw[tw_id]["from_orig"] === 'current'); // tw[tw_id]["from"]	= tw[tw_id]["from"];
        else tw[tw_id]["from"] = resolve_color(tw[tw_id]["from_orig"]);
        tw[tw_id]["to"] = resolve_color(tw[tw_id]["to_orig"]);
        tw[tw_id]["change"] = [];
        tw[tw_id]["change"]["red"] = tw[tw_id]["to"]["red"] - tw[tw_id]["from"]["red"];
        tw[tw_id]["change"]["green"] = tw[tw_id]["to"]["green"] - tw[tw_id]["from"]["green"];
        tw[tw_id]["change"]["blue"] = tw[tw_id]["to"]["blue"] - tw[tw_id]["from"]["blue"];
    } else {
        if (tw[tw_id]["from_orig"] !== '') {
            // tmp is a temporary variable that I use for retrieving prefix and suffix
            if (tw[tw_id]["from_orig"] === 'current') {
                try {
                    tw[tw_id]["from"] = tw[tw_id]["from"].match(float_pcre)
                } catch (e) {
                    tw[tw_id]["from"] = 0;
                }
            } else tw[tw_id]["from"] = tw[tw_id]["from_orig"].match(float_pcre);

            tw[tw_id]["from"] = parseFloat(tw[tw_id]["from"]);
            tw[tw_id]["to"] = parseFloat(tw[tw_id]["to_orig"].match(float_pcre));
            tw[tw_id]["change"] = tw[tw_id]["to"] - tw[tw_id]["from"];

            var tmp;
            if (tw[tw_id]["from_orig"] === 'current') tmp = tw[tw_id]["to_orig"];
            else tmp = tw[tw_id]["from_orig"];
            tmp = tmp.replace(float_pcre, rand_str);
            tw[tw_id]["prefix"] = tmp.slice(0, tmp.indexOf(rand_str));
            tw[tw_id]["suffix"] = str_replace(tw[tw_id]["prefix"] + rand_str, '', tmp);
        }
    }

    // debuggg...
    if (debugging) {
        var tw_info = new String();
        var elm_props = ['id', 'tagName', 'className'];
        for (var i in tw[tw_id]) {
            tw_info += i + ": ";
            if (i !== "element" && typeof (tw[tw_id][i]) === typeof (Object())) {
                for (var j in tw[tw_id][i])
                tw_info += "nt" + j + ": " + tw[tw_id][i][j];
            } else if (i === "element") {
                for (var j = 0; j < elm_props.length; j++)
                tw_info += "nt" + elm_props[j] + ": " + tw[tw_id][i][elm_props[j]];
            } else tw_info += tw[tw_id][i];
            tw_info += "nn";
        }
        alert(tw_info);
    }

    if (tw[tw_id]["from_orig"] === "") {
        tw[tw_id]["status"] = "playing";
        tw[tw_id]["timer"] = setTimeout("tw[" + tw_id + "]["element"].style[tw[" + tw_id + "]["property"]] = tw[" + tw_id + "]["to_orig"];tw[" + tw_id + "]["status"] = "complete"", tw[tw_id]["duration"]);
    } else ease(tw_id);

    return tw_id;
}

function ease(tw_id) {

    if (tw[tw_id]["step"] === 0) {
        tw[tw_id]["status"] = "playing";
        if (tw[tw_id]["is_color_tween"]) tw[tw_id]["element"].style[tw[tw_id]["property"]] = "rgb(" + tw[tw_id]["from"]["red"] + "," + tw[tw_id]["from"]["green"] + "," + tw[tw_id]["from"]["blue"] + ")";
        else tw[tw_id]["element"].style[tw[tw_id]["property"]] = tw[tw_id]["prefix"] + tw[tw_id]["from"] + tw[tw_id]["suffix"];
    }

    tw[tw_id]["step"]++;

    if (tw[tw_id]["step"] = tw[tw_id]["steps"]) {
        tw[tw_id]["status"] = "complete";
    }

}

function ease_repeat(tw_id) {
    try {
        tw[tw_id]["element"].style[tw[tw_id]["property"]] = tw[tw_id]["ez"];
        ease(tw_id);
    } catch (e) {}
}


/* Keep it simple with these nice functions */

function h2d(h) {
    // hex to decimal
    return parseInt(h, 16);
}

function str_replace(search, replace, subject, count) {
    // version: 908.406
    // discuss at: http://phpjs.org/functions/str_replace
    var i = 0,
        j = 0,
        temp = '',
        repl = '',
        sl = 0,
        fl = 0,
        f = [].concat(search),
        r = [].concat(replace),
        s = subject,
        ra = r instanceof Array,
        sa = s instanceof Array;
    s = [].concat(s);
    if (count) this.window[count] = 0;
    for (i = 0, sl = s.length; i < sl; i++) {
        if (s[i] === '') continue;
        for (j = 0, fl = f.length; j  "MozBorderRadius";
    var matched;
    var dash_letter = new RegExp("-[a-z]");
    while (1) {
        if (matched = property.match(dash_letter)) {
            matched = matched.toString();
            property = str_replace(matched, matched.charAt(1).toUpperCase(), property);
        } else break;
    }
    return property;
}

function resolve_color(color) {
    // return an array containing R, G and B values 
    if (color === 'transparent') // IE (6 and ?)
    color = '#FFF';
    var r, g, b;
    var hex_color_pcre = new RegExp("^#[0-9a-f]{3}([0-9a-f]{3})?$", 'gi');
    var rgb_color_pcre = new RegExp("rgb\(\s*((?:[0-2]?[0-9])?[0-9])\s*,\s*((?:[0-2]?[0-9])?[0-9])\s*,\s*((?:[0-2]?[0-9])?[0-9])\s*\)$", 'gi');
    var rgb_percent_color_pcre = new RegExp("rgb\(\s*((?:[0-1]?[0-9])?[0-9])%\s*,\s*((?:[0-1]?[0-9])?[0-9])%\s*,\s*((?:[0-1]?[0-9])?[0-9])%\s*\)$", 'gi');
    if (color.match(hex_color_pcre)) {
        if (color.length == 4) {
            r = color.charAt(1) + "" + color.charAt(1);
            g = color.charAt(2) + "" + color.charAt(2);
            b = color.charAt(3) + "" + color.charAt(3);
        } else {
            r = color.charAt(1) + "" + color.charAt(2);
            g = color.charAt(3) + "" + color.charAt(4);
            b = color.charAt(5) + "" + color.charAt(6);
        }
        r = h2d(r);
        g = h2d(g);
        b = h2d(b);
    } else if (color.match(rgb_color_pcre)) {
        r = RegExp.$1;
        g = RegExp.$2;
        b = RegExp.$3;
    } else if (color.match(rgb_percent_color_pcre)) {
        r = parseInt((RegExp.$1) * 2.55);
        g = parseInt((RegExp.$2) * 2.55);
        b = parseInt((RegExp.$3) * 2.55);
    } else return false;

    var returned = [];
    returned['red'] = r;
    returned['green'] = g;
    returned['blue'] = b;
    return returned;
}

function getStyle(oElm, strCssRule) {
    // http://robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
    var strValue = "";
    if (document.defaultView && document.defaultView.getComputedStyle) {
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    } else if (oElm.currentStyle) {
        strCssRule = strCssRule.replace(/-(w)/g, function (strMatch, p1) {
            return p1.toUpperCase();
        });
        strValue = oElm.currentStyle[strCssRule];
    }
    return strValue;
}

function generatePassword(len) {
    // http://kadimi.com/en/javascript/random-password-string/
    len = parseInt(len);
    if (!len) len = 6;
    var password = "";
    var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var charsN = chars.length;
    var nextChar;

    for (i = 0; i < len; i++) {
        nextChar = chars.charAt(Math.floor(Math.random() * charsN));
        password += nextChar
    }
    return password;
}

function substr(f_string, f_start, f_length) {
    // version: 908.406
    // discuss at: http://phpjs.org/functions/substr
    f_string += '';

    if (f_start < 0) {
        f_start += f_string.length;
    }

    if (f_length == undefined) {
        f_length = f_string.length;
    } else if (f_length < 0) {
        f_length += f_string.length;
    } else {
        f_length += f_start;
    }

    if (f_length  1000000000 && timeStamp < 2000000000
    var now = new Date().getTime() / 1000;
    var s = parseInt(now, 10);

    return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}

// My favorite $()


function $() {
    //http://v3.thewatchmakerproject.com/code/extended-dollar.txt
    var elements = new Array();
    for (var i = 0, len = arguments.length; i < len; i++) {
        var element = arguments[i];
        if (typeof element == 'string') {
            var matched = document.getElementById(element);
            if (matched) {
                elements.push(matched);
            } else {
                var allels = (document.all) ? document.all : document.getElementsByTagName('*');
                var regexp = new RegExp('(^| )' + element + '( |$)');
                for (var i = 0, len = allels.length; i < len; i++) if (regexp.test(allels[i].className)) elements.push(allels[i]);
            }
            if (!elements.length) elements = document.getElementsByTagName(element);
            if (!elements.length) {
                elements = new Array();
                var allels = (document.all) ? document.all : document.getElementsByTagName('*');
                for (var i = 0, len = allels.length; i < len; i++) if (allels[i].getAttribute(element)) elements.push(allels[i]);
            }
            if (!elements.length) {
                var allels = (document.all) ? document.all : document.getElementsByTagName('*');
                for (var i = 0, len = allels.length; i < len; i++) if (allels[i].attributes) for (var j = 0, lenn = allels[i].attributes.length; j < lenn; j++) if (allels[i].attributes[j].specified) if (allels[i].attributes[j].nodeValue == element) elements.push(allels[i]);
            }
        } else {
            elements.push(element);
        }
    }
    if (elements.length == 1) {
        return elements[0];
    } else {
        return elements;
    }
}


// Ease function(s)
linear = function (t, b, c, d) {
    return c * t / d + b;
};




















// ease functions
// Back
easeInBack = function (t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    return c * (t /= d) * t * ((s + 1) * t - s) + b;
};
easeOutBack = function (t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
};
easeInOutBack = function (t, b, c, d, s) {
    if (s == undefined) s = 1.70158;
    if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
    return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
};





//Circulat
easeInCirc = function (t, b, c, d) {
    return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
};

easeOutCirc = function (t, b, c, d) {
    return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
};

easeInOutCirc = function (t, b, c, d) {
    if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
    return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
};

//Bounce
easeInBounce = function (t, b, c, d) {
    return c - easeOutBounce(d - t, 0, c, d) + b;
};

easeOutBounce = function (t, b, c, d) {
    if ((t /= d) < (1 / 2.75)) {
        return c * (7.5625 * t * t) + b;
    } else if (t < (2 / 2.75)) {
        return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
    } else if (t < (2.5 / 2.75)) {
        return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
    } else {
        return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
    }
};
easeInOutBounce = function (t, b, c, d) {
    if (t < d / 2) return easeInBounce(t * 2, 0, c, d) * .5 + b;
    return easeOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
};
//*/

How can I set a WordPress page as my blog homepage

This can be done with a few clicks from your WordPress blog control panel.

So first login to your control panel, then

  • under the Settings menu choose Reading,
  • after the page finishes loading, choose A static page (select below) for the option Front page displays,
  • then on the first drop-down list  that follows choose the page you want to set as your blog homepage
  • save!.. you don’t wanna forget that one!

You Reading settings should look as follows (in this example, the page title is “The company” ):
WP homepage options

JavaScript round float to n decimal points

The best you can do with built in JavaScript functions is to round a number to the nearest integer using the method Math.round(x), so to round a float to n decimal points we need to come up with our own function.

The function round_float() rounds a floating point number x to n decimals, if you ommit the parameter n, the function will have the same behaviour as the round() method, here is the round_float function definition:

function round_float(x,n){
  if(!parseInt(n))
  	var n=0;
  if(!parseFloat(x))
  	return false;
  return Math.round(x*Math.pow(10,n))/Math.pow(10,n);
}

With prototyping

Dmitry suggested a better approach using prototyping:

if (!Number.toFixed) {
  Number.prototype.toFixed=function(n){
    return Math.round(this*Math.pow(10, n)) / Math.pow(10, n);
  }
}
 
// example:
floating_number = 123.45687;
decimal_points = 2;
window.alert(floating_number.toFixed(decimal_points));