10 June 2008, early morning
I haven’t had to write a Java program in ages. I think the last one I wrote was for CS341 (Algorthims), which would have been sometime in the Winter of 2002. After Algorithms all the courses I took used C++ — or were all about the math. Java looks a lot like C++, but the similarities end pretty quickly. The last time I wrote Java code it was all vim and the command line. Apparently that’s not the way people do things anymore. I’m downloading Netbeans – ever so slowly – now. I don’t think I’ve used an IDE since I was in high school. (Turbo Pascal, light of my life, fire of my loins. My sin, my soul.) I’m not a big fan of IDEs. I think they can sometimes hide too much of what is going on from the developer. With something like C++, I think it’s important to know how to cobble together a Makefile, and understand dependencies and the like. That said, I’m also not a big fan of doing crap work the computer can do for you. I’ll have to see how Netbeans works out.
[3] Code
9 May 2008, terribly early in the morning
Tyler mentioned on his blog, in passing, that one reason he likes jQuery more than Prototype is that the formers syntax is a bit object-oriented.
prototype has syntax which strikes me as antithetical to OO principals. for example, Element.hide(‘comments’) instead of $(’#comments’).hide().
I was thinking about the above while writing some Python code at work. I now prefer Ruby to Python, but it took a little while for me to warm up to Ruby. Ruby has a very terse syntax, and there is a lot of room in the language to write programs that look like that are composed of magic and pixie dust. (This is especially true when you look at Rails code.) Once you have written a few programs in Ruby it is a bit easier to see what’s up: where people have decided to leave brackets off, etc. Ultimately I prefer Ruby because if I want to know how long a list is, I can do so as follows: [1,2,3].length(). In Python, the same task is accomplished as follows: len([1,2,3]). The later just seems ass-backwards to me now.
(Python’s object-oriented programming support seems pretty half-assed, but I’m no expert in the language so my opinions of it may stem from my ignorance more than anything else. Still, what’s with all the self parameters. And __init__? Come on, you can do better than that.)
Code | Technology
6 April 2008, lunch time
It has been quite some time since I’ve written a plugin for textpattern. This plugin is quite simple; it will produce a list of the plugins you have installed in textpattern. To use the plugin, simply place the tag <txp:rsx_plugins_table /> in a form or page template. The plugin will produce a table, which you can style with CSS if you feel so inclined.
Download the plugin: rsx_plugins_table.txt. More information can be found at the Textpattern Forum thread for this plugin.
Update: I’ve added a new plugin that generates a definition list of your installed plugins instead of a table. This may be good for people who were trying to display the table in a very narrow space. I’m using this plugin right now on my about page. To use the plugin, simply place the tag <txp:rsx_plugins_list /> in a form or page template.
Download the plugin: rsx_plugins_list.txt
Update May 29th 2006: You can now decide to not show inactive plugins in the listing or table by using the show_inactive parameter.
Update Apr 6th 2008: You can now decide not to show the description field in the list or table by using the show_description parameter.
[3] Code
28 November 2007, early evening
Today I discovered MobileScrobbler, which I have to say is a very cool application. It’s a Last.FM client for the iPhone or iPod Touch. It works like the desktop scrobblers that integrates with iTunes, pinging the Last.FM servers whenever you play a new song on your iPod. This is actually a good use of the network connectivity of the iPhone. It’s neat watching your Last.FM page update while out and about with your iPod. (The only thing I don’t like about the program is how it’s poorly written. Not that I can really fault a program someone is giving away for free.) Programs like this make me want to learn Objective-C.
Code | iPhone
23 November 2007, lunch time
I’ve been reading up on Ruby in my spare time, while writing some C code at work. The differences between the languages is so stark. Here is a little problem I had at work recently.
Read the rest of this post. (333 words)
[2] Code | Nerd Alert
8 November 2007, early morning
I installed Git on a couple servers here at work and on my machine at home in order to give it a whirl. Git is a distributed version control system, famous for being developed by Linus Torvalds. It is currently in use to manage to Linux Kernel. Git is quite different than CVS and its successor SVN in that there aren’t any central repositories you pull your work from and submit your work back to. With Git, you can clone an existing repository and it becomes your own sandbox to play in; you can create branches and tags and do all sorts of stuff in your own repository, which no other developer needs to worry about. To actually share your changes, the work flow suggested is that you set up a ‘public’ clone of your repository which you submit your final changes to, and which other developers pull changes from. (You could also just share your actual repository.) Although the system is distributed, a group could still maintain a single ‘main’ repository that everyone pushes their changes to, and pulls from when they want a final build of a product. The big plus I’ve noticed so far is that since you don’t need to talk to a server all the actions you perform on your repository are very fast.
Apparently Git was tricky to use when it first came out. This doesn’t seem to be the case anymore. Setting up a repository is dead easy — far easier than the same task in SVN — and adding files, changing them, and committing your changes is also dead simple. Perhaps things get trickier when you move onto the more esoteric features in Git, but I suspect for most of the work a developer does it works well enough.
Linus gave a talk on Git at Google a little while back. I had never heard him speak at length before. It’s actually an entertaining talk, though he’s a bit of a jerk-ass. And by “a bit” I mean he’s a serious jerk-ass. (It’s been a good while since i’ve been around that sort of arrogance: high school was a long time ago.) I do have to say I find his style of talking kind of refreshing. Presumably he’s waiting for someone else to come along, call him a moron, and show him how he should be doing things.
Code
22 October 2007, late morning
I think every programmer should know how to use vi. It’s a small lean text editor that is usually found running on pretty much any Unix box you may find yourself in front of. I’m not saying you should know all the ins and outs of vi, but you should be able to start typing away if need be. I also think every programmer should know enough about Emacs that they can quit the program if they ever open it by accident. (FYI: Control-X Control-C will do the trick.)
[2] Code
12 September 2007, early morning
The placement of braces is a very contentious issue. People can get quite passionate about their placement.
Read the rest of this post. (198 words)
[7] Code
9 August 2007, terribly early in the morning
When programming, related functionality should be grouped and declared in their own header files, with definitions of functions in their own source files. Dividing your source code neatly in this fashion allows code that requires this functionality to (ideally) #include just the definitions it needs, and no more. You should be able to look at the #include directives in source file and header files and understand the dependencies of the code contained within; you should be able to see the relationships between the functions in your program. If you are lazy about the file structure of your source this becomes difficult. Don’t be lazy.
[ed. I think i’ll make this into a bigger post on how to clean up messy projects.]
Code
2 August 2007, mid-afternoon
This is a brief guide for those who want to build and install Git under MacOS X. The install process is fairly straightforward. The only hiccup is that the development environment for MacOS X doesn’t come bundled the Expat XML Parser. I’m not sure who these instructions will be helpful to, as most people bothering to install Git probably know what they’re doing.
Read the rest of this post. (612 words)
[24] Code
2 August 2007, early morning
I started using del.icio.us links back in May 2004. At the time I didn’t post links to this site the way I do now, inline with larger blog entries such as this. Interesting things I found on the net would get their own little blog post, regardless of how long or short that post might be; I wasn’t fond of doing things this way. Shortly after I started using del.icio.us, I began posting the links from there on the links page here. The page was populated with my last 10 or 20 links on del.icio.us, in addition to the links that are currently there. I also wasn’t too happy with this scheme, since it forced people to browse to another page to check for new links. That solution was short lived. When I started posting links here inline with my posts, I also started cross-posting those links to del.icio.us. This worked seamlessly till August 9th 2006. By this time I had really stopped checking my del.icio.us links page to see it was being updated properly, so I didn’t notice things had stopped working till some time in December. del.icio.us had changed its API and I hadn’t noticed.
Recently Jody mentioned he wished I posted my links to del.icio.us. (He is a lot more creative with the way he uses del.icio.us than I am.) Up until this time, no one had really said anything about the loss of my links on del.icio.us. I had really only been cross-posting for the sake of doing so. It was a programming exercise and that’s about it. Yesterday, I sat down and tried to figure out what had changed between del.icio.us and my script. The details are short and boring, but it didn’t take too long to fix things. My links are now being cross-posted to del.icio.us again.
A side note on PHP, and languages that let you pull variables out your ass: declaring a variable before you use it is a good thing. For example, in Pascal I wouldn’t end up with a bug like $title = urlencode($tittle);, which left me wondering why $title is empty when you urlencode it. Maybe i’m just a sucker.
[1] Weblogs | Code
22 March 2007, early morning
A function object is any object that can behave like a function. A function object is commonly referred to as a functor, because function object takes too long to both say and type. In C++, we implement functions by creating classes that override operator(); syntactically, this makes a function call and a call to the member function operator() of the functor identical. Functors are used throughout the STL.
There are countless places where the STL requires you provide it with some code so that the generic task it aims to solve can be tailored to solve your specific task. Consider the STL set. When you instantiate a set you must provide the STL with information on how to sort the elements within it. (This class is implemented as a balanced-binary tree, and as such, needs to know how to keep the elements within it sorted.) You tell the STL how to sort your elements by supplying a function object that when given two elements from your class returns true when the first is “less than” the second — you define what it means for one object to the less than another.
This sort of behaviour would be implemented in C using call-back functions: supplying pointers to the functions you want some block of code to use. You can think of functors as the evolution of call-back functions; being proper classes, functors can encapsulate functionality nicely. Since functors do everything call-back functions do and more you should probably use them over call-back functions, more often not.
[1] Code
20 February 2007, terribly early in the morning
Today while reading about auto_ptr’s — a topic for another day — I saw the function declaration/definition ~auto_ptr() throw() { delete ptr; }. I thought to myself, “What the hell is that throw() all about?” C++ can be a strange and esoteric language. Keywords get reused often, and mean different things depending on their context. Clearly this had something to do with exceptions, but what? After looking in my giant tome of C++ knowledge I had an answer. In C++ you can be explicit about what exceptions a function may throw. You do this by listing the exceptions within the parentheses following the throw keyword, which you include after the functions name. I have very vague memories of this being discussed in CS 246, though I can’t be certain it was. Anyway, I took CS 246 a bajillion years ago. throw() corresponds to a guarantee the function throws no exceptions. If you don’t include the throw keyword when declaring a function, then the function can throw any exceptions. In Java this is actually required behaviour: if your function throws an exception, you must list the exceptions thrown using the throws keyword. I haven’t had to program in Java in ages.
[1] Code
1 February 2007, early morning
You can use the sizeof operator in C and C++ to find out the size (in bytes) of a type. For example, if we have defined an array char array[10], then sizeof(array) will return the value 10. sizeof looks like a library function, but it isn’t one, it’s part of the definition of the language itself. The call sizeof array also returns 10. In most cases you can use or drop the parentheses around the operand for sizeof. The one exception to this occurs when trying to determine the size of a type. If a type name is to be the operand for sizeof it must be wrapped in parentheses; if you don’t do this, your program won’t compile. I usually drop the parentheses for calls to sizeof so I can tell at a glance if its operand is a type or a particular variable.
Code
29 October 2006, early morning
I’ve made a plugin to allow for front end editing.
Read the rest of this post. (406 words)
[16] Code
27 October 2006, mid-morning
The inline keyword is used in C++ as a hint to the compiler that a function you are writing should not be treated as a normal function, but should instead be treated as a macro. When the compiler encounters a call to such a function in the source code it is processing, it will replace that function call with the function’s source code, its body. This _should _ make your program faster. (A function call is a slightly involved process.) You inline a function by prefixing its definition with the keyword inline.
Read the rest of this post. (384 words)
[2] Code | Nerd Alert
12 May 2006, early morning
The sleep() function in C will delay your program for some number of seconds you specify. If you want to delay your program for some number of milliseconds, then clearly sleep() will not work. A good alternative to sleep() is the poll() function. Normally, this is used to check if there is data to be read from a group of file descriptors; it can also double as simple sleep command. poll() takes three parameters, an array of structures (struct *pollfd), the number of elements in the array (unsigned int), and the number of milliseconds to wait for data (int). By ignoring the first two parameters, you can use poll() as a higher resolution sleep(). Simply set the first two parameters to 0 when calling the function, and set the timeout to be however many milliseconds you wish to delay your program. I use this when writing simple simulators at work, and it works well enough.
[6] Code
23 March 2006, early evening
While upgrading to the latest version of Textpattern, I decided to clean up the way I implemented my Link-Log. The goal was to minimize the number of hacks needed to get things working. This article should explain what I have done, and should be as terse as possible.
Read the rest of this post. (169 words)
[1] Web Design | Code
28 February 2006, late evening
I’ve finally fixed the feed auto-discovery links on this site, and in doing so made a new plugin. This plugin will generate the auto-discovery links that you place in the head section of your HTML document. These are what feed-readers use to find the feeds available at your site. This plugin lets you specify whether you want the feeds to be “smart” (aware of what section and category they are in) or not. You can download the plugin here.
This plugin will produce audo-discovery feed links. There are two parameters:
smart – this can equal 1 or 0. If it is 1, then the feed links will be section and category aware.
flavour – this can equal ‘rss’ or ‘atom’. This is how you set what sort of feed link to produce.
Also, if you find my feeds are all really broken, please let me know.
Download the plugin: rsx_feed_auto_discovery_link-0.1.txt
Code | Weblogs
12 December 2005, mid-morning
I will write a proper post about the Referrer Filter Pepper shortly. Till then, briefly, the Referrer Filter Pepper is a plugin for the web statistics package Mint. This plugin is a more generic version of the Google Images Pepper I wrote for Mint 1.14.
Download the referrer filter pepper: funkaoshi-referrer-filter-pepper.zip
View the forum topic in the Mint Forum: [New Pepper] Referrer Filter
Code | Weblogs
15 November 2005, late evening
I’ve written a simple plugin to generate the meta information used by the google bot to decide whether to index a page or not. If the page generated is an individual article page, then the plugin will generate:<meta name="robots" content="index,follow">; if the page generated is anything else, the plugin generates: <meta name="robots" content="noindex,follow">.
Scribbling.net has a couple good articles on this which are worth checking out: Noindex and Help the Googlebot understand your web site
Download the plugin: rsx_search_engine_meta.txt
Update Nov 14th 2005: The plugin has been updated so it works correctly in TXP 4.0.2.
[1] Code
8 November 2005, late at night
This plugin will let you use two new conditional tags when building pages, <txp:rsx_if_next_section_different /> and <rsx_if_prev_section_different />. I use these tags to display my link-log mixed in with my regular posts. <txp:rsx_if_next_section_different /> is true if the current article’s section is different than the next article’s section. If the current article is the first article this condition is always true. <txp:rsx_if_prev_section_different /> is true if the previous article’s section is different than the current article’s section. If the article is the last article on the page this condition is always true. You can use <txp:else /> as you would expect.
Download the plugin: rsx_section_conditionals.txt.
Update: Damn it! I just noticed that you need edit your publish.php file to use this plugin, thus making it even more niche. You will need to add the following line of code to publish.php, after the line 766: $out['posted_rsx'] = $Posted;. (The previous line of code should be: $out['posted'] = $uPosted;.) We must do this because the plugin needs to have access to the database value Posted, which is not stored by default. (The unix timestamped version of the value is stored, but this is not much use.)
[2] Code
19 October 2005, late at night
I get a lot of hits from Google images. They end up cluttering up the referrer pane in my copy of Mint. The latest version of Mint lets you filter out domains you don’t want to see in your referrer pane anymore, which is nice and all, but it would still be nice to have these hits tracked somewhere. Being a tech-savvy guy, I thought I would try my hand at writing a plugin for Mint that does this very task, tracking hits from Google Images.
Read the rest of this post. (219 words)
[9] Code | Weblogs
5 January 2005, late evening
I’ve written plugin implements the idea discussed by Dunstan on his personal blog about displaying the time a post was published in a friendly manner. Simply place the <txp:rsx_time_of_day /> tag in an article template form and it will print out the time in a friendlier manner. For example, 12:00 will get turned into “lunch time”. I’ve basically copied his code verbatim. You can go and change what is output by editing the switch statement.
Download the plugin: rsx_time_of_day.txt
update: Bug Fix, $timeoffset was not declared as a global variable.
[9] Code
18 December 2004, late morning
I’ve modified the Wordpress Moveable Type import script so that it will import posts, comments, and primary categories from a moveable type export file into a textpattern database. I think that under the GNU license my changes are OK.
Read the rest of this post. (419 words)
[16] Code | Weblogs