Tuesday, October 27, 2009

Syntax highlighting in Microsoft Office Word

To paste highlighted code syntax in Word, just use Notepad++

1. Open Notepad++ and load your source file.  Then select your language from the Language menu:



2. Once your code's syntax is highlighted, go to the plugins menu, choose the NppExport plugin and click on 'Export to RTF':



3. Then your source file will be exported to .rtf format and when you open that in Microsoft Office Word, you will see that your syntax is highlighted.  then obviously copy and paste that source.

Saturday, October 24, 2009

How do you pronounce 'Euler' ?

These last two weeks at school, we've been doing stuff like Euler's Number, Euler Graphs and Euler Circuits, which all came from Leonhard Paul Euler, who was a pioneering Swiss mathematician.


When I was doing my assignment on Euler Graphs, I noticed that whenever I typed in 'a Euler Circuit' in Microsoft Word, I was always getting that green squiggly line below the 'a' and Office suggested that I change it to 'an'...and well it got me thinking, since I pronounce Euler as 'youler'.


Normally, an English speaking person would pronounce the word like I do, 'youler', but apparently, it's pronounced 'oiler'; and that's why Microsoft Word was always complaining about it; because 'an "oiler" circuit' makes sense, but "a oiler circuit" doesn't.


So, bottom line...the word Euler is pronounced as OILER


Friday, October 23, 2009

Drawing diagonal connector lines in Visio

I am now in need of creating some graphs and trees and have decided to use Microsoft's Visio for this purpose.

But the problem is that, by default, Visio's lines are set as Right-Angle Connectors and thus I couldn't create diagonal lines.

Anyways, to create diagonal connectors, just connect the line and then right click on it and change the routing to 'Straight Line' :



Wednesday, October 21, 2009

Passing multi-dimensional arrays to functions in C

Here is how to initialize and pass multi-dimensional arrays to functions in ANSI C :

void printArray(int **array, int m, int n)
{
    int i, j;
    for(i = 0; i < m; i++) {
        for(j = 0; j < n; j++) {
            printf("%d\n", array[i][j]);
        }
    }
}

int main()
{
      int i, j, k = 0, m = 5, n = 20;
      int **a = malloc(m * sizeof(*a));
   
      //Initialize the arrays
      for (i = 0; i < m; i++) { 
          a[i]=malloc(n * sizeof(*(a[i])));
      }
      for (i = 0; i < m; i++) {
          for (j = 0; j<n; j++) {
              k++; 
              a[i][j] = k;
          }
      }
   
      printArray(a, m, n);
      
      //Free allocated memory of the array
      for (i = 0; i < m; ++i) {
        free(a[i]);
      }
      free(a);
   
      return 0;
}

Sunday, October 18, 2009

LaTeX Online Equation Editor

Here is a neat website I found : http://www.codecogs.com/components/equationeditor/equationeditor.php

It allows you to type in a LaTeX expression and it generates a .gif file for you.

You can also use the following url to generate LaTeX notations on the fly:

http://latex.codecogs.com/format.latex?equation

where format is the ouput-format and equation is the the actual expression.

These are the available formats:
  • gif
  • png
  • pdf
  • swf
  • emf
  • svg

 Here is an example with the following expression (format: gif) :

A=4r\int_0^r \sqrt {1-\frac{x^2}{r^2}}\, dx = 4r\int_0^{\pi/2} r\sqrt{1-\sin^2 \theta} \cos \theta\, d\theta

generates this:


Syntax highlighting in Blogger

To implement code syntax highlighting, I used instructions from this post by Matthew V Ball.
Here are the instructions:

1. Go to http://syntaxhighlighter.googlecode.com/svn/trunk/Styles/SyntaxHighlighter.css, then perform a "select all" and "copy". The css information is now in the clipboard.

2. Paste the css information at the end of the css section of your blogger html template (i.e., after ).

3. [Updated March 25, 2009 to include closing script tags] Before the  tag, paste the following:

  1.   
  2. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shCore.js' type='text/javascript'>script>  
  3. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCpp.js' type='text/javascript'>script>  
  4. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCSharp.js' type='text/javascript'>script>  
  5. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCss.js' type='text/javascript'>script>  
  6. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushDelphi.js' type='text/javascript'>script>  
  7. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJava.js' type='text/javascript'>script>  
  8. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJScript.js' type='text/javascript'>script>  
  9. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPhp.js' type='text/javascript'>script>  
  10. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPython.js' type='text/javascript'>script>  
  11. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushRuby.js' type='text/javascript'>script>  
  12. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushSql.js' type='text/javascript'>script>  
  13. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushVb.js' type='text/javascript'>script>  
  14. <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushXml.js' type='text/javascript'>script>  
Feel free to remove lines for languages you'll never use (for example, Delphi) -- it will save some loading time.

4. [Updated to add final /script] Before the  tag, insert the following:
  1.   
  2. <script language='javascript'>  
  3. dp.SyntaxHighlighter.BloggerMode();  
  4. dp.SyntaxHighlighter.HighlightAll('code');  
  5. script>  

5. Use the "Preview" button to make sure your website is correct, then click "Save Template".

6. When composing a blog entry that contains source code, click the "Edit Html" tab and put your source code (with html-escaped characters) between these tags:
  1. <pre name="code" class="cpp">  
  2. ...Your html-escaped code goes here...  
  3. pre>  

Substitute "cpp" with whatever language you're using (full list). (Choices: cpp, c, c++, c#, c-sharp, csharp, css, delphi, pascal, java, js, jscript, javascript, php, py, python, rb, ruby, rails, ror, sql, vb, vb.net, xml, html, xhtml, xslt)


For performing the HTML escaping, you can get a good list of tools by searching for 'html esaper' or a similar term. Here's the one I used while writing this post.