Running Apache 2.2 in a foreground

It took a while for me to find out how to leave Apache 2.2 running in a foreground, since old -F switch were not available. So, to leave apache in a foreground u need to run it with -D FOREGROUND command line parameter.

/user/bin/httpd -D FOREGROUND

Enable XDebug in Zend Studio for Eclipse

Ever wanted to use XDebug for remote debugging in Zend Studio for Eclipse instead of standard Zend Debugger? Here is a good post about how to do this.

JavaScript recursive SetTimeout

A simple JavaScript solution for recursively setting timeout and running some operation periodically with maximum number of iterations support and only anonymous functions.

1
2
3
4
5
6
7
8
9
10
(function(){
    var t_count = 0;
    (function(delay, count) {
        setTimeout(function() {
            if (count && ++t_count > count) return;
            // do your stuff here
            setTimeout(arguments.callee, delay);
        }, delay);
    })(200, 10);
})();

If you will omit second argument to anonymous function than operation will run infinitely.

1
2
3
4
5
6
7
8
(function(){
    var t_count = 0;
    (function(delay, count) {
        setTimeout(function() {
        //...
        }, delay);
    })(200);
})();

Its even possible to constantly increase delay between operations.

1
2
3
4
5
6
7
8
(function(){
    var t_count = 0;
    (function(delay, count) {
        setTimeout(function() {
        //...
        }, delay * 0.5);
    })(200);
})();

Javascript function(){}() vs (function(){})()

What’s the difference between function(){}() and (function(){})() JavaScript constructions? Both are right away executed anonymous functions. I have asked this question to myself mainly because of context where I have used them and they seemed to be equal to me:

1
2
3
4
5
6
7
var f1 = function(){
    return 'value1';
}();
 
var f2 = (function(){
    return 'value2';
})();

I was assigning return value from function to a variable and it worked the same good for both versions with and without extra set of parentheses. After playing a bit and investigating jQuery code it become clear to me that the difference is in a standalone execution. Function with extra set parentheses you can be executed anonymously while variant without parentheses can only be used in a right side of assignment.

1
2
3
4
5
6
7
8
9
// does not work (syntax error)
function(){
    return 'value1';
}();
 
// works fine
(function(){
    return 'value1';
})();

Simplifying apache vhosts configuration with mod_macro

One of the reasons why Apache is still so popular on a web servers market is a huge number of modules available for it. In this post i would like to share with you my experience with using third party module called mod_macro for simplifying maintenance of Apache configuration files. This module really allows you to follow DRY rules in your configs by wrapping repeatable piece of config with a special Macro tag and than reusing it passing different variables within macro call.

Anyway it is worth to read original module documentation.

Here is a few config snippets I use:

# This VHost macro is used on my local machine
# and is used for development purposes, it allows
# me to specify relative document root directory
<Macro VHost $host $webroot>
  <VirtualHost *:80>
      DocumentRoot /www/vhosts/$host$webroot
      ServerName $host
      ServerAlias *.$host
      ErrorLog /www/vhosts/$host/error.log
  </VirtualHost>
</Macro>
 
Use VHost localhost /
Use VHost pma /
Use Vhost webmaster.local /
Use VHost framework.js.local /svn/trunk
Use VHost intranet.local /www
# This one is used on our development machine where every developer
# has his own virtual host (mapped with mod_rewrite). This particular
# part is used for setting mod_php configuration parameters
 
#
# Developer macro
#
 
<Macro Developer $name>
  <Directory /home/$name/sites>
    php_admin_value open_basedir            /home/$name/
    php_admin_value upload_tmp_dir          /home/$name/sites/tmp
    php_admin_value session.save_path       /home/$name/sites/tmp
    php_admin_value soap.wsdl_cache_dir     /home/$name/sites/tmp
    php_admin_value error_log               /home/$name/sites/php_error.log
  </Directory>
</Macro>
 
#
# List of developers
#
 
Use Developer boaz
Use Developer thomas
Use Developer danube
Use Developer smith

NB! Windows version of mod_macro can be downloaded from Apache Lounge website.

Lingvo bookmarklet (english <> russian)

I’d like to share Lingvo bookmarklet for english <> russian translation.

Here is it: Lingvo en <> ru

It is based on lingvo fr <> ru bookmarklet found here.

Google Translate Bookmarklets

I just found out that Google Translate has very useful boormarklets for your browsers to simplify translating whole web pages.

Here is the bookmarlets page. Just drag links with languages you want to translate into to your Bookmarks Toolbar and than click these buttons when you are on web pages you want to translate.

JavaScript as you have never seen it before!

I really got shocked after viewing this video and trying to launch examples at http://www.chromeexperiments.com/ in my Google Chome Beta (2.0.169.1). Is it really plain JavaScript? I could not believe my eyes :)
(more…)

Console history search by arrow up and arrow down

I find it very convenient using arrow up and arrow down buttons for searching in commands history in a shell. The mappings are in /etc/inputrc file:

# mappings for "arrow up" and "arrow down" to search the history
"\e[A": history-search-backward
"\e[B": history-search-forward

Copy package into chroot environment on Gentoo

I would like to share simple bash one line script for copying or updating a package installed on your main Gentoo system to an existent chroot environment. Basically this script takes full list of package files with help of “equery files” command and than copies all these files into chroot environment.

# for f in `equery files bzip2`; do if [ -d "$f" ]; then if [ ! -e "/your/chroot/directory$f" ]; then mkdir "/your/chroot/directory$f"; fi; else cp "$f" "/your/chroot/directory$f"; fi; done