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
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.6 by 10 people

  • Currently 2.6/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
22Jul

Moving from Blogger to BlogEngine.NET

22 July 2008 02:42 by Riaan Lehmkuhl

I just moved my blog from Blogger to BlogEngine.NET. I done this for various reasons, but mainly because I'm a control freak.

Although I could have used the "blog.importer.application" provided by BlogEngine.NET, I did the export and import manually to have full control of the process.

Normally when moving domains the best way would of course be to setup 301 redirects, So my new blog to keep rankings etc. but Blogger has made that impossible.

I searched for ways for just forwarding all the requests to the Blogger blog to my new blog and found many posts on moving from Blogger to Wordpress. So this post just includes the specifics for BlogEngine.NET.

The main two sources I used was:

I wanted my old blog to stay up with posts intact so that people that has bookmarked it or any posts can still find what they are looking for and because read this post: why-you-should-never-delete-your-blogger-blogs.

The Walkthrough:

(Remember to replace "YOUR_NEW_BLOG_DOMAIN_HERE" with your blog's address.)

  • Setup the auto redirect:
    Log into your Blogger account, navigate to the "Layout" tab and click on "Edit HTML". In the template editor put the following in the <head>...</head>:
    <meta content='5;url=http://YOUR_NEW_BLOG_DOMAIN_HERE/' http-equiv='refresh'/>
    This will handle the front page redirection of the blog.
  • To let the users know that your blog has moved, and that they will be redirected, add a message to the page:
    <div style='position: absolute; top: 30px; left: 30px; border: solid 2px #333; color: #000; background-color: yellow; padding: 5px; width: 400px; z-index: 5; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: large;opacity: .4;filter: alpha(opacity=40);'>
    <p><strong>My blog has moved!</strong></p>
    <p>You should be automatically redirected in 5 seconds. If not, visit<br/> <a href='http://YOUR_NEW_BLOG_DOMAIN_HERE/'> <strong>YOUR_NEW_BLOG_DOMAIN_HERE</strong></a> <br/> and update your bookmarks.</p>
    </div>
    Place this right after the opening <body> tag.
    redirect
  • Because your new blog will contain all the posts from the old Blogger blog you need to avoid being penalised for duplicate content, add this to the "head" section as in point one...
    <META NAME="ROBOTS" CONTENT="NOINDEX, FOLLOW"/>
    <META NAME="GOOGLEBOT" CONTENT="NOINDEX, FOLLOW"/>
    NOINDEX FOLLOW tells the crawler not to index the Blogger page but to FOLLOW the redirect. NOINDEX will also instruct the crawler to drop any already indexed version of page.
  • To make the individual posts forward to their new counterparts a few things need to be done:
    1. On the Blogger control panel in “Settings -> Formatting”, change the Timestamps on posts to the MM/DD/YYYY format.
    2. Look for this code in the Blogger Template
    <b:section class='main' id='main' showaddelement='no'>
    and enter the following widget code under it (combine the three bits):
    <b:widget id='Redirector' locked='true' title='Blog Posts' type='Blog' >
    <b:includable id='main' >
    <b:if cond='data:blog.pageType == "item"' >
    <b:loop values='data:posts' var='post' >
    <div id='redirectorTitle' style='visibility:hidden' > <data:post.title/ > </div >
    <script type='text/javascript' >
    var new_domain = 'http://www.lehmkuhl.za.net/blog/post'
    function utf8_uri_encode( str ) {
       var high_code = new RegExp(/[\u0080-\uffff]+/);;
       new_str = str;;
       while( m = high_code.exec( new_str ) ) {
          new_str = new_str.replace(m,encodeURIComponent(m));;
       }
       return new_str;;
    }
    var title = document.getElementById('redirectorTitle').innerHTML;;
    // [INCOMPLETE] Keep percent signs that aren't part of an octet?
    title = title.replace(/<[^>]*?>/g,'');; // remove tags
    title = title.replace(/&.+?;/g,'');; // remove entities
    title = utf8_uri_encode(title);; // handle UTF-8 characters
    title = title.toLowerCase();;
    title = title.replace(/[^%a-z0-9 _-]/g,'');; // remove punctuation
    title = title.replace(/\s+/g,'-');; // turn spaces into hyphens
    title = title.replace(/-+/g, '-');; // collapse runs of hyphens
    title = title.replace(/^-+/g,'');; // remove prefixed hyphens
    title = title.replace(/-+$/g,'');; // remove suffixed hyphens
    var timestamp = ' <data:post.timestamp/ >';
    timestamp = timestamp.split('/');
    timestamp = timestamp[2]+'/'+timestamp[0]+'/'+timestamp[1];
    var new_page = new_domain + '/' + timestamp + '/' + title + '.aspx';;
    document.location.href = new_page;
    </script >
    </b:loop >
    </b:if >
    </b:includable >
    </b:widget >

    This will redirect the blogger post...
    http://someblog.blogspot.com/2008/06/some-blog-post.html
    ...to...
    http://YOUR_NEW_BLOG_DOMAIN_HERE/post/2008/06/28/some-blog-post.aspx

To see a working example visit my old blog at http://somethingsubversion.blogspot.com/.

Currently rated 3.0 by 5 people

  • Currently 3/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