development
Delicious blog released
As of today the first official release of Delicious Blog is available.
Delicious Blog is a Drupal module which emulates the Delicious.com daily blog posting tool since this tool does not work for Drupal. It uses the XML feed of your bookmarks to fetch the latest bookmarks and create a new node of your choice containing the links, much like on a WordPress blog.
For me, this has always been one of the things I missed the most and on my Drupal sites. Delicious.com uses the XML-RPC protocol to send out these blog posts, but the data send out seems to be rejected by the Drupal implementation of XML-RPC. Other solutions such as the FeedAPI or SimpleFeed module can only create one node per bookmark which is also not what I wanted. So, after almost 2 years of Drupal core and custom module development I finally made my first public module contribution. Hooray for me!
Adding new files to CVS without write access
In my previous post I talked about some useful Drupal CVS aliases. During the Core patch review sprint this weekend! I noticed a problem with it: adding new files.
Normally new files are added to CVS using the command:
The problem is that this command fails without write access to the repository. Luckely there is a handy little tool called fakeadd which you can use to edit the CVS entries file and let it look like the new files have been added to the repository. The patch creation function also changes by adding the -N option.
cvs -q diff -uNRp . | grep -v "^\?" > /home/jensen/Desktop/jsomers_$1_$2.patch
}
Drupal CVS bash commands
I thought I'd share these Drupal CVS bash commands I regularly use when creating patches. You can simply copy paste them into your ~/.bash_aliases file. All commands are expected to be executed from a Drupal CVS checkout folder.
cvs -q diff -uRp . | grep -v "^\?" > /home/jensen/Desktop/jsomers_$1_$2.patch
}
drupal_update() {
chmod u+w sites/default # Make folder writeable
cvs -q update -dPC # Perform update and restore from repository
chmod u-w sites/default
find . -name '.#*' | xargs rm -f # Remove backup files
}
alias dpupdate='drupal_update'
alias dppatch='drupal_create_patch'
The dpupdate command will make the sites/default folder writable, perform an update and restore locally changed files to the latest repository version, remove the write permission from the sites/default folder and remove any backup files created by the update command.
The dppatch command will create a patch. Modify it to your needs. When calling this command I specify 2 parameters, the first is usually the issue numbers and the second one is my patch number. Hence using the command
will create a file called jsomers_1000_2.patch and place it on my Desktop.
Adding descriptions to enumeration values
I was implementing a C++ DLL wrapper in a C# application today and I used quite some enumerations. For debugging purposes it's always nice to print out a string or a description of the enumeration value instead of 0, 1, 252 or DEVICETYPEFOO. The problem is that we can't override ToString(). Luckily for us functionality to achieve this can be created quite easily and very generic so we don't need to create large functions per enumeration type filled with switch-case statements or if-clauses.
We start off by creating a very simple and straightforward class which will hold the description of the enumeration value.
- class Description : Attribute
- {
- public Description(string text)
- {
- this.Text = text;
- }
- public string Text { get; private set; }
- }
This allows us to add the Description attribute to the enumeration values. If we don't specify the description attribute the ToString() function will be used. In this case it will print out GRANNYSMITH or JONATHAN.
- public enum Apples
- {
- [Description("Granny Smith")]
- GRANNYSMITH = 0,
- [Description("Jonathan")]
- JONATHAN,
- }
The last thing we need is a function which will convert the enumeration value to the corresponding description. Don't forget to add a using statement for the System.Reflection namespace.
- static public string GetEnumDescription(Enum en)
- {
- Type type = en.GetType();
- MemberInfo[] memberInfo = type.GetMember(en.ToString());
- if ((memberInfo != null) && (memberInfo.Length > 0))
- {
- if ((attributes != null) && (attributes.Length > 0))
- {
- return ((Description)attributes[0]).Text;
- }
- }
- return en.ToString();
- }
All we need to do is call the GetEnumDescription function.
- Apples apple = Apples.GRANNYSMITH;
- Console.WriteLine(GetEnumDescription(apple));
Moving to NetBeans
I have been using Eclipse PDT for my PHP development on Windows. (And on Linux too, I use Vim for quick and small changes but for the entire project I prefer a complete IDE package.) Apart from missing a decent auto-format feature I quite like it.
Unfortunately Eclipse still suffers from the same problems I encountered when I used it for Java development at school. It's bloated and requires a lot of memory slowing down my computers.
At the end of 2008 NetBeans 6.5 has been release with what seemed to be decent PHP support. Last week I made the change. The only thing I was missing was the ability to define a variable type within a comment.
Example:
- <?php
- /* @var $player Player */
- $player = getNextObject();
In Eclipse this would allow me to use code completion on the $player variable which would come in handy when the object has a few dozen functions and properties. It seems I wasn't the only one missing this and it has been introduced into the next NetBeans version.
If you are looking for an easy cross-platform PHP IDE I can only advise you to give it a try!
Miscrosoft C Implementation Weirdness
After over an hour of debugging 10 lines of code today I came to the conclusion that there is a difference between the implementation of strlen() in C on Windows using the compiler shipped with Visual Studio and GCC on Linux resulting in different return values because some characters are included and others are not.
Over. An. Hour.
Can't they get anything right?
