Riaan Lehmkuhl's Blog

Subversion, Progamming, Tips & Tricks and whatever else springs to mind.
20Aug

Clone of the Windows shell "start" command for Nautilus in Ubuntu

20 August 2010 11:33 by Riaan Lehmkuhl

If you used the Windows shell a lot, you would likely have used the "start" command to launch an explorer window from the command prompt. The same can be easily done with Nautilus in Ubuntu. Create a shell script with the following content (in my case /opt/bin/browse.sh):

echo "nohup nautilus $1 2> /dev/null > /dev/null &" > /opt/bin/browse.sh
nohup is used so that the new process runs in the background and all output is discarded.

Make the file executable:

chmod ug+x /opt/bin/browse.sh

To make the script accessible you can do one of two things:
Either add an alias to your .bashrc file

echo "alias browse='/opt/bin/browse.sh'" >> ~/.bashrc

or Add a symbolic link to the /usr/bin directory:

sudo ln -s /opt/bin/browse.sh /usr/bin/browse

Usage: browse [target-directory]

Be the first to rate this post

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

Fix Apache "Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName" Error on Ubuntu

20 August 2010 10:44 by Riaan Lehmkuhl

After a fresh install of Apache2 on Ubuntu 10.04 you will likely see the error message when Apache starts:

Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

To fix it, you need to edit the httpd.conf file. By default it will be blank. Open the terminal and type the following command:

sudo echo "ServerName localhost" > /etc/apache2/httpd.conf

Finally restart the Apache server:

sudo apache2ctl restart

To check the status of Apache:

sudo service apache2 status

Be the first to rate this post

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

Convert XML elements and attributes to lowerCaSe using awk

13 August 2010 21:50 by Riaan Lehmkuhl

Install xmlstarlet (download from http://xmlstar.sourceforge.net/ or on ubuntu sudo apt-get install xmlstarlet).

Let's look at a simple XML file (menu.xml):

<BREAKFAST_MENU>
<FOOD NAME="Belgian Waffles" PRICE="$5.95">
<DESCRIPTION>two of our famous Belgian Waffles with plenty of real maple syrup</DESCRIPTION>
<CALORIES>650</CALORIES>
</FOOD>
<FOOD NAME="Strawberry Belgian Waffles" PRICE="$7.95">
<DESCRIPTION>light Belgian waffles covered with strawberries and whipped cream</DESCRIPTION>
<CALORIES>900</CALORIES>
</FOOD>
</BREAKFAST_MENU>

Convert the XML to PYX:

xmlstarlet pyx menu.xml > menu.pyx

The new file will now look like this:

(BREAKFAST_MENU
-\n\t
(FOOD
ANAME Belgian Waffles
APRICE $5.95
-\n\t\t
(DESCRIPTION
-two of our famous Belgian Waffles with plenty of real maple syrup
)DESCRIPTION
-\n\t\t
(CALORIES
-650
)CALORIES
-\n\t
)FOOD
-\n\t
(FOOD
ANAME Strawberry Belgian Waffles
APRICE $7.95
-\n\t\t
(DESCRIPTION
-light Belgian waffles covered with strawberries and whipped cream
)DESCRIPTION
-\n\t\t
(CALORIES
-900
)CALORIES
-\n\t
)FOOD
-\n
)BREAKFAST_MENU

Now we need to convert the lines beginning with "(" and ")" to lower case, and the first word of the lines beginning with an "A" (except the first "A").

cat menu.pyx | awk '{if (/^\(/) print tolower($0); else if (/^\)/) print tolower($0); else if (/^A/) print substr($0, 1, 1) tolower(substr($0, 2, index($0, " ")-1)) substr($0, index($0, " ")+1); else print $0; }' > menu.tmp

We now have the converted PYX file and this can be convert back to XML

xmlstarlet p2x menu.tmp > menu.xml

That's it, we have the converted XML file:

<breakfast_menu>
<food name="Belgian Waffles" price="$5.95">
<description>two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food name="Strawberry Belgian Waffles" price="$7.95">
<description>light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
</breakfast_menu>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
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 control, after adding a new row, and clicking away, the new row just disappears without any visible error.

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.
To find out if this is the cause of yoyr issue, put a break point in the DataError event handler. Even though the error might have beeen 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 2 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

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

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

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