An array of C#, PHP, and HTML programming articles, tutorials, and resources

Posts Tagged ‘ format ’

You may have noticed the fancing code snippets that accompany many of the tutorials on this website! I would love to say I developed this myself, but the truth is that this is a free resource free for anybody to download and use. It is called SyntaxHighlighter and can be found at http://code.google.com/p/syntaxhighlighter/.

What is Included?

So what does the Syntax Highlighter come with? Below is a list my favorite features of this software:

  1. It’s completely free!
  2. Associate keywords for supported languages are highlighted.
  3. Each line of code is numbered and colored for easier reading!
  4. Allows one click to code only view.
  5. Allows one click copy to clipboard of code.
  6. Allows one click copy to printer.

What Comes With the Download

The file can be downloaded from their official website at http://code.google.com/p/syntaxhighlighter/ as a rar compressed file. Inside the compressed file, you will find various folders and files. The core files that are required include:

  1. clipboard.swf
  2. shCore.js
  3. SyntaxHighlighter.css

Still, there are many more JavaScript files that have been included in the download. Not all of these files are required. Instead, you choose additional optional JavaScript files for the programming or scripting languages you want the Syntax Highlighter to associate.

Installation After Uploading Files

After you have uploaded the required and accompanying optional files, you will need to include the javascript and css files to the header of the pages with which you plan on using the Syntax Highlighter. See the example below:

<link type="text/css" rel="stylesheet" href="http://www.victorchen.info/wp-includes/js/SyntaxHighlighter/Styles/SyntaxHighlighter.css"></link>
<script language="javascript" src="http://www.victorchen.info/wp-includes/js/SyntaxHighlighter/Scripts/shCore.js"></script>
<script language="javascript" src="http://www.victorchen.info/wp-includes/js/SyntaxHighlighter/Scripts/shBrushCSharp.js"></script>
<script language="javascript" src="http://www.victorchen.info/wp-includes/js/SyntaxHighlighter/Scripts/shBrushJava.js"></script>
<script language="javascript" src="http://www.victorchen.info/wp-includes/js/SyntaxHighlighter/Scripts/shBrushPhp.js"></script>
<script language="javascript" src="http://www.victorchen.info/wp-includes/js/SyntaxHighlighter/Scripts/shBrushXml.js"></script>
<script language="javascript" src="http://www.victorchen.info/wp-includes/js/SyntaxHighlighter/Scripts/shBrushJScript.js"></script>
<script language="javascript">
  window.onload = function () {
    dp.SyntaxHighlighter.ClipboardSwf = 'http://www.victorchen.info/wp-includes/js/SyntaxHighlighter/Scripts/clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
  }
</script>

In the above, there Line 1 includes the CSS file. Next, Line 2 includes the one core JavaScript file. Lines 4 through 8 include optional JavaScript files. Lines 9 through 14 include setup for using Syntax Highlighter. The portion requires including the clipboard.swf file.

Usage

I assume you already have formatted code contained within the pre tags, as found in a previous tutorial called 3 Steps to Posting Sample Code on your Website. As of now, all you have is a formatted tag, without the fancy upgrades. All you need to add for fancy code formatting is to add name=”code” class=”html”. Exchange html with the type of file you have included. Click to see sample supported files: http://code.google.com/p/syntaxhighlighter/wiki/Languages. An example:

<pre name="code" class="html">&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Victor's Programming Aid&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;This is a test&lt;/p&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>

Conclusion

With that, you now have fancy code formatting on your website. Comment on some examples of where you have used the Syntax Highlighter in action!

You may already know that a hard drive on Windows is formatted as Fat32 or NTFS partions. But how do you convert from a popular file system to one that you need in Linux? GParted is free software that through an easy to use interface allows the format and partition of an entire hard drive.

The supported file systems are:

  • ext2
  • ext3
  • fat16
  • fat32
  • hfs
  • hfs+
  • jfs
  • linux-swap
  • ntfs
  • reiser4
  • reiserfs
  • ufs
  • xfs

The application is most easily downloaded as a Live CD (which is a CD that can be automatically booted during startup from the console). Before using this application, be sure to back up any information on the drive, as the operations will clear all data.

The application can be downloaded from their website at http://gparted.sourceforge.net/. The latest version as of the writing of this article is version 0.3.8

Web-based applications involve pages connected by links. Therefore, verifying the authenticity of links becomes a crucial factor. For example, one situation may involve verifyng a link before storing it into a database. Pass to the function a url as a string and it will return true (the link works) or false (the link did not work).

public bool checkUrlLink(string url)
{
   HttpWebRequest request = HttpWebRequest)WebRequest.Create(url);
   request.Proxy = null;
   try
   {
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
      return true;
   }
   catch
   {
      return false;
   }
}

This code snippet uses HttpWebRequest and HttpWebResponse functions. Therefore, the snippet above requires the following using statement:

using System.Net;

Also note that this code snippet will also check wheather a url is properly formatted. If the format is not correct, it will return false (simply because the url did not receive a response).