Tuesday, July 21, 2009

SyntaxHighlighter follow-up

Something about SyntaxHighlighter has just caught my attention.

As I'd mentioned in my post about it I started out from an older version. I noticed there are a few more brushes then I'd initially added.

I added
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushXml.js' type='text/javascript'/>
But the list consists of
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushAS3.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushDelphi.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushDiff.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushGroovy.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJavaFX.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPerl.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPlain.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPowerShell.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushScala.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushXml.js' type='text/javascript'/>
Wow that's quite a few. You can add any/all of these along with or instead of the ones I'd posted before. Each one is needed for it's respective language, of course.

My custom RDP script

I have a crazy situation. I work at a .Net company, but my installed OS is Linux (Ubuntu Jaunty atm). This is ok though, I asked my boss first, because we use Remote Desktop to do almost all actual work.
Now we move around from time to time. So sometimes I have a different printer I need to share with the server. And since I also want to share a single folder with the server (not my entire filesystem like the TerminalServer client would like), so I decided to write a bash script to help me decide where I am.

startremote.sh:
#!/bin/bash

# Ask where we are, since we don't know where we might end up we add 'other'
# which will default to no extra parameters
srem_WL=$(zenity --list --text="Were Are You?" --radiolist --column="Pick" --column="Locations" TRUE location1 FALSE location2 FALSE other)

# Only do something if cancel wasn't pressed
if [ -n "$srem_WL" ]; then

# The user on the server, I use $USER because I know that on this PC I'll
# always be logged in under the same name as on the server
srem_usr=$USER

# The IP address of the server
srem_ip=0.0.0.0

# The size I want my screen to be
# I add the -g here because one might want fullscreen (with -f)
srem_geo="-g 1910x1120"

# The shares I want to send along
srem_share="-r disk:ShareName=/path/to/some/share"

# The start of my execute command
srem_ex="rdesktop $srem_geo $srem_share"

if [ -n $srem_WL ]; then
# Here we define the configuration differences for each location
case $srem_WL in
location1)
srem_ex+=" -r printer:MyPrinterForLocation1"
;;
location2)
srem_ex+=" -r printer:MyPrinterForLocation2"
;;
esac
# Since other has not been added to the case list it won't add anything
fi

# The end of our execute command
srem_ex+=" -u $srem_usr $srem_up"

# EXECUTE
$srem_ex
fi
You could of course also always share both printers, rdesktop won't complain if it isn't connected, but I'm always looking for stuff to program. And this way you can kind-of create different profiles for different locations.

Friday, July 17, 2009

SyntaxHighlighter with Blogger

Since I post some code from time to time in this blog and I like the idea of syntax highlighting I looked into adding SyntaxHighlighter to my page. I'd found this post by someone else explaining how to do it, but by now this was a little outdated.

So now I thought that I might do this too, since I seem to have gotten it working. Here's what I did:

  1. (Using blogger) log in and go to Layout -> Edit HTML
  2. Insert this code right before the </body> tag:
    <link href='http://alexgorbatchev.com/pub/sh/[VERSION]/styles/shCore.css' rel='stylesheet' type='text/css'/>
    <link href='http://alexgorbatchev.com/pub/sh/[VERSION]/styles/shThemeDefault.css' id='shTheme' rel='stylesheet' type='text/css'/>

    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shCore.js' type='text/javascript'/>

    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushCpp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushCSharp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushCss.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushJava.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushJScript.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushSql.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushXml.js' type='text/javascript'/>

    <script class='javascript'>
    //<![CDATA[
    function FindTagsByName(container, name, Tag)
    {
    var elements = document.getElementsByTagName(Tag);
    for (var i = 0; i < elements.length; i++)
    {
    if (elements[i].getAttribute("name") == name)
    {
    container.push(elements[i]);
    }
    }
    }
    var elements = [];
    FindTagsByName(elements, "code", "pre");
    FindTagsByName(elements, "code", "textarea");

    for(var i=0; i < elements.length; i++) {
    if(elements[i].nodeName.toUpperCase() == "TEXTAREA") {
    var childNode = elements[i].childNodes[0];
    var newNode = document.createTextNode(childNode.nodeValue.replace(/<br\s*\/?>/gi,'\n'));
    elements[i].replaceChild(newNode, childNode);

    }
    else if(elements[i].nodeName.toUpperCase() == "PRE") {
    brs = elements[i].getElementsByTagName("br");
    for(var j = 0, brLength = brs.length; j < brLength; j++) {
    var newNode = document.createTextNode("\n");
    elements[i].replaceChild(newNode, brs[0]);
    }
    }
    }
    //clipboard does not work well, no line breaks
    // dp.SyntaxHighlighter.ClipboardSwf =
    //"http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/clipboard.swf";
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
    //]]>
    </script>
The SyntaxHightlighter.config.bloggerMode = true; is used to be able to use line breaks in your code snippets with blogger.

If you go here you can select your [VERSION] and if you then go to [VERSION]/styles/ you can see some shTheme*.css files where you can select the theme you would like to use.

Tuesday, July 7, 2009

An IComparer

In .Net you can very easily create a special class to handle comparing of (custom) objects. All you have to do is implement the IComparer or IComparer interface and implement it's one simple function: Compare.

So write a class that implements it:
public class MyComparer : IComparer<MyObj>
{
public int Compare(MyObj x, MyObj y) {
// If, for example you're working with an int:
return x.IntProperty.CompareTo(y.IntProperty);

// If, perhaps, it is a string:
return string.CompareTo(x.StringProperty, y.StringProperty)
}
}
The value you return must be negative if x is less then y, 0 if x is equal to y or greater then 0 if x is greater then y.

This can of course be used with things like MyCollection.Sort(new MyComparer()), really handy if you have strange objects.

Thursday, July 2, 2009

SQL Null

I am seriously confused by whatever it is that makes SQL (At least PL/SQL and T-SQL) consider null in a completely different way then anything else.

If I write a query
SELECT *
FROM table1
WHERE column1 = 0
Then of course if column1 hasn't been filled yet it won't return anything since null != 0

Sooo, then why is it that this query
SELECT *
FROM table1
WHERE column1 != 1
Won't return anything at all either.

I understand that null is not really like anything else, but to exclude it when looking for something in a certain column seems odd to me, or am I missing something?