random technical thoughts from the Nominet technical team

Adding Nvidia drivers to Fedora Core 5

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted by andyh on Mar 24th, 2006

Fedora Core 5 has just been release and I thought I would be one of the first to upgrade my machine. The upgrade process was painless but adding the nvidia graphics driver proved near-impossible. The driver supplied by nvidia would not compile.

After a lot of searching I found this post which indicated that the problem was that the kernel wouldn’t allow non-GPL modules. This will be fixed in the next kernel release - but that didn’t help me. I needed a new kernel that included the fix - and I found one here. Once installed I also needed the kernel-devel rpm and then the nvidia driver would compile correctly - except that I was using the AMD64 driver from nvidia which needs to be patched before it works. Once patched then it all works!

asm/linkage.h

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted by jad on Mar 22nd, 2006

I have just spent a couple of hours trying to compile bristuff on CentOS 4.2. I had the kernel sources and kernel-devel rpm’s installed but I kept getting this error message

make[1]: Entering directory `/usr/src/linux-2.6.9'
CC [M]  /home/jad/BRI/bristuff-0.3.0-PRE-1l/qozap/qozap.o
In file included from include/linux/kernel.h:11,
from /home/jad/BRI/bristuff-0.3.0-PRE-1l/qozap/qozap.c:13:
include/linux/linkage.h:5:25: asm/linkage.h: No such file or directory

Eventually I realised that the /usr/src/linux-2.6.9/include/asm symlink didn’t exist because I had never rebuilt the kernel on this machine. That will teach me!

Running 32 bit apps on FreeBSD 6.0 AMD64

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted by jad on Mar 16th, 2006

You need to install the 32bit libs. To do this run the following as root

cd /usr/src
make build32
make install32
ldconfig -32 /usr/lib32

Now edit /etc/libmap32.conf to add any mappings you need to get your apps working.

Thanks to this thread for help getting this working.

Note: Dont forget the -32 in the ldconfig command. If you dont include this flag lookups for all the 64 bit libs on you system will fail and no commands will work!

Flock

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.5 out of 5)
Loading ... Loading ...
Posted by jad on Mar 15th, 2006

I have been playing with Flock recently. Flock is a browser based on the mozilla code base that allows easy blogging and sharing of bookmarks. This is what the folks at flock.com say about Flock

We believe that it should be easy for everyone to contribute to and participate on the web. To that end, we’ve started with integrating tools that make it easier to blog, publish your photos and share and discover things that are interesting to you.

Flock

This is my first post with flock and is a bit of a test.

Firefox/Mozilla Search Engine plugins

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted by graeme on Mar 10th, 2006

We have recently released a pair of search engine plugins for Firefox and other Mozilla-based browsers. These are both available from Mycroft (the homepage for the Mozilla search engine project.

Nominet Search allows searches of the Nominet website to be made from the search bar, whilst Nominet whois provides whois search functionality there. Please note that usage of the whois plugin is subject to the same terms as all use of the whois service.

These plugins will soon also be availble directly on the Nominet website as well.

Why no substitutionGroup for attributes in XML Schema?

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted by jay on Mar 9th, 2006

There is a feature of XML Schema called substitutionGroup that is a very neat way to extend schemas. Unfortunately this only applies to elements, not attributes. But before I get to that, here’s a basic explanation of substitutionGroup.

substitutionGroup for elements

In the following example I’ve defined an element <command> based on the type “commandType”. That type in turn is a sequence that so far contains just one element, which is an <abstractCommand>. <abstractCommand> in turn is of the type “abstractExtensionType”, which is defined as an empty type.

<!-- extract from schema1.xsd -->

<element name="command" type="schema1:commandType"/>

<complexType name="commandType">
<sequence>
<element ref="schema1:abstractCommand" />
</sequence>
</complexType>

<element name="abstractCommand"
type="schema1:abstractCommandType" />

<complexType name="abstractCommandType" />

Now none of that is actually usable at the moment because the <abstractCommand> element doesn’t actually contain anything useful. So all we can do is this following pointless code:

<!-- extract from document1.xml -->
<command>
<abstractCommand/>
</command>

However let’s assume this is part of a much larger document, in which case we use this as a place marker. Then we create our second schema, where we provide a concrete command. In this case we define a new element called “create”, which can be used in place of <schema1:abstractCommand> thanks to the substitutionGroup attribute. This is also based on a type that is derived from the type of the element that it is used in place of. In other words <create> is of the type “schema2:extCommandType”, which in turn is an extension of “schema1:abstractCommandType”.

<!-- extract from schema2.xsd -->
<element name="create" substitutionGroup="schema1:abstractCommand"
type="schema2:extCommandType" />

<complexType name="extCommandType">
<complexContent>
<extension base="schema1:abstractCommandType">
<sequence>
<any namespace="##other" maxOccurs="unbounded"/>
</sequence>
</extension>
</complexContent>
</complexType>

So, to finish off the explanation, we can now use all of this in a new document that uses the <schema1:command> element from the first file, but contains the “create” command specified in the second file.

<!-- extract from document2.xml -->
<command>
<create>
<things_to_create/>
</create>
</command>

The final point is that if we had wanted to prevent anyone from create an <abstractCommand> element , just to be tidy, then we could have defined it using the “abstract” attribute:

<complexType name="abstractCommandType" abstract="true" />

substitutionGroup for attributes

XML Schema does not actually support substitutionGroup for attributes, but if it did then what would it look like? Well a bit like this:

<!-- extract from schema1.xsd -->

<complexType name="operation">
<sequence>
<any namespace="##other" />
</sequence>
<attribute ref="schema1:opcode" use="required" />
</complexType>

<attribute name="opcode" type="schema1:opcodeType" />

<simpleType name="opcodeType">
<restriction base="token">
<enumeration value="request">
<enumeration value="approve">
<enumeration value="reject">
<enumeration value="withdraw">
</restriction>
</simpleType>

<!-- extract from schema2.xsd -->

<simpleType name="extendedOpcodeType">
<union memberTypes="schema1:opcodeType">
<simpleType>
<restriction base="token">
<enumeration value="dispute">
</restriction>
</simpleType>
</union>
</simpleType>

<attribute name="extendedOpcode" type="schema2:extendedOpcodeType"
substitutionGroup="schema1:opcode" />

<!-- extract from document1.xml -->

<operation extendedOpcode="dispute">
<blah />
</operation>

I’ve proposed this to the XML Schema working group to see if they might consider it for v1.1

Further reading

If you are interested in reading more about XML Schema or substitutionGroup then don’t bother looking these up in the XML Nutshell book as these only get a cursory section. Use a specialist XML Schema book instead.

Using 'acts_as_list' in Ruby on Rails

1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 3.8 out of 5)
Loading ... Loading ...
Posted by jay on Mar 6th, 2006

** UPDATE - The two sections at the end about :position and move_higher and move_lower have been updated after further research **

** UPDATE - Checked this with Rails 1.2 and the bugs still exist **
One very nice feature of rails is the easy way it can handle parent/child relationships where the children need to be treated as an ordered list, which it does through the acts_as_list interface. This is explained a bit in the otherwise excellent rails book but not enough to actually use it.

So just to recap, if you have a table of parent objects and a table of children objects and you want to represent the children as an ordered list, you add an ‘acts_as_list’ statement to you child model, specifying the parent scope:

class Parent < ActiveRecord::Base
has_many :children
end

class Child < ActiveRecord::Base
belongs_to :parent
acts_as_list :scope => :parent     # could have used :parent_id
end

Adding records
So the first question that comes to mind is how do I add a record to the list. A quick look at the documentation reveals a method called insert_at but no instructions on how to use it. Well it turns out to be pretty simple. All you do is create a new child record and save it, which automatically adds it to the end of the list. Then call insert_at on it, specifying the new position. For example (though I’m sure this can be simplified further):

@child = Child.new(params[:child])
@child.parent_id = @parent.id
@child.save
@child.insert_at(params[:new_position])

Retrieving the ordered list
Having done this I soon discovered that I was not getting the list in the order that I was setting the children, but rather the order in which I had added them. After much testing I realised the obvious missing code. The declaration of the parent model given in the book is incomplete. It should actually be:

class Parent < ActiveRecord::Base
has_many :children, :order => :position
end

Which then ensures that the generated SQL contains an ‘order by’ clause to return the list in the order of the position, which is the proper order for the list.

Starting index
When the records are added to the database by ActiveRecord the :position column starts at 1 and goes up from there. The book claims that the starting index for the list is 0, but there are a number of bugs with this. If you create the parent object then access it via the array interface child.parent[0] then it does work as the book says. However ‘move_higher’ and ‘move_lower’ don’t work correctly, as explained below.

The other confusing bit is when you use ‘insert_at’, where the starting index is actually the position you add the first record at. So if you add a record and then move it to position 1 using the ‘insert_at’ then ActiveRecord does not complain and from that point on your list has a starting index of 1 not 0. Though in practice you don’t need to do that as the default for ‘insert_at’ is position = 1. Interestingly you can even insert a record at position -1 and it all works as expected.

move_lower and move_higher
The method move_lower is used to move a child to a lower position in the list, in other words from position 4 to position 3. The counterpart is move_higher which is used to move a child the other way.

To get move_lower to work you need to substract two from the position. So if you want to move the child at position 4 to 3 then do

child[2].move_lower

and if you want to move the child at position 2 to 1 then do

child[0].move_lower

To get move_higher to work you need to add one to the position. (Don’t forget the array index is one less than the position). So if you want to move the child at position 3 to 4 then do

child[3].move_higher

and if you want to move the child at position 1 to 2 then do

child[1].move_higher

Recent Posts

Highest Rated

Categories

Archives

Meta: