Sunday, June 7, 2009

My worst production fail

In respond to http://thedailywtf.com/Articles/A-Classic-Production-Failure.aspx my worst production fail was almost classic but a little different. I was green and just started to work in a small company.

Consider the following sql statement in PHP:

UPDATE table SET balance = $sum - $amount
what if $amount less than zero

UPDATE table SET balance = 50 - -10
-- means comment, no -- equals to + in SQL

and what we have is not what we wanted - every record with balance = 50

That was my epic production fail. Backup and stored balance transactions records saved my day.

Don't use such stupid statements...

Wednesday, April 29, 2009

PHPBB3 Template path could not be found

I received this error when I was trying to login into ACP after writing Auth plugin for integrating site authentication system with phpBB3. In my case the mistake was assigning phpBB3 variable in plugin, that led to altering the global variable.

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';

Saturday, April 11, 2009

How did I install dual monitors in ubuntu

As I killed one day for this, I can share how I finally managed this. I had an ati driver: with my Radeon 9200. These are two good links for this:

BinaryDriverHowtoATI | Community Documentation

HowTo: Dual Monitors (Xinerama/TwinView/MergedFB/Big-Desktop) | Ubuntu Forums

One of the reasons to install fglrx driver instead of open source ati for ati card is dual mode. As from first link ubuntu documentation:

The 'fglrx' driver does not support cards earlier than the 9500.

Different configurations with xorg.conf file didn't have an effect for me. I even tried to install envy packages with no result. So I took the easier way and installed nvidia Geforce 6200. After that I removed all video drivers via synaptic manager: ati, fglrx, envy, nvidia, upgraded my ubuntu to 8.10, reconfigured x server:
sudo dpkg-reconfigure xserver-xorg
restarted x server. I got an low resolution screen. After I installed nvidia-settings package and with it I configured my resolution, and even dual monitors using Twinview. This program allowed also to save configuration to xorg file. I restarted my x-server and vuala I got cool dual montitors.

Monday, February 23, 2009

Showing current branch for GIT in bash profile

Add into ~/.bashrc

PS1='\[\033[01;32m\]\h\[\033[01;34m\] \w\[\033[31m\]$(__git_ps1 "(%s)") \[\033[01;34m\]$\[\033[00m\] '

Thanks to http://www.shaldybin.com/2008/11/small-surprise-from-git-16.html

Saturday, February 7, 2009

Select Isn't broken

I have just read the following in The Pragmatic Programmer:

Even if the problem does lie with a third party, you'll still have to eliminate your code before submitting your bug report.

And I recalled that several weeks ago I was in a similar situation. My server script executed 2 times after submitting form. I tested all the code, and didn't understand, almost went crazy, asked colleague for help, we couldn't find the reason for such behavior. Direct call of action was fine. I began to think that the problem was in Codeigniter code and I was about to send them a bug report. However, after testing the code in another browser was successful, I began to suspect HTML of the site that came from client. What was found? 

<a href="url"><button></button></a>

generates 2 requests in Firefox. So we omited link and changed to type submit and everything was fine.
Ok, what's the lesson? Always be suspicious. But it is like 99% the problem is in your code, not in OS, external library or framework.

Wednesday, December 10, 2008

Ignore files in SVN

The file you want to ignore is located in svn repository. Before you start backup your file. To ignore it set the property to project directory.

svn propedit svn:ignore /path/to/project

In opened text editor specify filenames that you want to ignore by locations from project directory each in a new line. Save. Remove file from svn. And commit. Restore file from backup.

Example:

1. Backup ignoring file

$ cp application/config/database.php application/config/database.php.back

2. In command line

$ svn propedit svn:ignore .

3. In a text editor insert

application/config/database.php

See message "Set new value for property 'svn:ignore' on '.'"
4. In command line

$ svn remove application/config/database.php
D application/config/database.php

5. In command line

$ svn commit -m "Ignoring database config"
Sending .
Deleting application/config/database.php

6. Restore file

$ mv application/config/database.php.back application/config/database.php


Now "svn status" will return nothing.

Tuesday, September 9, 2008

XSL &nbsp; equivalent


<xsl:text> </xsl:text>