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

Thursday 7 July 2011

add rvm function to .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

This loads RVM into a shell session.

Saturday 4 June 2011

installing rvm and linux defaults

this post is really just for me to remember some things that I wll come back and edit it as needed ..

apt-get install rubygems

apt-get install curl

apt-get install gitbash < < (curl -s https://rvm.beginrescueend.com/install/rvm)

apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev

Saturday 7 May 2011

migratordotnet - create initial database

and here you go..

Migrator.Console.exe SqlServer "Server=localhost;Database=DBNAME;Trusted_Connection?=True" MyMigrations.dll -dump "c:\temp\dump.cs"

Friday 8 April 2011

Can't connect to local MySQL server through socket mysql.sock

You may be getting this error after an update or install or mysql server.

there are lots of different suggestions on how to fix this on the web, most of them will not work.. what will work is killing the mysqld process then restarting it..

to do this, do the following:

ps -A

this will list all processes, find the id of any mysql processes, then in shell type:

kill 11514 (where 11514 is ps id)

run ps -A again and check there is no mention of mysql anywhere..

now run "service mysqld start"

this should start mysql and create the mysql.sock file you had issues with earlier..

hope it fixed it for you,

Paul

Tuesday 5 April 2011

Rake create and migrate test databases

here is your answer:

rake environment RAILS_ENV=test db:create

rake environment RAILS_ENV=test db:migrate

cheers,

Paul

Thursday 3 March 2011

The bundled mysql.rb driver has been removed from Rails 2.2

So.. been trying to get a legacy rails app working and had this error..

after googling for a while, most people got this fixed using a gem install mysql -- --with command, or by copying an installed dll to the ruby bin directory.

However, what fixed it for me was:

sudo apt-get install libmysql-ruby

if you stumbled upon this, i hope it helped!

Paul

Wednesday 2 February 2011

nltk corpora/ xx cannot be found

You may have just installed nltk and want to try a demo such as:[python]

>>> import nltk
>>> nltk.stem.porter.demo()


you may receive the error: "resource corpora/ not found"
this can be fixed by using the dltk package downloader

open your shell
start python
then type the following:[python]
>>>import nltk
>>>nltk.download()

this will open the nltk downloader where you can download everything you need.
fixed!

Monday 3 January 2011

PyYAML on Windows 7 64 bit (Python NLTK) PyYAML python required not found in registry

Catchy blog title huh?

So, I needed to use the Natural Language Toolkit. (http://www.nltk.org/)

To do this, following their instructions, you will need to download the following items:

NLTK: http://nltk.googlecode.com/files/nltk-2.0b9.win32.msi, http://nltk.googlecode.com/files/nltk-2.0b9.win32.exe

The problem is, when python installs it does not enter any registry keys. Then, when you try to install 
PyYAML, you will get the following error:

PyYAML python 2.6 required not found in registry

To fix this we need to enter the correct values in the windows registry. Follow these steps to do that:

click the start button, type "regedit", and click ok to open regedit. Enter the keys below:

To add a new key, navigate, in this case to HKEY_CURRENT_USER\Software\ then right click software and choose new->key then type the name

You dont need to add values unless they are shown below:
[HKEY_CURRENT_USER\Software\Python]
[HKEY_CURRENT_USER\Software\Python\Pythoncore]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6\InstallPath] 
Value: C:\Python26
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6\PythonPath]
Value: C:\Python26;C:\Python26\Lib\;C:\Python26\DLLs\

next time you try to install PyYAML it will detect the python installation, problem solved..

go mad ...