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: , , ,

Disable foreign key checks in MySQL

November 24, 2008 – 22:47

Disabling foreign key checks in MySQL is usefull when you are dealing with tables that use foreign keys (InnoDB engine).

MySQL logo

MySQL logo

You can not delete (drop) multiple tables, a parent table or a child table until you disable foreign key checks four your current database.

The sql command to disable foreign key checks is:

SET FOREIGN_KEY_CHECKS = 0;

To enable the foreign key checks use the opposite command:

SET FOREIGN_KEY_CHECKS = 1;

Tags: , ,

Shell script to extract the exchange rates from BNR (Romania)

August 13, 2008 – 19:59

Here is a simple script to get the exchange rates from www.bnro.ro/nbrfxrates.xml

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
# clear the screen
clear
# display an info message
echo "+------------------------------+"
echo "|        BNR exchange          |"
echo "+------------------------------+"
# check for parameters
if [ $# -ne 1 ]
  then
    echo "Usage: $0 eur  or  $0 usd"
  else
    # convert parameter to upper case
    CURRENCY=$(echo $1 | tr '[:lower:]' '[:upper:]')
    # execute the extraction
    RON=$(lynx -source http://www.bnro.ro/nbrfxrates.xml | grep $CURRENCY | cut -c25-30)
   echo "1 $CURRNECY = $RON RON"
fi

More details about running a shell script on How to create a simple shell script and Understanding file permissions and ownership on Linux .

Tags: , ,