Showing posts with label webdev. Show all posts
Showing posts with label webdev. Show all posts

Prototype (et al) in Greasemonkey

So, using Prototype in Greasemonkey is... awkward, at best.

You see, everything you do in GM Javascript is actually stored in this weird space called "unsafeWindow". (Clearly, I don't fully understand why.)

It also seems to be impossible to intrude on the basic elements (like Element itself) that PType wishes to.

Thus, you have to be sneaky: you cause the page to load your scripts. ...And yet, for reasons incomprehensible, you still access them in unsafeWindow. Even when events fire. ...Which, by the way, seems to be the only way to do it: events firing. You can't just natively "do stuff".

Disappointing... but work-around-able.

I think we can use this to help us Monkify some of our websites. My first target is Learnerweb, which is Usable But Obnoxious as-is.

Here's a script that causes a new <p> to appear on the cspabq page when you click pretty much anywhere under the header:

// ==UserScript==
// @name Monkeys. Greasy, greasy monkeys.
// @namespace CSP
// @description Testing Prototype and ilk in GM
// @include http://www.cspabq.org*
// ==/UserScript==

var scripts = [
'http://wiki.script.aculo.us/javascripts/prototype.js',
'http://wiki.script.aculo.us/javascripts/effects.js',
'http://wiki.script.aculo.us/javascripts/controls.js'
];
for (i in scripts) {
var script = document.createElement('script');
script.src = scripts[i];
document.getElementsByTagName('head')[0].appendChild(script);
}

window.addEventListener('load', function(event) {

$ = unsafeWindow['window'].$;
div = document.getElementById('content-main');
div.addEventListener('click', function(event) {
x = document.createElement('p');
x.innerHTML = "It is very greasy. You are likely to be eaten by a monkey.";
$('content-main').appendChild(x);
}, 'false');

}, 'false');

Firefox extensions

It's time to take stock of my FireFox extensions, again, since I've shuffled them around quite a bit.

  • Adblock - A completely different way to surf, and there's no turning back. It's amazing how much suckier the web is with banners all over, and you have to use this for a few weeks to feel that pain--when you use someone else's browser!
  • Flashblock - Only see flash when you want to see flash. ...An extremely rare problem with some sites that have "hidden" flash scripts that talk to one another, but it's so rarely a problem that I don't care.
  • BugMeNot - When you want to read that article that requires registration... (Not very often, but oh-so-nice when you do!)
  • Delicious - I jumped on the Delicious (bookmark site) bandwagon some months ago, and I love the fact that my bookmarks come with me everywhere (and I don't need to worry about crashes and the like)...
  • IE View Lite - (website is down at the moment...) Right click on links to "Open in IE". That's all. ...And it's terribly handy here at work, where several apps we use are "IE Only" [rolls eyes].
  • WebDeveloper - I am using this less, now that FireBug does most of this stuff... but it still has some great form-tweaking options, and a nice "View CSS" option, among other things.
  • SessionSaver - Another plug I can't imagine living without--it brings up every tab you had open the last time you ran FFox... and even restores things after a crash.
  • FireBug - "Holy Flurking Schnitt". This does nearly everything you would want when doing webdev. The only problem with it is that it makes debugging in IE incredibly painful! (And, of course, the new Beta has a "lite" version that you can plug into IE, suposedly--I haven't checked that out yet, though...) Damn. Of course, this is only for webdevs, and any webdev reading this already knows about it. ; )
...I am, of course, very satisfied with this set of plugs.

Silence

Introspective week.

[Now Playing: "Square Lamp" by esem... damn, what a fine track this is.]

I've been thinking a lot this week. About work, about quality, about ruby, about miniatures, about drawing... the whole shebang.

Work: I want to write more code. That's the long and the short of it. I'm weak at detail-oriented stuff, and I'm good at algorithms and problem-solving: I should be writing more code. I asked my boss about this today, and he supports the idea; we'll see where that goes. (To be honest, my experiences with such requests are usually taken quite seriously.)

Quality: I went to a local conference regarding the Bladridge criteria yesterday. I rather enjoyed it, though I would argue that I didn't learn anything, really. Rather, it was great idea-fodder, and allowed me some "blocked time" to contemplate how to make use of the criteria at work. ...I also considered working on a "personal criteria" for self-improvement.

Ruby: As I've mentioned, I've been pushing for it at work. There has been surprising support for it, and the lead programmer just asked me to try writing a web-page for a new project using ruby. ...My reflex was to say "no", because I wanted more time to learn it and discover best practices, but I think working on it would be an excellent way to explore the language. The first thing I went looking for was a DBASE-format library... and the first page I stumbled upon was an argument of why the writer had switched from ruby to python. ...And it's a recent article; a well-informed one. His reason, of course, was the robustness of the Py libraries out there.

Of course, this is something that will change with time. ...Or will it? ...I wonder if ruby will really be the last popular language. (Errr... last to rise to power, anyway.) I'm not terribly willing to write new libraries that are missing... I wonder if those who are willing are a dying breed. With the vast libraries available for Java and C++ on the low-end, and Perl and Python on the high-end... It will take a massive force of will to build ruby up to that level. I shudder to think how insurmountable an obstacle that will be for the languages of tomorrow.

Of course, MS has the weight to throw .NET out there, and the world will eat it. (Thank you, MaSter, may I have another?) But that's an exception.

Perhaps that's why DSL's are so popular these days... it's only in the small world of Doman-Specific problem sets that new languages have the ability to emerge.

Of course, the idea of "Very High Level Languages" may be the next big thing. Frameworks on steroids: programming languages built on today's languages. Imagine Rails, but without DHH's "convention over configuration" as a limitation: a meta-language smart enough to look at your database and figure out the schema.

Perhaps I've been drinking the MS water too much lately, since that sounds like "Visual Rails" to me.

Miniatures: Yes. Since playing miniatures with my son a few weeks ago, I've been contemplating building up my own collection. A lot. ...Obessing, really. I've decided to beef up my collection of Star Wars driod miniatures, and for D&D, I'm considering a "Devils and Blues" pool of minis... "blues" being Blue dragons. (The teams in D&D, called "Warbands", are alignment-specific, and blue dragons are LE, like Devils.) ...I'm also big on druids and constructs... but I can't quite come up with a Warband concept that seems solid enough to warrant investing in.

Strangely, my wife doesn't seem disturbed by this, and suggested I just build a collection over time, $20 a month or so. [shrug] I guess I will.

...I tried to stay the urge by installing Neverwinter Nights... but found it didn't scratch the itch.

Drawing: Okay, not much to say here. I've just thought about it a lot, lately. ...I haven't actually drawn much, however. ..A little. Enough to claim "I haven't stopped". But still, it's one of those frustrating situations where you know you should stop thinking and start doing... but something stops you. A Human curse.

Why I switched back to Prototype from YUI

While I love YUI's documentation, I just can't help but prefer this:

function checkExistingNamesRequest(name, value){ var div = 'checkExistingNames_'+name+'_container'; loading(div, "existing "+name+" names"); var myAjax = new Ajax.Updater( div, "./checkExistingNames.cgi", { parameters: $H({ name:name, value:value }).toQueryString() } ); }

To this:

var svrCheckExistingNames = "checkExistingNames.cgi"; var checkExistingNamesSuccess = function(o, n) { if(o.responseText !== undefined) { $('checkExistingNames_'+n+'_container').innerHTML = o.responseText; } } nameHandler = function(o) { checkExistingNamesSuccess(o, this.name); } var clientTest = nameHandler.bind({name: 'client'}); var projectTest = nameHandler.bind({name: 'project'}); var collectionTest = nameHandler.bind({name: 'collection'}); var collrefTest = nameHandler.bind({name: 'collref'}); function checkExistingNamesRequest(n, v){ $('checkExistingNames_'+n+'_container').innerHTML = "Checking existing "+n+" names... <img src='../icons/loading.gif' border=1>"; var test = clientTest; if (n == 'project') test = projectTest; if (n == 'collection') test = collectionTest; if (n == 'collref') test = collrefTest; var request = YAHOO.util.Connect.asyncRequest('GET', svrCheckExistingNames+"?name="+n+"&value="+v, {success: test, failure: test}); }


Which do you think is more maintainable?

(Frickin' Blogger is not meant for code, is it?!?)

Ruby

I got paid (for the first time) to write Ruby today.

A co-worker and I set up a new publications database and used Rails to get up the scaffolding for the website.

Of course, the only real "code" I wrote was to display a list of authors related to a partiucular title. I don't have the code in front of me, but it was something like:

<% for author in @title.authors %>
<%= link_to author.fname+' '+author.lname, :action=>'author_show', :id=> author.id %><%= ', ' unless author === @title.authors.last %>
<% end %>

I had to create the title_controller.rb's "author_show" method, which was something like:

def author_show
redirect_to(:controller=>'author', :action=>'show', :id=>params['id']);
end

...And aside from a "has_and_belongs_to_many" from titles to authors and vice-versa... that was all I had to write to get that functionality (of displaying all the authors for a title).

Of course, I'm a little disappointed that I had to put that "<%= ', ' unless author === @title.authors.last %>" in there. Really what I wanted was a ".join(', ')", but I couldn't get that to work: I'm not familiar enough with link_to and... well... with tying bits and pieces of ruby together.

Even still, the way it is is very readable. (Yeah... that's my excuse, and I'm sticking to it!)

The co-worker that I was helping was very impressed with the amount of ground we covered in the three hours we worked on it, anyway. ...Note that over half that time was wasted trying to connect to the SQL Server database... (Turns out there is not trick to it, just set the type to "sqlserver" and fill out the rest of the fields intuitively!)

On the down side, I was so wrapped up in the project that I totally forgot that I had a date with my wife for lunch--and I was away from my desk, so I didn't get her calls. ...So I'm in the doghouse, now. : | D'oh.

A Possibility

A co-worker just asked me to look at his database ERD--a butchered version of Northwest Pubs (one of Microsoft's example DBs), to handle VA publication references.

I thought, "whoa, he could have this up in running in a few hours with Rails." I've been trying to sell rails to this co-worker for over a year now, so when I told him my thought this morning, he was prepared for it: ruby wasn't a foreign concept to him anymore. His response was "that's what I wanted to hear!".

We're scheduling some pair-programming to give it a whack in the near future.

Another co-worker overheard the conversation. ...He then asked me what I thought about another web-application...

[writhes hands insidiously]

Mouse Over

What's the fsck'ing point of a mouseover image?

...I mean, I could understand if you have some complicated imagemap, where it's not entirely clear where one "button" ends and another begins... but you can't really use a mouseover image in those cases. (Not on an HTML page.) Mouseover images are used in well-segmented menus, where the user is plainly aware of which option their mouse is hanging over.

So what's the point of making that option "glow"?