Posted 476 days ago
Wrote a quick function today also to verify that the syntax of an email address is valid, using regular expressions.
^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$
This will match a userid containing letters, numbers, underscores, dots and hyphens, followed by an at sign, then a domain name containing letters, numbers, hyphens and dots, followed by a suffix of 2-to-4 characters.
Using this regex, I can ensure that the user has entered a potentially valid email address before attempting to send out a confirmation email.
Posted 476 days ago
Part of my new comment system for Blosxonomy includes an email verification system that requests the user to confirm their email before their comments will be displayed on the blog. To do this, I wrote a simple random-hex-code generator to build unique url's. When a comment is posted by a user with an unconfirmed email address, a random URL is generated using the random hex code, and emailed to that user.
Generating such codes in ruby is very simple, and often useful, so I thought I'd post the method I wrote to do it:
def generateUniqueHexCode( codeLength )
validChars = ("A".."F").to_a + ("0".."9").to_a
length = validChars.size
hexCode = ""
1.upto(codeLength) { |i| hexCode << validChars[rand(length-1)] }
hexCode
end
validChars is initialized to be an array containing characters 'A' through 'F', and '0' through '9'. I then append codeLength random characters from that array to the hexCode string and return it.
While a more robust implementation would validate uniqueness against the list of already generated IDs, the assumption is that these ID's are short lived, and the likelihood of generating repeats IDs given a sufficient length (I use 64) is miniscule.
Posted 477 days ago
Well after a months-long hiatus from doing anything even remotely related to Blosxonomy, I finally got around to implementing a simple user-confirmation system for the comments system.
Now, when you post comments to an entry, your email is verified against a list of authorized emails. If your email isn't in my list, a verification email is automatically generated and sent to you, containing a link. All you need to do is click the link to confirm your email, and voiala, your comment appears, and you're free to comment as much as you like.
Hopefully this simple step will significantly reduce the amount of comment spam I recieve on this site.
In other sad news, a simple typo in a bash script resulted in the accidental deletion of all comments in my database. *Oops*. Guess I should have made a backup.
Posted 893 days ago
Blosxonomy 0.7 will be up momentarily at Blosxonomy.com - I just finished upgrading timfanelli dot com to make use of it's new database support. Blosxonomy now has the option of storing entries in either the traditional Blosxom style files, or in its own database format.
The database offers significant performance improvements over the file system; especially when you're working with folksonomies. There was previously no way for me to generate my tag cloud and related links without parsing parts of entry entry file on my site; and with about 200 entries right now, my response times for a typical page request were very near 2.5 seconds.
With the new database schema in place, and a complete rewrite of the underlying folksonomy engine to make use of it, I'm looking at about 1 second response times, which is a significant improvement. I'd recommend that anyone who decides to switch to Blosxonomy start using it, but the Blosxom style entry support will always be there too :).
To facilitate the migration, Blosxonomy also now has a utility to convert your entries between the two formats, so you can move back and forth as you like. For now, it's also the easiest way to get new entries into the database - just make a Blosxom style post and import it. Similary, updating old entries can be achieved by exporting the entry, editing it as you would any Blosxom post, and then reimporting it -- a process which does not affect your timestamps :).
I have one or two more things to clean up, and then it'll be available for download over at Blosxonomy. Stay tuned!
Posted 893 days ago
I spent a little while tonight getting ramped up to finally implement a database layer for Blosxonomy, and discovered that getting Ruby DBI working was more difficult that I expected. In particular, it turns out my Mac had multiple versions of Ruby installed, resulting in mis-linked binaries that cause abnormal terminations when I tried to use DBI. The specific error I got was:
/usr/lib/ruby/site_ruby/1.8/powerpc-darwin8.3.0/postgres.bundle: [BUG] Bus Error
Here's what I did to resolve this error and get DBI working:
Cleanup your Rubies
OS X 10.4 ships with Ruby 1.8.2. I had also installed Fink, which installed Ruby 1.8.1. I don't recall if I caused it to do that, or if it was a dependency of something else. This was my first problem. You can check to see if you have them both installed by doing:
/sw/bin/ruby --version /usr/bin/ruby --version
Ideally, only /usr/bin/ruby will work, and /sw/bin/ruby won't exist. If this is not the case, you should remove the Fink installation. The latest version of Ruby DBI wouldn't link against Ruby 1.8.1, it would only link against 1.8.2 or 1.8.3. To remove Fink's Ruby, I did:
fink remove ruby18-dev ruby
This removed Ruby 1.8.1 and the development header files from your system.
Next, we'll upgrade to Ruby 1.8.3 - Download 1.8.3 Here, extract the tar bundle, and perform the following steps:
configure --prefix=/usr make sudo make install
I have XCode 2.2 installed, and use GCC 4.0 by default and did not have any problems. You shouldn't either. This will install the new Ruby over the old one, and also install the new development headers. Confirm that the installation was successful:
ruby --version
Should now show version 1.8.3
Install Ruby PostgreSQL
Download the latest snapshot PostgreSQL Ruby bindings from http://ruby.scripting.ca/postgres/. At the time of this writing, the latest snapshot is 20051127, which is compatible with PostgreSQL 6, 7 and 8. The installation is simple:
ruby extconf.rb \ --with-pgsql-include-dir=/path/to/postgres/includes \ --with-pgsql-lib-dir=/path/to/postgres/libs make sudo make install
You can omit the --with-pgsql... options if you have PostgreSQL installed in a standard location. I installed
PostgreSQL 8.1 using Fink, and did not need to specify these options.
Ruby DBI
Finally, we'll install the DBI library. You can download it from their Rubyforge project page. At the time of this writing, version 0.0.23 is the latest, released on May 20, 2004
Again, installation is very easy, just do:
ruby setup.rb config --with=dbi,dbd_pg ruby setup.rb setup ruby setup.rb install
--with=dbi,dbd_pg tells the config to prepare the DBI library, and the PostgreSQL driver. You can specify as many
plugin drivers as you like in that. Popular ones will include dbd_mysql, dbd_odbc and dbd_db2. Once
this step is complete, you'll be able to connect to your PostgreSQL databases using DBI.
A very very very short sample
Here's the quick sample I was using to test that DBI was properly installed. It's very simple and doesn't do anything at all, but it makes calls to DBI enough to have caused the error earlier.
require 'dbi'
dbh = DBI.connect('DBI:pg:databasename')
dbh.disconnect
Posted 906 days ago
I added a subtle feature to my blog this morning; my tag cloud now shuffles every hour. I did this by seeding the random number system using the current hour and shuffling the tags in my tagcloud, like so:
srand( Time::now.hour )
tags = tags.sort{ |a,b| rand() <=> rand() }
The result is that with each hour my tag cloud takes on a new form, and there will be 24 different combinations.
If you wanted to shuffle every hour and not repeat every 24 hours, you could also seed using the decimal representation of the current time rounded to the previous hour:
now = Time::now srand( ( now - (now.min * 60 + now.sec) ).to_i )
Posted 906 days ago
Ruby is a very powerful, fun, and expressive language - I thought instead of continuing my sometimes long winded Intro To XXX series this morning, I'd post a cheat sheet of sorts to get you started writing Ruby code quickly.
Posted 908 days ago
I recently decided I was going to take up Ruby programming as a hobby. Prior to that I had taken on Python, which has quickly become one of my favorite languages. Ruby is coming in a close second, and could easily take it over as soon as they have built in XML support - so I thought I'd follow up my Intro To Python series with some Intro To Ruby posts.
I've found Ruby very easy to learn and use - I decided to learn Ruby about 2 weeks ago now, and have since released Blosxonomy, a Ruby implementation of a Blosxom like blogging system that powers this site. Its syntax is simple and intuitive, and the grammar is expressive and easy to learn.
Posted 910 days ago
Whipped out a quick plugin tonight along the lines of optimizing my fold at timfanelli.com. It trims my entries down to 20 words summaries when you're viewing my home page. When you visit my homepage then, you only see the first 2 lines of text for recent entries, and you can follow the title link to view the full story.
When you browse by tags, the ReadMore plugin takes effect showing you potentially more content than you'd see on my home page, but still not the entire story (unless, of course, I neglected to add a <!-- BREAK --> to my post.). The home page summary plugin strips any markup from the summary to prevent bastardizing otherwise valid markup, and also to prevent my other plugins (such as ReadMore) from taking effect.
Home page summaries will be released when I post Blosxonomy 0.6 - but if you're curious to see how it works, here's the method I use to generate an entry's summary:
def generateSummary( body ) # Remove markup from the body body = body.gsub( /<[^>]+>/, '' ) # Split the body into words (consecutive blocks of non-whitespace) words = body.scan( /[^\s]+/ ) # Take the first 20 words words = words.slice( 0, [20, words.length].min ) # Join them back together in a paragraph. return "<p>%s...</p>" % words.join( " " ) end
I use this same method now to generate <atom:description> content in my Atom 1.0 renderer plugin.
Posted 912 days ago
I ported the pyBlosxom trackback plugin this morning, so I now have trackback support re-enabled! Very exciting.
Now that Blosxonomy has comments and trackback support, I'm going to release version 0.5 at Blosxonomy.com
Posted 915 days ago
I recently decided it'd be fun to learn the Ruby language, and that a worthy undertaking to do so would be to port pyBlosxom - which I've been using for a little over a year now. The result is something I'm quite proud of, and am still actively working on -- Blosxonomy.
add to
del.icio.us