All posts filed under Web. You can view a list of all the categories here.

Defensio

The website experienced some downtime yesterday. The main reason was that Defensio's server went down (hardware problem, not their fault). All posts/comments are spam-proofed with Defensio, because of that, my application crashed when trying to reach Defensio's server, more precisely the plugin used to communicate with Defensio did the crashing. It wasn't too long before their server was back up again, and I took the time to push out a few bug fixes, and play with Capistrano's deploy:web:disable.

Despite the hiccup, I'm still partial to Defensio over Akismet. They just seem... cooler. @cmercier even apologized to me over Twitter (me being one not usually noticed)! Hopefully they get the hardware issue sorted out soon, but I'm sticking with them either way.

Filed in Web.

Rails 2.1.1 & Django 1.0

Ruby on Rails 2.1.1 was released earlier today. Just finished upgrading this blog, only involved removing the REXML vulnerability fix from the initializers and changing environment.rb to use the 2.1.1 gem (RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION).

Also congrats to Django which hit version 1.0. Out of the frameworks I've tried, Django seems to be the best next to my personal favorite, Ruby on Rails (no brainer?). I'm sure the Django fans and princessjrnorman(link removed) are happy.

Filed in Web.

Found Defensio's Learning Curve

This website makes use of Defensio for comment spam control, as mentioned in a previous post. Lately it's been getting a lot of spam comments. Two were let through at the beginning, but after several weeks it seems Defensio has found it's bearings, and accuracy is on the rise. The website (or API key) currently has a 95% accuracy rating, by many standards low, but the fifty-seven spam comments blocked throughout the last few weeks says otherwise.

Now all I need is an admin panel to manage it all, this inline-administration is getting on my nerve.

Filed in Web.

Tofu!

PRINCESSJRNORMAN(link removed) and accomplice code named "Tarpman" have started work on a "minimal window manager for X11 that is extensible in Lua". Check out their progress here(link removed).

Filed in Web.

The Orange Seed

Silent as a ninja, The Orange Seed makes its debut. Who: Richard Neary, Sunny Hundal and my self. What: A tumblelog. Where: http://theorangeseed.com/. When: October 22nd to infinity. Why: I've always wanted a tumblelog, and having one written in Rails is even cooler.

The source code is available on GitHub!

Filed in Web.

Ruby on Rails 2.3.5 Released

Just a quick note, Ruby on Rails 2.3.5 was released last night. I updated the site last night, which brought up some issues with the RailsXss plugin and Erubis, but everything should be working now. Anyway, go update now!

Filed in Web and The Site.

Google Chrome for Mac

The long awaited Google Chrome for Mac has just been released. Get it while it's hot!

Filed in Web.

Submitting a CodeMirror'ed Field with JavaScript

This issue arose the other day while working on a code editor for a content management system. A little background information: it was just a single textarea that was submitted using AJAX to save the data; previously it was running CodePress, but it was decided to switch to CodeMirror to integrate with Tobias Lütke's Liquid Editor.

CodePress worked fine, it provided great syntax highlighting and saved properly with AJAX. Upon switching to CodeMirror, the saving process started malfunctioning. To sum it up, a user had to submit the form twice in order to send the correct params from the form. CodeMirror attaches a function onto a forms submit event called updateField, which as can be guessed, updates the form's field that CodeMirror is applied to, with the proper value (since CodeMirror hides the field and shows its own stuff in an iframe). So the problem was updateField wasn't being called, therefore, the old data was being submitted again.

The Fix

Let's get into some code! Here's the bit of code used to submit the form, which is called with the onsubmit= attribute on the form tag (note this is Prototype).

function submit_form(form) {
  new Ajax.Request('/admin/update', {
    asynchronous:true,
    evalScripts:true,
    parameters:Form.serialize(form)
  });
}

When a user submits the form, it send an AJAX request to /design/update which handles the data and presumably saves it to the database. To get it all working properly, the form's textarea's value needed to be updated with the new (modified) one from CodeMirror. Here's the code used to initialize CodeMirror.

var editor = CodeMirror.fromTextArea("editor", {
  parserfile: "parseliquid.js",
  stylesheet: ["/codemirror/css/xmlcolors.css", "/codemirror/css/liquidcolors.css"],
  path: "/codemirror/"
});

This puts the editor in place of a field with the ID of "editor". So from that example we know that we have access to an object called editor. CodeMirror provides a function called getCode which can be sent to editor. So essentially all that needs to be done is updateField manually!

function submit_form(form) {
  $("editor").value = editor.getCode(); // The magic dust
  
  new Ajax.Request('/admin/design/update', {
    asynchronous:true,
    evalScripts:true,
    parameters:Form.serialize(form)
  });
}

We set the field's value to the new value from CodeMirror, and continue on as normal, simple as pie! (Pie is not easy to make by the way.).

Hopefully this helps others who are encountering the same issue, and does a good job explaining the problem and solution!

Filed in Programming, Web, and Tutorials.

no such file to load -- iconv

After upgrading from Ruby 1.8.7 patch-level 174 to patch-level 249, I noticed I couldn't run Rails anymore. After some investigating, I found out it was the iconv library (used for text conversions). Ruby apparently couldn't locate it (require 'iconv' failed). I was stumped, since it never had had this problem before.

The solution was to simply give the configuration script the location to my iconv installation (please note I'm running OS X Snow Leopard).

./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1 --with-iconv-dir="/usr/local"

Make sure to provide the correct path to your iconv installation. After compiling, require 'iconv' returned true. Huzzah!

Filed in Web.