Insert value “0″ for primary keys with auto increment in MySQL

July 12, 2009 – 22:11

In order to insert value 0 in a field that is set as primary key for a MySQL table you need to execute the following query prior to any insert query:

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

Now you can successfully run the insert query with 0 set as value for a primary key, without getting any error message.

Tags: , , , ,

Remove blank lines from a textarea using Prototype

February 18, 2009 – 00:03

Here is a JavaScript function used to remove blank lines from a textarea. This snippet is using the Prototype JavaScript framework

1
2
3
4
function removeBlankLines(field)
{
    $(field).value=$(field).value.gsub(/\s+/, '\r\n');
}

You can use it with “onblur” attribute:

<textarea id="some_text" onblur="removeBlankLines(this)"></textarea>

Tags: , , , ,

Remove spaces from an input field with JavaScript

December 10, 2008 – 23:31

This is a small snippet to remove the spaces from an input field using JavaScript. It can be useful when you want a value without spaces, or when you want to replace the spaces from the input field with other characters.

The JavaScript code:

1
2
3
4
5
function stripspaces(input)
{
    input.value = input.value.replace(/\s/gi,"");
    return true;
}

The input field:

<input type="text" name="field_with_no_spaces" onkeydown="javascript:stripspaces(this)" onblur="javascript:stripspaces(this)" />

The spaces will be stripped from the input field in real-time, as the user types.

Tags: , ,

Copy from Firefox and paste into Excel

December 3, 2008 – 22:58

You’ve probably already noticed that if you try to copy a table from Firefox and paste into an Excel spreadsheet, using the classic methods the table formatting is not preserved, and the data from the table is copied into one cell from the Excel spreadsheet.

The solution is to paste the table contents in Unicode format into the Excel spreadsheet. You can do it using the Paste Special command from the Edit menu in Excel.

Step by step instructions:

1. Copy the table content from Firefox into clipboard (using CTRL+C or right-click and Copy).

2. Go to the Excel spreadsheet, select Edit from the menu, then Paste Special; in the Paste Special dialog box, select Unicode and pres the Ok button.

Now your data is properly formatted.

Tags: , ,

Enable compositing effects for metacity in Ubuntu 8.10

November 25, 2008 – 22:21

Desktop effects in Ubuntu 8.10 can be used without Compiz, by enabling compositing in Metacity – the Gnome’s default window manager.

Ubuntu

Ubuntu

There are more ways to enable compositing in Metacity, but first you need to disable Compiz if you are using it. The fastest way is to go to System->Preferences->Appearance, select the Visual Effects tab, then check the radio button None.

  • CLI way to enable compositing effects: open a terminal and type:
gconftool-2 -s '/apps/metacity/general/compositing_manager' --type bool true
  • GUI way to enable compositing effects: open the Configuration Editor (gconf-editor), go to apps->metacity->general and enable the checkbox compositing_manager.

Although  Metacity is much smoother, the effects are minimal – just some shadows on windows and menus, windows preview for Alt+Tab.

Tags: , , ,