Full-service Internet Marketing & Web Development
Recent Posts

Recommended Reads
|
Mercurial Hook: Forbid 2 headsMike Peters, December 5, 2009 -- Posted under Programming |
The Mercurial version control system offers a powerful mechanism to let you perform automated actions in response to events that occur in a repository. In some cases, you can even control Mercurial's response to those events. No comments
The name Mercurial uses for one of these actions is a hook (aka trigger).
One of the most popular hooks is the ability to reject multiple heads.
What are multiple heads?
Multiple heads are a case where the code repository contains changes from two (or more) developers, that haven't been merged. These changes may potentially overlap and break the application flow.
Having multiple heads occurs in two cases:
* As part of a merge (generally temporary)
* Bugfix versions (generally permanent)
At any time, you can view the head(s) of a repository with the command: hg heads
Pitfalls to watch-for with Multiple Heads
Consider the following scenario:
* It's Monday morning. Bob and Linda each pull a copy of the repository to their local Mercurial HG.
* Bob makes a few changes to index.php and pushes them to the server Monday afternoon.
* Linda makes a few additional changes to index.php and pushes them to the server on Tuesday morning.
Since Linda doesn't have the most recent copy of index.php (with Bob's changes), her copy of index.php will create a second "head" to the project.
There are now two development branches - the one with Bob's changes and the one with Linda's changes, neither one having all changes in place.
While TortoiseHG will often block Linda's push with a warning that it will create multiple heads, it is possible to push with -f (force). Some Mercurial plugins automatically push with -f, creating the second head on the live server repository.
Yes you can run 'hg merge' on the live server to merge Bob and Linda's changes (the two heads) locally, but you never ever want to run hg merge on a live server.
Running 'hg merge', adds "<<<<< local >>>>> other" comments into the source files, as part of its file-diff process. This temporarily breaks the syntax of your source files for the duration of the merge.
If this is a live server, your scripts will all STOP WORKING until the merge is complete and the "<<<<< local >>>>> other" notations are removed from the source files.
Rejecting Multiple heads - Do the merge offline
Instead of allowing multiple heads on the live server, a much better approach is to reject multiple heads, forcing the engineers to merge changes locally, before pushing any change that will create a second head.
In the example above, when Linda attempts to push the changes on Tuesday, her push will be rejected with an error message of "Trying to push more than one head, try run hg merge before it."
Linda then has to pull the recent changes, retrieving Bob's additions, merge the changes locally and then push a version that incorporates both her changes and Bob's into the server.
The benefits of this approach are:
#1. Server scripts are never rendered inactive by a local 'hg merge' run
#2. Engineers always need to retrieve (and test) the latest version, prior to being able to upload changes that may conflict with others.
#3. The live server always has a single development graph, containing the most recent changes.
Installing NetBeans Forbid2Heads Mercurial hook
Step 1: Locate your HG extensions folder
The folder name is 'hgext' and it is typically installed under Mercurial's home folder. For example:
/usr/home/mercurial/work/mercurial-1.3.1/hgext
Step 2: Install forbid_2heads Python script
Create a new folder named 'forbid_2head' under 'hgext' and save this file under /hgext/forbid_2head/forbid_2head.py:
# win32text.py - LF <-> CRLF translation utilities for Windows users
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
# To forbid pushes which creates two or more headss
#
# [hooks]
# pretxnchangegroup.forbid_2heads = python:forbid2_head.forbid_2heads
from mercurial import ui
from mercurial.i18n import gettext as _
def forbid_2heads(ui, repo, hooktype, node, **kwargs):
if len(repo.heads()) > 1:
ui.warn(_('Trying to push more than one head, try run "hg merge" before it.n'))
return True
Step 3: Add hook to Mercurial config file
Update your Mercurial hgweb.config, adding the new hook under the 'hooks' section, like this:
[hooks]
pretxnchangegroup.forbid_2heads = python:forbid_2head.forbid_2heads
--
Attempting to push changes to the repository that will create multiple heads is now blocked.
Users will be presented with an error message and the transaction rolled back, until the user merges changes locally, so that no multiple heads are created:
--
The live server repository will always have a single development branch. Engineers will be forced to merge changes locally, before new changes can be pushed:

View 1 Comment(s)
The name Mercurial uses for one of these actions is a hook (aka trigger).
One of the most popular hooks is the ability to reject multiple heads.
What are multiple heads?
Multiple heads are a case where the code repository contains changes from two (or more) developers, that haven't been merged. These changes may potentially overlap and break the application flow.
Having multiple heads occurs in two cases:
* As part of a merge (generally temporary)
* Bugfix versions (generally permanent)
At any time, you can view the head(s) of a repository with the command: hg heads
Pitfalls to watch-for with Multiple Heads
Consider the following scenario:
* It's Monday morning. Bob and Linda each pull a copy of the repository to their local Mercurial HG.
* Bob makes a few changes to index.php and pushes them to the server Monday afternoon.
* Linda makes a few additional changes to index.php and pushes them to the server on Tuesday morning.
Since Linda doesn't have the most recent copy of index.php (with Bob's changes), her copy of index.php will create a second "head" to the project.
There are now two development branches - the one with Bob's changes and the one with Linda's changes, neither one having all changes in place.
While TortoiseHG will often block Linda's push with a warning that it will create multiple heads, it is possible to push with -f (force). Some Mercurial plugins automatically push with -f, creating the second head on the live server repository.
Yes you can run 'hg merge' on the live server to merge Bob and Linda's changes (the two heads) locally, but you never ever want to run hg merge on a live server.
Running 'hg merge', adds "<<<<< local >>>>> other" comments into the source files, as part of its file-diff process. This temporarily breaks the syntax of your source files for the duration of the merge.
If this is a live server, your scripts will all STOP WORKING until the merge is complete and the "<<<<< local >>>>> other" notations are removed from the source files.
Rejecting Multiple heads - Do the merge offline
Instead of allowing multiple heads on the live server, a much better approach is to reject multiple heads, forcing the engineers to merge changes locally, before pushing any change that will create a second head.
In the example above, when Linda attempts to push the changes on Tuesday, her push will be rejected with an error message of "Trying to push more than one head, try run hg merge before it."
Linda then has to pull the recent changes, retrieving Bob's additions, merge the changes locally and then push a version that incorporates both her changes and Bob's into the server.
The benefits of this approach are:
#1. Server scripts are never rendered inactive by a local 'hg merge' run
#2. Engineers always need to retrieve (and test) the latest version, prior to being able to upload changes that may conflict with others.
#3. The live server always has a single development graph, containing the most recent changes.
Installing NetBeans Forbid2Heads Mercurial hook
Step 1: Locate your HG extensions folder
The folder name is 'hgext' and it is typically installed under Mercurial's home folder. For example:
/usr/home/mercurial/work/mercurial-1.3.1/hgext
Step 2: Install forbid_2heads Python script
Create a new folder named 'forbid_2head' under 'hgext' and save this file under /hgext/forbid_2head/forbid_2head.py:
# win32text.py - LF <-> CRLF translation utilities for Windows users
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
# To forbid pushes which creates two or more headss
#
# [hooks]
# pretxnchangegroup.forbid_2heads = python:forbid2_head.forbid_2heads
from mercurial import ui
from mercurial.i18n import gettext as _
def forbid_2heads(ui, repo, hooktype, node, **kwargs):
if len(repo.heads()) > 1:
ui.warn(_('Trying to push more than one head, try run "hg merge" before it.n'))
return True
Step 3: Add hook to Mercurial config file
Update your Mercurial hgweb.config, adding the new hook under the 'hooks' section, like this:
[hooks]
pretxnchangegroup.forbid_2heads = python:forbid_2head.forbid_2heads
--
Attempting to push changes to the repository that will create multiple heads is now blocked.
Users will be presented with an error message and the transaction rolled back, until the user merges changes locally, so that no multiple heads are created:
Quote:
|
pushing to http://mydomain.com/ searching for changes 4 changesets found adding changesets adding manifests adding file changes added 4 changesets with 2 changes to 7 files (+1 heads) Trying to push more than one head, try run "hg merge" before it. transaction abort! rollback completed abort: pretxnchangegroup.forbid_2heads hook failed [command returned code 1] |
--
The live server repository will always have a single development branch. Engineers will be forced to merge changes locally, before new changes can be pushed:

View 1 Comment(s)
|
Were you just banned from Google Adwords?Mike Peters, December 4, 2009 -- Posted under Traffic |
If you're doing any PPC affiliate marketing, chances are you've heard what's been going on these last 3 days...
Google just completed another round of banning PPC affiliates, providing no information on the cause, other than a canned email.
Unlike a "Google Slap" which is a temporary increase of bid-prices due to low quality-scores, a "Google Ban" is permanent and prevents you from ever advertising on Google using your credit-cards or ip-addresses that you previously used with Google.
We've heard from hundreds of PPC affiliates who got banned on this recent round. Search Engine Marketing forums are exploding with angry marketers who've lost their entire business over-night.
Is affiliate marketing on Google Adwords dying a slow death? This remains to be seen.
The recent ban wasn't limited to affiliates running rebill offers but rather a mix of accounts promoting anything from Clickbank products, CPA offers, poor landing pages, etc.
If you're a PPC marketer, you're going to be forced to evolve or close shop.
Remember this -
Google accounts for about 15% of the traffic available online.
Look into other avenues such as Email Marketing, PPC on other engines such as Yahoo and MSN, Media buys, Product launches and Social media marketing, as a way of driving traffic to your offers.
View 3 Comment(s)
Google just completed another round of banning PPC affiliates, providing no information on the cause, other than a canned email.
Unlike a "Google Slap" which is a temporary increase of bid-prices due to low quality-scores, a "Google Ban" is permanent and prevents you from ever advertising on Google using your credit-cards or ip-addresses that you previously used with Google.
We've heard from hundreds of PPC affiliates who got banned on this recent round. Search Engine Marketing forums are exploding with angry marketers who've lost their entire business over-night.
Quote:
|
Dear advertiser, We are writing to let you know that your Google AdWords account has been disabled due to one or more serious violations of our advertising policies related to Landing Page and Site Quality. As a result, your ads will no longer run through the Google AdWords system and we are unable to accept advertising from you in the future. Please note that future accounts you open will also be disabled. ... Please note that this action is related to sites that have recently been advertised through your account. In a review of your account history, we found that your account had submitted a least one site that egregiously violated our advertising policies. Although you may have removed these sites since our latest review, advertisers that have a history of promoting these types of sites are still subject to account-level disabling. ... If you have additional questions or concerns not addressed by our policies or help center, you can contact support by replying to this email. Sincerely, The Google AdWords team |
Is affiliate marketing on Google Adwords dying a slow death? This remains to be seen.
The recent ban wasn't limited to affiliates running rebill offers but rather a mix of accounts promoting anything from Clickbank products, CPA offers, poor landing pages, etc.
If you're a PPC marketer, you're going to be forced to evolve or close shop.
Remember this -
Google accounts for about 15% of the traffic available online.
Look into other avenues such as Email Marketing, PPC on other engines such as Yahoo and MSN, Media buys, Product launches and Social media marketing, as a way of driving traffic to your offers.
View 3 Comment(s)
|
How to install PHP 5.2.11 with php-fpmMike Peters, November 10, 2009 -- Posted under Programming |
This post will walk you through the process of installing PHP 5.2.11 to run under NGinx using PHP-FPM.
NGinx doesn't have built-in support for running PHP, it uses a third-party daemon to spawn instances of php-cgi and then communicates with those instances over sockets.
PHP-FPM is a replacement for spawn-cgi. Runs faster and is more reliable.
Step 1: Download PHP 5.2.11 and apply PHP-FPM patch
Step 2: Configure PHP
Step 3: Install
Step 4: Start PHP-FPM
NGinx doesn't have built-in support for running PHP, it uses a third-party daemon to spawn instances of php-cgi and then communicates with those instances over sockets.
PHP-FPM is a replacement for spawn-cgi. Runs faster and is more reliable.
Step 1: Download PHP 5.2.11 and apply PHP-FPM patch
cd /home
mkdir temp
cd temp
wget http://www.softwareprojects.com/files/auto/php-5.2.11.tar.gz
wget http://www.softwareprojects.com/php-5.2.11-fpm-0.5.13.diff.gz
tar zxvf php-5.2.11.tar.gz
gzip -cd php-5.2.11-fpm-0.5.13.diff.gz | patch -d php-5.2.11 -p1
mkdir temp
cd temp
wget http://www.softwareprojects.com/files/auto/php-5.2.11.tar.gz
wget http://www.softwareprojects.com/php-5.2.11-fpm-0.5.13.diff.gz
tar zxvf php-5.2.11.tar.gz
gzip -cd php-5.2.11-fpm-0.5.13.diff.gz | patch -d php-5.2.11 -p1
Step 2: Configure PHP
cd php-5.2.11
'./configure' '--enable-fastcgi' '--enable-fpm' '--enable-calendar' '--enable-ftp' '--enable-mbstring' '--enable-mysql' '--with-curl' '--with-dom' '--with-mcrypt' '--with-gd' '--with-iconv' '--with-jpeg-dir=/usr/lib' '--with-mysql=/usr/local/mysql' '--with-openssl' '--with-soap' '--with-sockets' '--with-zlib' '--enable-zip'
make all
'./configure' '--enable-fastcgi' '--enable-fpm' '--enable-calendar' '--enable-ftp' '--enable-mbstring' '--enable-mysql' '--with-curl' '--with-dom' '--with-mcrypt' '--with-gd' '--with-iconv' '--with-jpeg-dir=/usr/lib' '--with-mysql=/usr/local/mysql' '--with-openssl' '--with-soap' '--with-sockets' '--with-zlib' '--enable-zip'
make all
Step 3: Install
make install
strip /usr/local/bin/php-cgi
strip /usr/local/bin/php-cgi
Step 4: Start PHP-FPM
/usr/local/sbin/php-fpm start
|
How to install PHP ChartDirector under FreeBSDMichel Nadeau, November 6, 2009 -- Posted under Programming |
PHP ChartDirector is a powerful PHP extension that allows to generate very complex charts. You can visit their Web site here.
This tutorial will show you how to install it under FreeBSD.
1. Download PHP ChartDirector
The download page is located here -
http://www.advsofteng.com/download.html
Make sure you pick the FreeBSD version for PHP, and make sure you choose the good version between 32 and 64-bit. At the time of writing this post, the latest 32-bit version available for FreeBSD was this one -
http://download2.advsofteng.com/char...freebsd.tar.gz
Now that you have the download link, the first thing to do is to find out where is your PHP extensions directory. You can find it by checking at phpinfo()'s output or in your php.ini file (which is usually located in /usr/local/lib/php.ini). Just search for "extension_dir" in php.ini - you will find it right away. In our case, our extensions directory was "/usr/local/lib/php/extensions/current". We can now download and extract ChartDirector...
When extracting ChartDirector, it creates a "ChartDirector" folder that contains these files/folders:
We are mainly interested by the "lib" directory. Let's copy the files that we need...
You can get rid of these 2 PHP files:
2. Determine the right version
To determine the right version of the DLL that you must use, refer to this page -
http://www.advsofteng.com/doc/cdphpdoc/phpinstall.htm
For example, if you have PHP 4.4.9, you will use this one -
PHP Version 4.2.1 and above: phpchartdir421.dll
Even if it's FreeBSD and not Windows, you are going to specify a DLL as the extension in your php.ini file. You can delete all the others DLL's that you are not using, but make sure you keep the "fonts" folder and the "libchardir.so" file - they are required. So your extensions directory might look like this:
3. Configure the extension in php.ini
Now that we have all we need, we're going to configure php.ini to add the PHP ChartDirector extension.
Open your php.ini and add a line like this one in the extensions section:
Make sure you use the right DLL for your PHP version. Save your php.ini file and restart your PHP engine and/or Web server (Apache, FastCGI, etc.) to reload your PHP configuration.
To test PHP ChartDirector, you can use the "phpdemo" directory that you can find in the PHP ChartDirector archive. Just copy the folder in the root of your Web server and point it with your browser (ex: http://yourWebAddress/phpdemo). This demo is also very convenient for charts examples.
View 1 Comment(s)
This tutorial will show you how to install it under FreeBSD.
1. Download PHP ChartDirector
The download page is located here -
http://www.advsofteng.com/download.html
Make sure you pick the FreeBSD version for PHP, and make sure you choose the good version between 32 and 64-bit. At the time of writing this post, the latest 32-bit version available for FreeBSD was this one -
http://download2.advsofteng.com/char...freebsd.tar.gz
Now that you have the download link, the first thing to do is to find out where is your PHP extensions directory. You can find it by checking at phpinfo()'s output or in your php.ini file (which is usually located in /usr/local/lib/php.ini). Just search for "extension_dir" in php.ini - you will find it right away. In our case, our extensions directory was "/usr/local/lib/php/extensions/current". We can now download and extract ChartDirector...
cd /usr/local/lib/php/extensions/current
wget http://download2.advsofteng.com/chartdir_php_freebsd.tar.gz
tar xvfz chartdir_php_freebsd.tar.gz
wget http://download2.advsofteng.com/chartdir_php_freebsd.tar.gz
tar xvfz chartdir_php_freebsd.tar.gz
When extracting ChartDirector, it creates a "ChartDirector" folder that contains these files/folders:
doc/
lib/
phpdemo/
LICENSE.TXT
README.TXT
lib/
phpdemo/
LICENSE.TXT
README.TXT
We are mainly interested by the "lib" directory. Let's copy the files that we need...
cd /usr/local/lib/php/extensions/current
mv ChartDirector/lib/* .
mv ChartDirector/lib/* .
You can get rid of these 2 PHP files:
rm FinanceChart.php
rm phpchartdir.php
rm phpchartdir.php
2. Determine the right version
To determine the right version of the DLL that you must use, refer to this page -
http://www.advsofteng.com/doc/cdphpdoc/phpinstall.htm
For example, if you have PHP 4.4.9, you will use this one -
PHP Version 4.2.1 and above: phpchartdir421.dll
Even if it's FreeBSD and not Windows, you are going to specify a DLL as the extension in your php.ini file. You can delete all the others DLL's that you are not using, but make sure you keep the "fonts" folder and the "libchardir.so" file - they are required. So your extensions directory might look like this:
fonts/
libchartdir.so
phpchartdir421.dll
libchartdir.so
phpchartdir421.dll
3. Configure the extension in php.ini
Now that we have all we need, we're going to configure php.ini to add the PHP ChartDirector extension.
Open your php.ini and add a line like this one in the extensions section:
extension=phpchartdir421.dll
Make sure you use the right DLL for your PHP version. Save your php.ini file and restart your PHP engine and/or Web server (Apache, FastCGI, etc.) to reload your PHP configuration.
To test PHP ChartDirector, you can use the "phpdemo" directory that you can find in the PHP ChartDirector archive. Just copy the folder in the root of your Web server and point it with your browser (ex: http://yourWebAddress/phpdemo). This demo is also very convenient for charts examples.
View 1 Comment(s)
|
How to count unique visitors in an nginx access.logMike Peters, November 4, 2009 -- Posted under Programming |
This nifty one-liner will count the number of unique visitors in an NGinx web-server access.log file, for a given day:
Replace 04/Nov/2009 with the date you'd like to count the number of unique visitors for.
grep "\[04/Nov/2009" access.log | cut -d" " -f1 | sort | uniq | wc -l
Replace 04/Nov/2009 with the date you'd like to count the number of unique visitors for.
|
FreeBSD No Ports FixMike Peters, November 4, 2009 -- Posted under Programming |
When installing a FreeBSD system, you're asked if you would like to install the Ports Collection. If you chose no, you can follow these instructions to obtain the ports collection:
Option 1 - CVSup
Option 2 - Portsnap
Option 1 - CVSup
csup -L 2 -h cvsup.FreeBSD.org /usr/share/examples/cvsup/ports-supfile
csup
csup
Option 2 - Portsnap
portsnap fetch
portsnap extract
portsnap extract
| « Previous Posts | » Next Posts |
