Riaan Lehmkuhl's Blog

Subversion, Progamming, Tips & Tricks and whatever else springs to mind.
16Dec

cat Command for windows

16 December 2009 10:24 by Riaan Lehmkuhl

The cat command is one of the most frequently used commands on Linux/Unix like operating systems. Needless to say it could also be very useful on your Windows system.

Here is the C# code to create your own cat command...

Program.cs:

using System;

namespace cat {
    class Program {
        static void Main(string[] args) {
            if (null != args && args.Length > 0) {
                foreach (string arg in args) {
                    if (System.IO.File.Exists(arg)) {
                        Console.Write(System.IO.File.ReadAllText(arg));
                        Console.Write(Environment.NewLine);
                    }
                }
            }
        }
    }
}

The usage should be mostly the same as with it’s Unix counterpart.

To learn more see The cat Command.

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
16Dec

Apache Click Framework PickList control client JavaScript via PrototypeJS

16 December 2009 10:04 by Riaan Lehmkuhl
/*
 * get a hook on the buttons (> or < or >> or <<) of a Click PickList control.
 * call in domloaded() passing the name of the PickList and a js callBack method to be envoked.
 * the callBack method should have one parameter to receive the clicked button element.
 * an additional attribute ('forid') is also set on the button element, 
 * which will contain the requested PickList name.
 *
 * DEMO:
 * The Java Click component...
public Form form = new Form("myForm");
public PickList myPicker = new PickList("myPicker", "My Picker");
@Override
public void onInit() {
    super.onInit();
    form.add(myPicker);
}
 * Now for the JavaScript...
function domloaded() {
    attachToPickListButtons("myForm_myPicker", demoCallBack);
}
function demoCallBack(el) {
	if (!(typeof(el.forid) == 'undefined')) {
		var id = el.forid;
		var directionClicked = el.value; // > or < or >> or <<
		var toSelected = null != directionClicked.match(">");
		var moveAll = null != (directionClicked.match(">>") || directionClicked.match("<<"))
		var plh = new pickListHelper(id);

		var toString = "id = '" + id + "'\n";
		toString += "directionClicked = '" + directionClicked + "'\n";
		toString += "toSelected = '" + toSelected + "'\n";
		toString += "moveAll = '" + moveAll + "'\n";
		toString += "SelectedList = '" + typeof(plh.getSelectedList()) + "'\n";
		toString += "UnSelectedList = '" + typeof(plh.getUnSelectedList()) + "'\n";
		toString += "HiddenList = '" + typeof(plh.getHiddenList()) + "'\n";
		alert(toString);

		if (!moveAll) {
            if (confirm("Just for fun, let's move ALL items to " + (toSelected ? "unselected" : "selected") + " \n(opposite direction you just chose).")) {
                plh.moveAll(!toSelected);
            }
        }
	}
}
*/
function attachToPickListButtons(id, fn) {
    $$("input[onclick^='pickListMove'][type='button']").each(function(field) {
        if (!(typeof(field.onclick) == 'undefined')) {
            var fieldOnclick = "" + field.onclick;
            if (null != fieldOnclick.toLowerCase().match(id.toLowerCase())) {
                Event.observe(field, 'click', function(event) {
                    var element = Event.element(event);
                    element.forid = id;
                    fn(element);
                });
            }
        }
    });
}
/*
 * a wrapper around a Click PickList control
 */
function pickListHelper(id) {
	var _selectedList = $(id);
	var _unselectedList = $(id+ "_unselected");
	var _hiddenList = $(id+ "_hidden");

	this.getSelectedList = function() {
		return _selectedList;
	}

	this.getUnSelectedList = function() {
		return _unselectedList;
	}

	this.getHiddenList = function() {
		return _hiddenList;
	}

	this.moveAll = function(toSelected) {
		// call pick list method from click control to do the heavy lifting
		var fromList = toSelected ? _unselectedList : _selectedList;
		var toList = toSelected ? _selectedList : _unselectedList;
		pickListMoveAll(fromList, toList, _hiddenList, toSelected);
	}
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
04Nov

Get DOS 8.3 short name with VbScript

04 November 2009 10:26 by Riaan Lehmkuhl
Create a new text file called shortname.vbs Open in notepad and paste the following code in it:
set fso = CreateObject("Scripting.FileSystemObject") 
strLongName = Wscript.Arguments(0)
strShortName = "Invalid File/Folder - (" & strLongName & ")"
Set fsoFile = Nothing
On Error Resume Next
Set fsoFile = fso.GetFile(strLongName)
if Err.number <> 0 then
Set fsoFile = fso.GetFolder(strLongName)
end if
if fsoFile is not nothing then
strShortName = fsoFile.ShortPath
end if
Wscript.Echo strShortName
Run the script using cscript:
cscript shortname.vbs "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"
You will then get the following output:
C:\PROGRA~1\Adobe\READER~1.0\Reader\AcroRd32.exe

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
23Feb

Windows.Forms Binding errors with .Net 2.0 (Part 4)

23 February 2009 20:53 by Riaan Lehmkuhl

The problem:
In a DataGridView, after adding a new row, and clicking away, the new row disappears.

The solution:
This is most likely caused by an error being raised due to a data input error. Im my case it was because of a non visible column not allowing nulls.
put a break point in the "DataError" event handler. Even though the error might be written to the row's ErrorText, it is never displayed because the row disappears.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
19Aug

MSTSC /console not working anymore

19 August 2008 21:13 by Riaan Lehmkuhl
When using the "Virtual Server Administration Website" to admin your Virtual Server 2005 R2 virtual servers one needs to be logged on to the console of the host server or you get a HTTP 500 Internal Server Error message. For this reason I've always used the mstsc /console command to log in to session 0 of the host server, but to my dismay this just didn't seem to work anymore.
I opened the command prompt and typed in mstsc /?. Lo and behold, the console option is gone:
---------------------------
Remote Desktop Connection Usage
---------------------------
MSTSC [] [/v:] [/admin] [/f[ullscreen]]
[/w: /h:] [/public] | [/span] [/edit "connection file"] [/migrate]
"connection file" -- Specifies the name of an .rdp file for the connection.
/v: -- Specifies the remote computer to which you want to connect.
/admin -- Connects you to the session for administering a server.
/f -- Starts Remote Desktop in full-screen mode.
/w: -- Specifies the width of the Remote Desktop window.
/h: -- Specifies the height of the Remote Desktop window.
/public -- Runs Remote Desktop in public mode.
/span -- Matches the remote desktop width and height with the local
virtual desktop, spanning across multiple monitors if necessary. To span
across monitors, the monitors must all have the same height and be aligned
vertically.
/edit -- Opens the specified .rdp connection file for editing.
/migrate -- Migrates legacy connection files that were created with
Client Connection Manager to new .rdp connection files.
---------------------------
OK   
---------------------------
I noticed the /admin switch, which seemed to do the trick.
After some more research I've found that this was apllied with XP SP3 and supposed to be because of some new security features in Windows Server 2008 and Vista SP1. Due to this fact this trick won't work on these.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
04Aug

RE: Updated SyntaxHighlighter Extension for BlogEngine.NET

04 August 2008 23:59 by Riaan Lehmkuhl

There seems to be a conflict between the SyntaxHighlighter javascript and the BlogEngine.NET Widget Zone administration drag-and-drop javascript. When the SyntaxHighlighter Extension is enabled, the drag-and-drop in the Widget Zone does not work although there doesn't seem to be any javascript errors.

Luckily we don't need to rearrange the widget zone that often. So when you need to do that just disable the SyntaxHighlighter Extension temporarily, rearrange your widgets and enable the SyntaxHighlighter Extension again.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
27Jul

Updated LinkList widget for BlogEngine.NET

27 July 2008 15:51 by Riaan Lehmkuhl

Here's an updated LinkList widget that allows for changing the order of items in the list with a 'Move Up' command.
Also updated the txtUrl control's ValidationExpression to cater for urls starting with '/', '~/' and 'mailto:'.

LinkList  

Download the updated LinkList widget or get the patch files from CodePlex to apply to your working copy.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
27Jul

Grass And Sky BlogEngine.NET 1.4 template

27 July 2008 15:09 by Riaan Lehmkuhl

As promised in a previous post here is the Grass And Sky template adapted for BlogEngine.NET 1.4

Grass And Sky website template 

This theme is not a 100% complete yet, but maybe you can make it work for yourself.

Download and give it a go.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
27Jul

Updated SyntaxHighlighter Extension for BlogEngine.NET

27 July 2008 12:52 by Riaan Lehmkuhl

Looking for ways to add syntax highlighting to my blog I came accross Scott Dougherty's article for Adding SyntaxHighlighter to BlogEngine.NET and then Chris Blankenship's SyntaxHighlighter Extension for BlogEngine.NET.

I really like his extension, but I wanted the installation path and loaded language scripts to be configurable so I've updated his extension to use the BlogEngine Extension Manager.

  1. Download SyntaxHighlighter
  2. Extract and upload the SyntaxHighlighter code to your blog (I renamed the dp.SyntaxHighlighter directory to just SyntaxHighlighter)
    eg. ~/extensions/SyntaxHighlighter
  3. Download, extract and upload the SyntaxHighlighter.cs file into the ~/App_Code/Extensions directory

    NOTE:
    If you already had the SyntaxHighlighter Extension from Chris Blankenship installed, you might have to delete the "~/App_Data/datastore/extensions/SyntaxHighlighter.xml" file before the new extension settings will be loaded.

  4. Login to your blog and go to "Extensions" under the "Control panel"
  5. Click on "Edit" next to the "SyntaxHighlighter" extension and configure as required (see preview below)

SyntaxHighlighter Extension Manager

For a list of supported languages see the syntaxhighlighter wiki

For Windows Live Writer support:

  1. Download and install Windows Live Writer and the SyntaxHighlighter for Windows Live Writer plugin (Requires .Net 3.5 framework)
  2. Update the blog style (In Live Writer under the "Weblog" menu then "Edit Weblog Settings..." and click on the "Editing" tab)

NOTE:
If you have custom ordered list item styles in your theme, you might have to make a small change to the SyntaxHighlighter CSS. In my case I've got a custom list-style-image so I had to make the following change in the "SyntaxHighlighter\Styles\SyntaxHighlighter.css" file:
in the following bit, I added list-style-image: none;:

/* clear styles */
.dp-highlighter ol,
.dp-highlighter ol li,
.dp-highlighter ol li span 
{
margin: 0;
padding: 0;
border: none;
list-style-image: none;
}
Here's the diff:
Index: /BlogEngine/BlogEngine.Web/extensions/SyntaxHighlighter/Styles/SyntaxHighlighter.css 
=================================================================== 
--- /BlogEngine/BlogEngine.Web/extensions/SyntaxHighlighter/Styles/SyntaxHighlighter.css 
+++ /BlogEngine/BlogEngine.Web/extensions/SyntaxHighlighter/Styles/SyntaxHighlighter.css 
@@ -17,6 +17,7 @@
margin: 0;
padding: 0;
border: none;
+	list-style-image: none;
}
.dp-highlighter a,

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
23Jul

Firefox 3 Bug: invalid 'in' operand this._sandbox

23 July 2008 19:27 by Riaan Lehmkuhl

If you are getting the following JavaScript error in Firefox 3, here is a quick workaround:

Error: invalid 'in' operand this._sandBox Source File: file:///C:/Program%20Files/Mozilla%20Firefox/components/nsProxyAutoConfig.js Line: 95
Open the file mentioned in your favourite text editor (one that can handle unix line endings; if you have nothing else, use WordPad), and seach for the this line:
if (!("FindProxyForURL" in this._sandBox))
   return null;
and wrap it in a try/catch block like this:
try {
   if (!("FindProxyForURL" in this._sandBox))
      return null;
} catch (e) { return null; }
Save your changes, and restart Firefox.

Although this is probably not the correct way to solve this problem, at least it helps to keep the 'Error Console' garbage free.

 

Currently rated 2.8 by 9 people

  • Currently 2.777778/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Riaan Lehmkuhl


Me, a disorder of the brain that results in a disruption in a person's thinking, mood, and ability to relate to others.

Recent comments

Comment RSS

Thingies

Calendar And Month List

<<  February 2010  >>
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567

View posts in large calendar

Disclaimer & Privacy

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Privacy:
We use third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

Most comments

Cool Quote

I know that you believe that you understood what you think I said, but I am not sure you realize that what you heard is not what I meant. - Robert McCloskey