How to turn off drupal messages

A red error message displaying on your webpage, visible to every visitor is the worst thing you can do to your site. Unfortunately, drupal displays error messages on the screen by default. There are several solutions to this problem.

1. Install disable_messages plugin

The disable messages plugin is only available for drupal 6 and drupal 7.

2. Edit page.tpl file

Remove the following piece of code from your page.tpl file

Counting cells in Excel

Excel provides 4 different functions to count cells: count(), counta(), countblank(), countif()

=count(A1:A10)

Counts cells in the range which hold a value. Empty cells and cells containing formulas are not counted.

=counta(A1:A10)

Counts non-empty cells in the range. Cells containing formulas are counted.

=countblank(A1,A10)

Counts empty cells in the range.

=countif(A1:A10,"<10")

Counts cells in the range which satisfy a condition. In this example, only cells with value less than 10 are counted.

PHP Benchmark Results

Benchmarking is the process of evaluating existing processes and identifying best practices. For example, there are three ways to loop through an array, we would test each method and identify the best performing method. In terms of code, this very often means identifying methods that would be least expensive in terms of CPU time and memory consumption.

Following is a simple benchmark script. It compares while loop with for loop.

Escaping single quotes inside single quotes in bash

In bash, you can use the backslash character ("\") to escape any character. However, if a single quote is inside single quotes, it cannot be escaped with a backslash character. For example:

alias ycd='some_command'

works fine but

alias ycd='command -option 'something''
alias ycd='command -option \'something\''

both of the above return errors.

A trick around this problem is to use both quotes i.e. use double quotes to surround the single quote and single quotes again to surround the single quote.

Changing keyboard on a mac

  1. Click on the Apple logo and select "System Preferences"
  2. Click on "International" icon on "System Preferences" window.
  3. Click on "Input Menu"
  4. Make sure that "Show input menu in menu bar" is checked.
  5. Make sure the "Keyboard Viewer" is set to viewable.
  6. Select the languages you desire
  7. Close the window
  8. Use the flag icon on the top left to set the keyboard layout

PHP code to convert XML to JSON

Converting XML to JSON is very easy in PHP. See the following code.

$jsonfile =  fopen("file.json", "w") or die ("Cannot open JSON file for writing");
$xml = simplexml_load_file("file.xml") or die ("Cannot load xml file");
fwrite($jsonfile, json_encode($xml));
fclose($jsonfile);

line 1: open an empty file to write JSON line 2: load xml file line 3: convert xml to json using json_encode function and then write the json file line 4: close the file

Pages