# Posts

I am rereading some chapters in “Data Structures & Problem Solving Using Java”. I just finished reading chapter 17 on linked lists. Here is the singly linked list and sorted linked list from this chapter done in c#.

``````using System;
using System.Collections.Generic;

{
public class ListNode<T>
{
private T elem;
private ListNode<T> nextNode;

public T Element
{
get {return elem;}
set {elem = value;}
}

public ListNode<T> Next
{
get {return nextNode;}
set {nextNode = value;}
}

public ListNode(T theElement) :
this(theElement, null)
{
}

public ListNode(T theElement, ListNode<T> n)
{
elem = theElement; nextNode = n;
}

}

{
private ListNode <T> cur;

{
cur = theNode;
}

public ListNode<T> Current
{
get{return cur;}
set{cur = value;}
}

public bool IsValid()
{
return cur != null;
}

public T Retrieve()
{
if ( IsValid() )
{
return cur.Element;
}
else
{
return default(T); //null;
}
}

{
if (IsValid())
{
cur	= cur.Next;
}
}
}

{

/// <summary>
/// Construct the List.
/// </summary>
{
this.header = new ListNode<T> (default(T)); //(null);
}

public bool IsEmpty()
{
}

public void MakeEmpty()
{
}

/// <summary>
/// Return an iterator representing the header node.
/// </summary>
/// <returns>
/// </returns>
{
}

/// <summary>
/// Return an iterator representing the first node in the list.
/// </summary>
/// <returns>
/// </returns>
{
}

{

while(itr != null && !itr.Element.Equals(x))
{
itr = itr.Next;
}

}

/// <summary>
/// Remove the first occurrence of an item.  The code is not foolproof.
/// There may be two iterators, and one can left dangling if the other
/// removes a node.
/// </summary>
/// <param name="x">
/// A <see cref="T"/>
/// </param>
public void Remove(T x)
{
if(p.Current.Next != null)
{
p.Current.Next = p.Current.Next.Next;
}
}

/// <summary>
/// Return iterator prior to the first node containing an item.
/// </summary>
/// <param name="x">
/// A <see cref="T"/>
/// </param>
/// <returns>
/// </returns>
{

while (itr.Next != null && !itr.Next.Element.Equals(x))
{
itr = itr.Next;
}
}

public void Insert(T x, LinkedListIterator<T> p)
{
if(p != null && p.Current != null)
{
p.Current.Next = new ListNode<T>(x, p.Current.Next);
}
}

{
if (theList.IsEmpty())
{
System.Console.WriteLine("Empty List");
}
else
{
{
System.Console.WriteLine(itr.Retrieve());
}
}

System.Console.WriteLine("");
}
}

{
public new void Insert(T x, LinkedListIterator<T> p)
{
Insert(x);
}

public void Insert(T x)
{

//while(curr.IsValid() && ( x.CompareTo(curr.Retrieve() ) > 0) )
while(curr.IsValid() && (!EqualityComparer<T>.Default.Equals(x, curr.Retrieve())) )
{
}

base.Insert(x, prev);
}
}

class MainClass
{
public static void Main(string[] args)
{

int i;

theItr = theList.Zeroth( );
theList.PrintList(theList);

for( i = 0; i < 10; i++ )
{
theList.Insert( i , theItr );
theList.PrintList( theList );
}

for( i = 0; i < 10; i += 2 )
{
theList.Remove( i );
}

for( i = 0; i < 10; i++ )
{
if( ( i % 2 == 0 ) == ( theList.Find( i ).IsValid( ) ) )
{
Console.WriteLine( "Find fails!" );
}
}

Console.WriteLine( "Finished deletions" );
theList.PrintList( theList );
}
}

}

``````

# DreamHostAPI Nearing First Release

Looking through the code I have for the .NET dreamhost library I can now say that I have 100% of the private server API covered. Unless I have overlooked something, as far as I can tell I only have the Announcement list left to do.

This has been an interesting project and a nice introduction to a few simple aspects of .NET programming. Once the announcement API is finished I am not sure if I will continue with this project. If I do continue I will clean up the code somewhat and make the error reporting more useful.

The example user interface that I have been programming along with the library is also coming along. It does not implement all the library features yet but you can adjust your memory usage, list private server history and stats, list: users, domains, dns information.

Still to be done with the GUI is to is: save user information in a configuration file and load it when the program opens, setting most of the private server settings, announcements, and adding and removing DNS.

# Video Converter

A couple of months ago I sort of forked off a version of oggconvert and called it video2theora. Basically what I did was take the oggconverts projects glade file as a base and instead of using gstreamer I used ffmpeg to create a program that would allow converting video files to theora videos for use with the new firefox and opera video tags.

I hope this is only a temporary situation until gstreamer codecs on windows is in better shape. I attempted to get oggconvert to work on windows following the instructions on the website but gstreamer kept crashing. Hopefully this will improve in the future. Until then I will be using the gui based on ffmpeg.

# Python and Clutter Introduction/Tutorial

Check out http://majorsilence.com/pygtk_book for the most up to date version.

The best way to describe clutter is to quote its home page which states:

Clutter is an open source software library for creating fast, visually rich and animate graphical user interfaces.

Clutter can be integrated with many Linux technologies including GStreamer, Cairo a GTK+. It also is portable and runs on Windows and OSX, which allows for cross platform goodness.

But how is clutter used? This is actually very simple. Instead of creating a gtk.Window as in using PyGTK, with clutter, a clutter.Stage is created. And instead of using widgets, Actors are used. This is actually rather neat. We have Stages to do the work on with Actors that perform.

Some base Actors included with clutter are:

• Label - displaying Labels
• Rectangle - For creating Rectangles
• Entry - For entering text

A stage is created by using the clutter.Stage object like so:     stage = clutter.Stage()

The size of stage can be set:     stage.set_size(800, 400)

The title of the stage can be set using the stage.set_title() method:     stage.set_title(“Hey Hey, My First Clutter App”)

# Colors

The colour of a stage can be set using set_color() method and using the clutter.color_parse() method. The clutter parse method can take several different colour inputs including the colours as Text or HTML Notation.

The colour of a stage can be set:

stage.set_color(clutter.color_parse(“red”))     stage.set_color(clutter.color(“#FF0000”))

Or the colour may be set directly using the clutter.Color() using RGB colors.     stage.set_color(clutter.Color(255, 0, 0))

Colours can not just be applied to a stage as has been shown here but may also be applied to all the Actors that will be shown in the next section.

The clutter.Label Actor allows the programmer to put text labels anywhere on the stage. These are useful to display information to the user of the program. A small example of labels changing the font type and size of the letters. If no position is set it will default to placing the labels in the upper most left corner.

``````import clutter

stage = clutter.Stage()
stage.set_size(400, 400)

label = clutter.Label()
label.set_text("Clutter Label Text")
# If no position is given it defaults to the upper most left corner.