Barry Dobson

RSS

Champions league final

Unlucky to Manchester United but the better team won. I don’t think there is any shame in losing to Barcelona. Awesome team.

N00b!

Hi, I thought I check out Tumblr as an alternative to paying for a hosted Wordpress blog. I don’t really blog a lot though!!

Creating iPhone Ringtones For Free In iTunes

Unfortunately Apple decided they would like to charge for people to be able to download ringtones for songs they already bought. Luckily there is a way you can use iTunes to get ringtones from any MP3 file for free, here’s how.

  1. Open iTunes and find the song you wish to make a ringtone out of.
  2. Play the song in iTunes. Take a note of the start and finish times of the section of the song you wish to use. (E.G. Maybe you want an instrumental section of a song that starts at 2:34 and ends at 2:51)
  3. Right click on the song in iTunes. Click “Get Info”. Find the tab that contains the options for start time and end time. Tick these two options and fill in the start and end time that you noted down from step 2 (I think this can get do milliseconds if you need to be precise). Click OK to close the dialogue.
  4. Now go into the iTunes preferences. On the first tab, click on “Import Settings”. Make sure the encoder is set to AAC (You can change this back to MP3 once this process is finished, but for creating ringtones it should be AAC). Close the preferences screen.
  5. Right click on the song again that you wish to make the ringtone from and select the copy to AAC option. After a pause you will notice a new song has appeared below the one you chose. It will have the same name/artist but it’s length will reflect that of the options you set in step 3. Right click the original song and un-tick the start and end time options.
  6. Right click the new version of the song and select to view in explorer copy the song to your desktop. Back in iTunes you can now remove the new song your library (select to move file to recycle bin, we don’t need this cluttering up your library).
  7. Once you have the new song file on your desktop you need to change the file extension. If you can’t see the file extension you need to enable it in folder properties. (In explorer select Tools > Folder options. In the View tab find the tick box for “Hide extensions for known file types” un-tick it. Select ok, you should now see the file extension, m4a, in this case).
  8. You need to change the extension from m4a to m4r. When you do this you will notice the icon change and it will now say ringtone.
  9. Drag the file back into iTunes. You will now see the ringtone option in your library and the new ringtone will be within that.
  10. Plug in your iPhone. In the sync options select to sync ringtones. When you perform a sync your ringtones will be sent to your iPhone. In the settings in your iPhone you will now have the option of selecting your new ringtone.

The process seems a bit complicated and painful, but after you have done it a couple of times it will only take a minute to create custom ringtones from any MP3 file in your library, and it’s free. If you prefer to use an editor like Sony Sound Forge for you editing needs (in order to play around with samples and get better accuracy when cropping) you can still go ahead and use it. Simply create your file in the editor and export it. Add it to your iTunes library and follow the instructions from step 4. Hope this helps.

PLS-00103: Encountered the symbol “” WHEN expecting one OF the following

I recently came across this error whilst developing stored procedures in oracle. The stored procedure will be built in Oracle but marked as invalid. Trying a re-compile will give you the above error.

The problem appears to be with Windows CRLF characters on line breaks. Oracle does not treat this as white space, instead it sees it as an empty string. In order to get round this problem, convert the CRLF characters to LF characters and Oracle should be happy.

Using VB.Net To Encrypt LDAP MD5 Passwords

When passwords are stored in an LDAP directory they are stored encrypted. LDAP supports different types of hashing, but I chose to use MD5.  The LDAP implementation is to use Base 64 encoding. Below is a simple function I use to convert the plain text password into a hashed string ready to be added to LDAP.

Public Shared Function EncryptPassword(ByVal value As String) As String

        Dim cryptProvider As New MD5CryptoServiceProvider
        Dim b As Byte() = Text.UTF8Encoding.UTF8.GetBytes(value)
        Dim encoded As Byte() = cryptProvider.ComputeHash(b)
        Dim hash As String = Convert.ToBase64String(encoded)

        Return hash

End Function

VB.Net HttpWebRequest Takes A Long Time On First Request

I have recently been using the HttpWebRequest object in .Net Framework 2 and 3.5. I’m using it to observe the timings of requests on a project and noticed some strange behaviour. The first time you call GetResponse it can take over 30 seconds to return the response, whereas subsequent calls to the same URL will result in much quicker responses. I have found the problem to be in the use of proxies. It tries to find a proxy to use on the first request. To fix this (unless you are using a proxy of course) set the Proxy property to Nothing

request.Proxy = Nothing
By doing this it no longer looks for the default proxy and will speed up requests.

Deleting LDAP Entries

Following on from my popular post on searching LDAP directories I thought I’d follow up with a simple piece of code that allows you to delete entries. There are two ways to remove an entry. The first way is to search for a node an remove it, along with all of its children. The second way is to search for a node and remove one or more of its children. Below I will demonstrate both methods.  

Dim dir As New LdapConnection(MySettings)

Using users As DirectoryEntry = dir.GetObject(MyQuery)
    For Each r As DirectoryEntry In users.Children
        users.Children.Remove(r)
    Next
    users.CommitChanges()
End Using
  Above shows us searching for a node then looping through each child and removing it. We could also examine the properties and delete based on that. If you want to delete a specific item its easier and more efficient to use the following method  
Using users As DirectoryEntry = dir.GetObject(MyUserQuery)
    users.DeleteTree()
    users.CommitChanges()
End Using
  In the above example we just search directly for a single node (user) then call the ‘DeleteTree’ method. It the entry we searched for had any children, they would also be deleted.   I hope this helps you out. Don’t forget to leave comments if this helped, or you need any more info, thanks.

Wordpress iPhone Application

I’ve just installed the Wordpress iPhone application on my iPod Touch, and am giving it a go. Have you used it? What do you think?

iPhone & iPod Touch Screen Shots

I don’t know if this is a new feature of the iPhone 2.0 software (I doubt it) but you can take screen shots from your iPhone or iPod Touch!

When your on the screen you want to capture just hold down the ‘Home’ key and press the ‘Sleep’ button. The screen will flash and the screen shot will now be in your pictures folder. The screen shots are stored in PNG format and can be transferred to a PC or Mac. This even works on the iPod touch. Once you have taken a screen shot the next time you plug the iPod into the computer you will see the iPod as a drive in your system. The pictures can then just be drag and dropped.

Working With LDAP In VB.Net

I wrote a post a while ago dealing with an error that VB can throw when dealing with an LDAP connection, you can find it here. Because this post has proved popular with people searching for the error code on Google, I thought I’d put together a quick post on using LDAP in VB.Net.

Simple Directory Search

To perform a simple query you can use the following syntax:

Dim results as SearchResultCollection

Using dir As New DirectoryEntry(connectionPath, principle, credentials, AuthenticationTypes.ServerBind)
	Dim s As New DirectorySearcher
	s.SearchRoot = dir
        s.Filter = (&(objectClass=groupOfUniqueNames)(cn=techSupport))
        s.SearchScope = SearchScope.Subtree
        results = s.FindAll
End Using
  1. First we are declaring a variable to hold our search results.
  2. Next we open up a connection to the LDAP directory. This is done by instantiating a DirectoryEntry object. The DirectoryEntry object requires the connection path in the form of a URL (LDAP://MyServer:10389/OU=subdir,O=parent”), the principle (“uid=myuser,ou=system”), credentials (“mypassword”), and the method of authentication (this will depend upon your LDAP directory).
  3. In order to search the directory we need to use the DirectorySearcher Object. We assign our DirectoryEntry object to the SearchRoot property, this will tell the DirectorySearcher where to base its search. The Filter property needs the details of what we are searching for, in this example we are looking for an entry whose ObjectClass is “groupOfUniqueNames” and CN is “techSupport”. The ampersand in front of the query tells the searcher this is an AND operation. The SearchScope property tells the searcher that we want to search the whole sub tree from the SearchRoot down.
  4. Lastly we return the results.

This is a very basic example of searching the directory. The directory is searchable on any property that an object may have, e.g. you may want to find all entries whose are inetOrgPerson and have a surname of smith. In that example your filter would be

(&(objectClass=inetOrgPerson)(sn=Smith))

Performing An Update

You can perform an update on a directory entry just like you can in a database. When performing an update it is important to remember an entry can have multiple properties of the same name. In other words the properties are in fact arrays. The following is an example of an update.

Public Sub UpdateUser(ByVal username as String, ByVal firstName as String, ByVal surname as String)

        Dim myUserDN As String = String.Format("{0}uid={1},{2}", _settings.LDAPUrl, username, _settings.UsersDN)
	Using u As New DirectoryEntry(myUserDN, _settings.Principle, _settings.Credentials, AuthenticationTypes.ServerBind)
	    AddUpdateProperty(u, "cn", firstName)
            AddUpdateProperty(u, "sn", surname)
 	    u.CommitChanges()
	End Using
End Sub

Private Sub AddUpdateProperty(ByVal r As DirectoryEntry, ByVal propName As String, ByVal value As Object)
        If r.Properties(propName).Count = 0 Then
            r.Properties(propName).Add(value)
        Else
            r.Properties(propName).Item(0) = value
	End If
End Sub

The above code shows two sub routines. Lets look at the first one, UpdateUser:

  1. First we construct the URL to the object we want. We supply the LDAP URL along with the path to the entry we want.
  2. Next we attempt to connect straight to our entry using the DirectoryEntry object. If the object is not found this line will throw a DirectoryServicesCOMException exception.
  3. Now we can go ahead and update the properties we need to change. This is done via a helper function to handle the fact the entry could contain none, one or many of the property.
  4. Lastly we call the CommitChanges method on the Directory Entry.

Performing An Insert

Performing an insert on the directory is very similar to performing an update. The code below shows how we can insert a new user type entry.

Using users As New DirectoryEntry(userDNRoot, _settings.Principle, _settings.Credentials, AuthenticationTypes.ServerBind)
    Using newUser As DirectoryEntry = users.Children.Add(String.Format("uid={0}", username), "person")

        ' add user required properties
        AddUpdateProperty(newUser, "cn", forename)
        AddUpdateProperty(newUser, "sn", surname)
        newUser.CommitChanges()
    End Using
End Using

Lets look at the code:

  1. We need to connect to the LDAP directory. This time we connect to the root DN of where we want to add our new entry. Think of this as XML, we are going to add a child entry to the root.
  2. Once we have a connection, we can use the Children.Add methods to create a new DirectoryEntry object. As a parameter we pass in the name of the entry.
  3. Using the same helper function we saw above in the update functionality we create the properties on the object (note that this is a shortened list).
  4. Once we have assigned all the properties we go ahead and commit changes.

You can download this sample project to check out some working examples.

If you have found the above article useful, have any comments or questions on it please leave a comment, and if you are a Digg user, don’t forget to give it a Digg, thanks.