Thursday, 1 December 2011

C# Removing or deleting an element and its contents from xml using regex

I was performaing a code review the other day where i cam upon this code

doc = rover.data.ArtisteDataHelper.getCurrentEventShows(festivalId);
XmlNodeList list = null;
list = doc.DocumentElement.GetElementsByTagName("biography");
while (list.Count > 0) {
      list[0].ParentNode.RemoveChild(list[0]);
}

list = doc.DocumentElement.GetElementsByTagName("description");

while (list.Count > 0) {
     list[0].ParentNode.RemoveChild(list[0]);
}

this operation was being performed over a 7mb file, and took around 18 seconds to complete. So, I thought I would see how fast it can remove these nodes using regular expressions.

I came up with the following code. It was designed specifically to remove elements with cdata inside them, but you can write regex to do anything you want of course, the performance gains will still be the same.

string xmlstring = doc.InnerXml.ToString();
string xmlstringresult = Regex.Replace(xmlstring, @"<description><!\[CDATA\[((?:[^]]|\](?!\]>))*)\]\]></description>", "");
string xmlstringresult2 = Regex.Replace(xmlstringresult, @"<biography><!\[CDATA\[((?:[^]]|\](?!\]>))*)\]\]></biography>", "");
result = new XmlDocument();
result.LoadXml(xmlstringresult2);

Result:
WHILE LOOP: 18 seconds
REGEX: 0.41 seconds

Wednesday, 2 November 2011

Kindle Fire Cannot load volume misc

Hi,

I had a friend that bricked his kindle fire, so I installed CM7 on it today, while doing so I got this error

E: Cannot load volume \misc!

you might also see

md5 file not found

how do you fix this?

you dont, these errors are ok, just reboot the device after CM7 (update.zip) has installed,

even if you see the errors, when it reboots, it should load fine.

Hope that helped,

Paul

Wednesday, 12 October 2011

Ubuntu Unity desktop on vmware player



This will enable the 2d unity mode on ubuntu when using vmware player. 3d is not avaible yet.

add the repository:sudo add-apt-repository ppa:unity-2d-team/unity-2d-daily


update repository:sudo apt-get update


install unity 2d:sudo apt-get install unity-2d-default-settings


now, logout of ubuntu on your vm

click your login name on the ubuntu login screen

you should now be able to see that unity 2d as your operating system (in the bottom task bar, if it is not, then select it)

all done (see pic below)

one more note to say, you may want to install CompizConfig Settings manager as well to tweak your desktop post install. use the command below and then look for CompizConfig in applications.sudo apt-get install compizconfig-settings-manager


.

Ubuntu - Install flash on chrome oct 2011

sudo apt-get install chromium-browser flashplugin-installer

Tuesday, 20 September 2011

Perform a URI check in PowerShell using WebRequest

Hi,

here is how to write a url checker in powershell.. enjoy[csharp]

Set-ExecutionPolicy RemoteSigned
$logpath = "C:\powershell logs\"

#build filename from parts
$outputfile = "{0}\{1:dd.yyyy.MM-hh.mm.ss}-site_response.txt" -f $logpath, $(Get-Date)

$sitelist = Get-Content C:\install\psscripts\sites.txt

Foreach($url in $sitelist) {
    $request = [net.WebRequest]::Create($url)
    $response = $request.GetResponse()
    $content = $response.ResponseUri
    $response.ResponseUri, $response.LastModified, $response.StatusCode | format-list | Out-File $outputfile -append
    $response.Close()
}

Thursday, 1 September 2011

Check Mail Server Using Telnet on windows command line

Hi,

I had someone ask today how to check if a mail server was working. So here is how to do it using telnet from the command line.

The idea here is that you know the mailserver domain, and you know a valid email address that can send from that domain.

Open your command window and type telnet. If you get an error, open control panel, click programs, then click "turn windows features on or off"

In the box that pops up, select the telnet options. Let it install, close you command window and re-open it then type the following:

telnet MAIL_SERVER_NAME 25 
EHLO google.com 
MAIL FROM:valid@emailaddress.com 
RCPT TO: me@myaddress.com 
DATA 

Subject: test message from server name 

This is a test message you will not see a response from this command. 
QUIT


You should receive the mail. 

If any of the above commands produce an error, something is wrong. 

thanks, 

Paul

Monday, 8 August 2011

Install Sun Java on unbuntu 10.x and newer

I got this answer from stackoverflow, but there are about another 20 or so answers on there and I keep having to sift through them all, so here is what worked for me:

sudo nano /etc/apt/sources.list

# uncomment the two lines referring to "partner"

sudo apt-get update

sudo apt-get install sun-java6-jre sun-java6-bin sun-java6-jdk

that should work..

Paul