Photoshop: Text Tool Keyboard Shortcuts

In order to speed up your work using Photoshop’s powerful but sometimes quite frustrating text tool, here are a couple of handy keyboard shortcuts you might like to remember:

  • Commit text changes by pressing CTRL+Enter. (Pressing Enter on its own will just start a new line obviously!)
  • With all text selected, you can hide the selection colour with CTRL+H to see an accurate preview. Useful when working with colour in particular!
  • CTRL+Shift+Left or Right arrow keys selects the whole next or previous word.
  • CTRL+Shift+< or > decreases or increases the font-size by 2 points.
  • CTRL+Shift+ALT+< or > decreases or increases the font-size by 10 points.
  • CTRL+ALT+Left or Right arrow keys increase or decrease letter kerning by 100.
  • ALT+Left or Right arrow keys increase or decrease letter kerning by 20.
  • CTRL+ALT+Up or Down arrow keys move the text baseline up or down by 10.
  • ALT+Up or Down arrow keys move the text baseline up or down by 2.
  • CTRL+Shift+L, R or C aligns the paragraph of text left, right or center.

Finally, and although not a keyboard shortcut, double clicking on the T icon in the layers panel will actually select all text in that layer.

Useful.

Posted in Software & Websites, Tutorials | Tagged , , , , , , | Leave a comment

Send Highlighted Text and Link via Email Fast!

Arthur Sabintsev (aka LazyRussion) brings to us the brilliant little Firefox add-on named Email This! which basically allows you to right-click on any selected text on any webpage your are currently browsing and then send the highlight text, title plus link to an email recipient using GMail, Google Apps GMail, Yahoo or even standalone mail clients like Outlook Express or Thunderbird.

The amount of times I want to send an email to myself containing the exact data I just mentioned above for later reference is a lot, so this little add-on is certainly proving to be one hell of an effort saver! :)

To use, simply install as normal and once installed, set the necessary mailer preferences by clicking on the Options button under the Email This! entry on the add-ons page. Once set up, Email This! now becomes usable via either a toolbar entry or a right-click context menu option.

All that, all that is left is now to browse to a page, highlight a passage of text and click send! Brilliant I tell you! :)

Add to Firefox: https://addons.mozilla.org/en-US/firefox/addon/3102

Related Link: http://lazyrussian.com/my-projects/email-this-firefox-extension/

Posted in Software & Websites | Tagged , , , , , , , , , | Leave a comment

Force Your Script to Run Longer than Maximum Execution Time

I have to process some large CSV files that generate a lot of SQL statements that need to be executed. Naturally, trying to parse any of the files almost always results in my script spitting back that horrible maximum execution time exceeded error message, even though I’ve adjusted the maximum execution time setting in the php.ini file to as large as I dare go.

So how does one go about forcing a script to stay alive infinitely until it eventually finishes its job?

(Note: You really don’t want to apply what follows to an infinite loop snippet of code!)

Well, PHP does hand us the nifty set_time_limit() function that basically restarts PHP’s built in timeout counter, setting it to zero and then changing the new timeout value to the number of seconds specified in the function call. So for example, if the timeout default is 30 seconds and you call set_time_limit(20) 25 seconds into script execution, the script will now be able to run 45 seconds before timing out.

Now calling the function with a seconds parameter of zero is said to remove the time limit altogether, though in practice you may find that this doesn’t always work exactly how it should.

If for example your long-running script is based on a long loop operation, the easiest way to ensure your script doesn’t time out is to call the set_time_limit function with a specified timeout duration of say 20 seconds for each and every loop iteration.

This will in essence keep resetting the timeout counter and extending the maximum execution time, thus resulting in a script that has a potential to run just about forever! :)

[Unless of course you are running your script under II7 on a Windows Server 2008 machine where you'll have to adjust some additional Windows Environment parameters! Something to note though is that this function won't work if you are running PHP in SAFE mode. Unfortunately there doesn't seem to be a workaround for this instance! :( ]

Related Link: http://php.net/manual/en/function.set-time-limit.php

Posted in Technology & Code, Tutorials | Tagged , , , , | 1 Comment

How to Convert an UTF-16 File to an UTF-8 file using PHP

Taking Andrew Walker’s previously mentioned handy little UTF-16 to UTF-8 string converter function, we now have in our means a particularly easy way in which to craft a simple UTF-16 to UTF-8 file converter, useful as I have found in the past for those silly little cases like when someone is spitting out Microsoft SQL Server generated CSV files (which are by default encoded in UTF-16) at you for example.

So let’s put down the code then shall we?

function utf16_to_utf8($str) {
    $c0 = ord($str[0]);
    $c1 = ord($str[1]);
 
    if ($c0 == 0xFE &amp;&amp; $c1 == 0xFF) {
        $be = true;
    } else if ($c0 == 0xFF &amp;&amp; $c1 == 0xFE) {
        $be = false;
    } else {
        return $str;
    }
 
    $str = substr($str, 2);
    $len = strlen($str);
    $dec = '';
    for ($i = 0; $i &lt; $len; $i += 2) {
        $c = ($be) ? ord($str[$i]) &lt;&lt; 8 | ord($str[$i + 1]) :
                ord($str[$i + 1]) &lt;&lt; 8 | ord($str[$i]);
        if ($c &gt;= 0x0001 &amp;&amp; $c &lt;= 0x007F) {
            $dec .= chr($c);
        } else if ($c &gt; 0x07FF) {
            $dec .= chr(0xE0 | (($c &gt;&gt; 12) &amp; 0x0F));
            $dec .= chr(0x80 | (($c &gt;&gt;  6) &amp; 0x3F));
            $dec .= chr(0x80 | (($c &gt;&gt;  0) &amp; 0x3F));
        } else {
            $dec .= chr(0xC0 | (($c &gt;&gt;  6) &amp; 0x1F));
            $dec .= chr(0x80 | (($c &gt;&gt;  0) &amp; 0x3F));
        }
    }
    return $dec;
}
 
function convert_file_to_utf8($csvfile) {
    $utfcheck = file_get_contents($csvfile);
    $utfcheck = utf16_to_utf8($utfcheck);
    file_put_contents($csvfile,$utfcheck);
}

To convert a file simply call the convert_file_to_utf8() function and pass to it the file path of the file you wish to convert. The function then uses the PHP function file_get_contents() to pack the input file’s contents into a string variable which is then passed to the main converter function which converts the string from UTF-16 to UTF-8 encoding if necessary. Finally, we use file_put_contents() to stuff the resulting string back into the original file, overwriting the original file contents.

Nice and simple really.

Posted in Technology & Code, Tutorials | Tagged , , , , , , , , | Leave a comment

Inserting Backslashes into a Database Table with PHP

Sometimes you need to store things like file paths into a database table during your PHP script’s execution. However, on going back to the database after running your script, you might come across your path with all of its backslashes (\) missing!

So just what is going on here?

In most cases you will be using a string construct to send your SQL command, in other words, mysql_query() will be sending along a string SQL statement to be processed by the database. However, recall that backslashes usually need to be escaped in order to display a backslash, and in PHP for example, escaping characters is done by using a backslash – so in other words to display a backslash in a string, you actually need to put down two of the things: \\

However, when pushing your escaped string through to the database, remember that mySQL also needs to escape the backslashes it receives via your SQL statement, meaning that in actual fact you need to be double escaping your escaped backslashes!

To make this simpler to understand, you want to use this in your SQL string: \\\\. So what happens now is that the PHP script escapes the above to \\ which is then passed along to mySQL which then further escapes it to \, leaving you with a nice shiny backslash in your record as a result.

Got it?

Anyway, naturally PHP makes things a little easier for us by providing the handy mysql_real_escape_string() function which will handle the escaping of all special characters for use in a SQL statement, even taking into account the current character set of the connection specified!

Now you know.

Related Link: http://www.php.net/manual/en/function.mysql-real-escape-string.php

Posted in Technology & Code, Tutorials | Tagged , , , , , , | 1 Comment

PHP: Convert a UTF-16 String to a UTF-8 String

Andrew Walker crafted this handy little PHP function which can convert a UTF-16 encoded string into a more PHP-friendly UTF-8 encoded string.

The function first checks to see if the string passed to it is prefixed with a Byte Order Mark (BOM), and if the necessary BOM exists, the function continues to convert the rest of the string to its more compact UTF-8 format.

Obviously if no BOM is present, the function leaves the input string unchanged.

function utf16_to_utf8($str) {
    $c0 = ord($str[0]);
    $c1 = ord($str[1]);
 
    if ($c0 == 0xFE && $c1 == 0xFF) {
        $be = true;
    } else if ($c0 == 0xFF && $c1 == 0xFE) {
        $be = false;
    } else {
        return $str;
    }
 
    $str = substr($str, 2);
    $len = strlen($str);
    $dec = '';
    for ($i = 0; $i < $len; $i += 2) {
        $c = ($be) ? ord($str[$i]) << 8 | ord($str[$i + 1]) : 
                ord($str[$i + 1]) << 8 | ord($str[$i]);
        if ($c >= 0x0001 && $c <= 0x007F) {
            $dec .= chr($c);
        } else if ($c > 0x07FF) {
            $dec .= chr(0xE0 | (($c >> 12) & 0x0F));
            $dec .= chr(0x80 | (($c >>  6) & 0x3F));
            $dec .= chr(0x80 | (($c >>  0) & 0x3F));
        } else {
            $dec .= chr(0xC0 | (($c >>  6) & 0x1F));
            $dec .= chr(0x80 | (($c >>  0) & 0x3F));
        }
    }
    return $dec;
}

Thanks Andrew, this was exactly what I was looking for! :)

Related Link: http://www.moddular.org/log/utf16-to-utf8

Posted in Technology & Code | Tagged , , , , , , , | 1 Comment

Getting the First Object Returned by a jQuery Selector

If for instance you have just used a jQuery selector to grab a whole lot of objects and now realize that in actual fact you only want to effect the first object that the selector returned to you, you can rest easy in the knowledge that jQuery as per usual has you covered.

Now jQuery 1.4 has gone and simplified the logic for us by supplying us with a function neatly named first(), which when in action looks something like this:

$(‘li’).first()

However, if you are not up and running on the 1.4 library just yet, there is an older way of doing this, using either the built in selector :first or by making use of the specific object selector function, namely eq().

Using the built in selector method, your code would look like this:

$(‘li :first’)

On the other hand, using the eq() function will leave you with this:

$(‘li’).eq(0) … (where 0 is basically the beginning index of the returned object array)

In any event, using either one of these three methods will result in jQuery returning only one object, namely the first object it encountered when applying the initial selector value.

Useful.

Posted in Technology & Code, Tutorials | Tagged , , , , , | Leave a comment
 
Your Ad Here
Afrigator   Sorted bru, tagged by Amatomu.com