November 16th, 2008
There are two mappings: the numerical value corresponding to a character (charset) and the binary representation of that value (encoding). UTF is a charset that has a number of encodings; utf8 is an encoding.
Thanks to utf, we can have different languages on the same webpage.
First of all, make sure the encoding of your text editor is utf8.
PHP
header("Content-Type: text/html; charset=utf-8");
You don’t need that if you managed to edit your httpd.conf properly.
As long as you don’t want to mess with the content of a string, you can pass it around blindly. But as soon as you want to use any function that relies on substring operations (such as substring, wordwrap, chunk_split) you need to use the equivalent multibyte functions, obtaining prepending mb_ (you need to install the extension on PHP)
MySQL
Similar to PHP (careful with substring and fulltext indexing) but no problem if the charset of the db is UFT8
Email
Similar to HTML, just use:
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
The problem is that that meta applies only to the body but it’s quite likely you need UTF8 also for the to/from header. In that case you need a trick you can find on Google
HTML
Don’t forget the following in your head section:
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
Javascript
It fully supports UTF8 apart from the escape() function. Google the utf8 version if you need it.
User Input
No problem with the user input because the browser sends data back to the server using the same encoding the server is using. But there are some exceptions (very old browsers, hacking attempts,…)
Tags: utf, utf8
Posted in Web Development | No Comments »
November 15th, 2008
gettext (an alias is just underscore!)
Posted in PHP | No Comments »
November 12th, 2008
split –bytes=1m /path/to/large/file /path/to/output/file/prefix
You can change the output file size by changing the –bytes=1m to your preference. You can use b, k, or m. b represent bytes, k represent kilobytes, m represent megabytes.
To restore the original file:
cat prefix* > newfilename
To split a file using a regular expression:
csplit filename separator ‘{*}’ (the last bit is to split not just once but as many times as possible)
To restore the original files:
cat $(ls -L) >> a
Tags: split
Posted in Linux Command Line | No Comments »
November 7th, 2008
It’s good for deploy as well.
It can be used also to do backups locally.
Very useful to move big amount of data over the Internet because of its incremental feature.
Backing up from local machine to remove backup server (with the same user):
#!/bin/bash
export RSYNC_RSH=/usr/bin/ssh
dest=backup1
user=$(whoami)
cd || exit 1
rsync -aHPvz . "${user}@${dest}:."
[-z -> to compress, not necessary in LAN]
[-b -> backup of the already exisitng destination files]
SSH is useful just if you send data over the Internet.
Listing the files on the backup server:
#!/bin/bash
dest=server1
user=$(whoami)
cd || exit 1
rsync “${user}@${dest}:.” | more
Restoring (the script runs locally):
#!/bin/bash
dest=server1
user=$(whoami)
cd || exit 1
for file in “$@” ; do
rsync -aHPvz “${user}@${dest}:./${file}” “./${file}”
done
For restoring, you simply run the script, passing the names of the files to be restored as arguments on the command line.
We can also restore all the files at once by using a dot as the filename
Posted in Linux Command Line, System Administration | No Comments »
November 5th, 2008
wc - print newline, word, and byte counts for each file (program for count statistics from a file)
dt = $(date)
ls -l > files.txt 2>error.txt
Redirects standard error to a file
ls -l > files.txt 2>&1
Redirects standard error and standard output to the same file
Some ‘magic’ variables:
- $? is a variable that contains the return status of the most recent command executed.
- $$ is a variable that contains the process ID. This can be useful to create a unique temporary filename.
- $0 is the name of the script itself
- $* contains all the arguments as one string value
- $@ contains all the arguments as an array -> you can use:
for file in “$@”; do
rm file
done
Posted in Linux Command Line | No Comments »
November 4th, 2008
ab -n 1000 -c 5 http://mydomain.com/bench.htm
makes 1000 separate requests for the same file with a concurrency (simultaneous requests) of 5
Posted in Apache, Benchmarch | No Comments »
November 2nd, 2008
Tags: profiling
Posted in PHP | No Comments »
October 26th, 2008
This is an example of the Structure of a file that will manage a page.
This is also a good example on how to manage dropdown boxes.
$(document).ready(
function ()
{
// shows the tags related to the selected category
function showTags()
{
var categoryValue = $('#category').val(); // the selected value of the dropdown menu
var categoryIds = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
for (var i in categoryIds)
{
if ($('#tags_' + categoryIds[i]).css('display') == 'block')
{
$('#tags_' + categoryIds[i]).slideUp('fast');
$('#tags_' + categoryIds[i]).css('display', 'none');
}
}
$('#tags_' + categoryValue).slideDown('fast');
$('#tags_' + categoryValue).css('display', 'block');
// other examples
if ( ($('#smallImage').html() == "") ) // it checkes the actual content of the div
{
var id = $('#bigImageDiv').children('span').attr('id');
}
if ($('#featured:checked').val() != null) // it checkes whether the checkbox is ticked
{
// something
}
}
// showTags must be shown both when the page is loaded
// and in the event of a change in the dropdown 'category'
showTags();
$('#category').change(function() { showTags() });
// set up tool tips
$('label').Tooltip({showURL: false, delay: 0, track: true});
return false;
});
Posted in JQuery | No Comments »
October 26th, 2008
Creating a button with Gimp
- new image 80×20
- select the all image with ‘Select Rectangular Region’ tool
- Menu > Select > Rounded Rectangle
- Radius about 40/50
- Gradient tool
- Make a vercial gradient with two colors quite close
- Text Editor: Sans Bold, 11px, white
- Save as a gif
Tags: button
Posted in Web Design | No Comments »
October 26th, 2008
border-collapse: collapse
Posted in Web Design | No Comments »