Monday, April 7. 2008Printer held Hostage by Ink Cartridge
I've had a Canon Pixma MX700 multifunction printer since the beginning of the year. I've been pretty happy with it. It's worked well for scanning, copying, faxing and printing. Until today. Today I needed to scan something, and was greeted with the following message when I turned it on:
U150 The following ink tank cannot be recognized.The yellow cartridge was indicated. I though that it was an odd problem, but I didn't care for the moment, because I didn't want to print, just scan. But no button on the printer would bypass this error and let me scan. I ended up calling Canon, and happily received a domestic phone rep. He had me try a couple things, but eventually decided that the yellow ink would need to be replaced. They would send me one free. I asked if there was any way to bypass the error so I could just scan, and he said there was not. If I wanted to use it today I would have to go out and buy a yellow ink cartridge. So after driving all the way across town and spending $16, I have my printer back...for now. It seems like questionable design to cripple all the functions of the printer just because one color cartridge is faulty. A better failure mode would be to only prevent color printing. Black and white printing, and the other printer functions should still be usable. Hey Canon, how about updated firmware for this? Please? Monday, March 10. 2008Determining Image File Types in Ruby
Today I came across a PNG file that had been uploaded from a browser with a .JPG extension and image/jpeg MIME type. It's too bad that MIME types are apparently unreliable when it comes to file uploads. I went looking for a way to determine the file type by actually reading the file. This is probably a solved problem, but I was unsuccessful Googling for the answer. I came up with the following Ruby method which decides the image file type using up to the first 10 bytes:
def image_type(file) case IO.read(file, 10) when /^GIF8/: 'gif' when /^\x89PNG/: 'png' when /^\xff\xd8\xff\xe0\x00\x10JFIF/: 'jpg' when /^\xff\xd8\xff\xe1(.*){2}Exif/: 'jpg' else 'unknown' end end This works well on a small set of test files (400+ from a browser temp files directory). Let me know if there's a case where this code doesn't work, or if there's a better solution in general. Saturday, December 15. 2007I'm in Rails
I've made a code contribution to Ruby on Rails. It was minor, but I'm glad I could help. See ticket 10435 and changeset 8386.
Supposed to get some rain today...keeping my fingers crossed. Update 2007-12-17: Looks like my patch made it into Rails 2.0.2. And we did get that rain, but more would be good. Update 2008-03-17: I managed to get another small patch committed. Go open source! Saturday, December 8. 2007Formatting a Javascript Date for MySQL
I don't like to code in JavaScript, but that's the Ajax-y wave of the future. So I write it when I have to. This week I needed to format a Javascript date as a MySQL-style date like 2007-12-08.
JavaScript apparently doesn't have a nice date formatting function or even a generalized sprintf. Another Javascript quirk is that the Date.getMonth() function returns 0-11, while the getDate() function returns 1-31. I'm not sure what the designer was thinking on that one. I came up with this function...feel free to use it in your code with or without credit:
function formatDate(date1) {
return date1.getFullYear() + '-' + (date1.getMonth() < 9 ? '0' : '') + (date1.getMonth()+1) + '-' + (date1.getDate() < 10 ? '0' : '') + date1.getDate(); } Tuesday, August 28. 2007Improving upon Rails' validates_inclusion_of
I'm fairly new to the Ruby language and the Ruby on Rails framework, but it worked nicely for quickly building my website BirdSite.
I was using validates_inclusion_of fairly regularly to make sure the data in my models was valid. But then, watching the development log, I noticed extra SQL queries being made when I accessed my main model. It seems that validates_inclusion_of was forcing the model to make queries to the related models even when I didn't need data from them. Some Googling led to a blog post that did the validation a different way. It worked well, until I added the code to a new model today and it broke. The code was translating the model field name into a string from which to call the model itself. But the code assumed that the model would be a single word. I added a change to strip the spaces out, and it worked again. I contacted the company that hosts the blog and they confirmed that it was a problem, and they didn't know of a nicer Ruby way to correct it short of dropping the spaces with search/replace. They updated their code. I'm glad I could help out. It really works better than the standard validates_inclusion_of. Tuesday, August 14. 2007Rails acts_as_ferret without DRb
I wanted to add a search feature to my Ruby on Rails application BirdSite. There is a plugin called "acts_as_ferret" which allows Rails applications to use the Ferret search engine (based on Lucene).
Using this tutorial, I was able to get search up an running. It worked great on my development system. But there was a warning that you needed to run the indexer using a DRb server instead of directly from the Rails app. This is because the index cannot handle multiple processes writing to it simultaneously. (I also ran into this problem using PHP with another engine called Xapian). I was hoping my new site was low traffic enough to avoid problems. Since I'm hosting it on a shared server, I can't run a DRb server there anyway. But I got my first indexing exceptions less than 24 hours after I loaded my stuff onto the live server. So I decided to try periodic indexing by a cron job. This would allow me to update the index once an hour, from a single process. The downside is that the search index is only updated hourly, but I decided I could live with that. The first step is telling your Rails app to not index the content when updating. My model already had a before_save method, so I added this code:
# in the model def before_save # other stuff goes here # disable automatic ferret indexing...move it to a cron job self.disable_ferret(:always) end Then I had to create a rake task which would build the index:
# ferret_index.rake desc "Updates the ferret index for the application." task :ferret_index => [ :environment ] do | t | MyModel.rebuild_index # here I could add other model index rebuilds puts "Completed Ferret Index Rebuild" end This task is simplified: I'm telling it to rebuild the entire index each hour. I'm guessing when my dataset gets big enough, this will be really slow. In that case I'll need to track all the model instances that got updated in the past hour and just index those. Finally, I needed a cron job to run the rake task, making sure to set the environment to "production":
cd /rails_app && rake ferret_index RAILS_ENV=production
So far this is working well, and I haven't received any indexing exceptions since. Friday, July 6. 2007Check out the BirdSite!
I recently published a new website: birdsite.org.
This site was inspired by BugGuide, where I've been
a participant for several years, both as a photographer and a developer. I'd been
thinking about doing a similar site for other fauna that I photograph.
This forum thread made it clear
that others were interested in such a site for birds. I decided to build it. For my
own programming amusement I created this site as my first project with
Ruby on Rails. I still have lots of features to
add but I wanted to get the bare bones up and running.
Wednesday, May 30. 2007Drupal Anti-spam Registration Question
Last year I had to add an anti-spam question to my PHPBB forum to prevent spam bots from signing up and wreaking havoc. Lately the same bot problem has crept up on a site I have running Drupal 4.7.x. So I resorted to the same solution, though this one is implemented as a Drupal module. It is very simple...the only thing you configure is the question and answer you want to use. Click here to see it, and follow the instructions in the comments. I hope it helps you.
Saturday, April 21. 2007PHPBB Anti-spam Registration Question
If you are not comfortable installing this on your own, I'll do it for you. If you're using PHPBB 2.0.23 and the SubSilver template, I will install it for $25 via Paypal. (If you're using a different template or need an older site updated to the latest PHPBB, I can do that too, but it will take longer and cost extra). Contact me.
I've been meaning to document this for a while now, and I finally made myself write it up. The simple measure I will describe has been working for my PHPBB website since last December. It has kept spam accounts from registering and posting anything on my site. This idea involves asking a question during registration that spam bots do not know how to answer. You can choose any question and answer that you want. The website that I run PHPBB on is a sailing website, so I asked a question that sailors could answer. For this example I chose another question. You have to change two files, templates/(your template)/profile_add_body.tpl and includes/usercp_register.php. In templates/(your template)/profile_add_body.tpl, add this after the <!-- END switch_confirm --> line (about line number 68):
<!-- BEGIN switch_add_profile -->
In includes/usercp_register.php, add this after else if ( $mode == 'register' ) { (about line number 275):<tr> <td class="row1"><span class="gen">Anti-Spam Question:</span></td> <td class="row2"> <span style="font-size: small;">Enter the name Luke Skywalker's father. Check your spelling! Requiring this question to be answered will hopefully limit spammers who try to sign up.</span><br /> <input type="text" class="post" style="width: 200px" name="bonusq" size="25" maxlength="255" value="" /> </td> </tr> <!-- END switch_add_profile -->
// mod by MB to require human data to prevent spam bots
So there you have it. I'm sure there are some sophisticated PHPBB mods out there that will do the same and more for you, but this simple change has saved me a lot of trouble. I'm keeping my fingers crossed that it will last.
if(trim(strtolower($_POST['bonusq']))!='darth vader') { $error = TRUE; $error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . 'You did not answer the Anti-Spam question correctly...' . 'please try again.'; } // end mod Update 2007-05-23: I omitted one other mod to make this work. You also need to edit your includes/usercp_register.php file. Find the line if ( $mode == 'editprofile' ) (about line number 941) and modify that block to look like this:
if ( $mode == 'editprofile' )
{ $template->assign_block_vars('switch_edit_profile', array()); } else { // Else block is Mod by MB 2006-08-11 $template->assign_block_vars('switch_add_profile', array()); } Update 2007-06-24: Several folks wrote in expressing confusion about where these blocks of code belonged. I apologize, and I amended the article to give approximate line numbers where the mods belong. I used PHPBB 2.0.22 as my reference. Note that if you have made other modifications to your PHPBB files, the line numbers might not be quite right. Update 2007-06-27: Bug fix. See comment #7 below. Update 2007-09-29: A lot of people have written in having trouble with this modification when it comes to users editing their profile. To avoid problems, I have applied the modification to a new copy of PHPBB 2.0.22 and tested it. I made copies of the modified files and they are available to download. The modification as it appears in this blog post is what I used, and it works fine for me. I did not make any of the other changes from the comments (except the bug fix from June which has already been incorporated into this post). Update 2008-02-27: The update works just fine for me in PHPBB 2.0.23 as well. Neither profile_add_body.tpl nor usercp_register.php were changed between 2.0.22 and 2.0.23. Wednesday, April 18. 2007Java Runtime Environment Space Eater
If you're looking for some spare disk space, check out your C:\Program Files\Java folder. Mine was full of various folders like jre1.5.0_7, jre1.5.0_11, etc. I'm not sure how they all got there, but I'm guessing they came from installing several versions of OpenOffice over the years. Looking at the Add/Remove programs in the Control Panel, I had like 8 versions of the Java Runtime Environment, collectively eating up several hundred megabytes. So I cleared out all but the latest and things are nice and tidy for the moment.
(Page 1 of 7, totaling 66 entries)
» next page
|
CategoriesQuicksearchArchivesSyndicate This Blog |