Saturday, January 31, 2009

can_has_assets? A new Rails plugin for requiring stylesheets and javascript in views.

I sat down and scratched an itch I've had ever since I started developing Rails plugins: finding a way to require javascript / stylesheets on a per-view basis.

There's Needy Controllers, but that operates in your controllers, and me, being me, wanted to require the CSS and JS from the view, since I'm already hooked on the whole
<%= title "hello world" %>
in views idiom. (view-specific logic in views, basically)

So, I built can_has_assets as a way to scratch my itch. The master branch is currently acting as stable, and since the plugin is so simple, it probably won't be updated very often (or at all). Feel free to push if you do something interesting with it though.

Anyway, straight from the README:


CanHasAssets
============

can_has_assets is a super-simple way of requiring stylesheets and javascript files
from within views. It also supports inserting snippets of CSS and Javascript into
a page only once. Snippet support should really only be used for rapid prototyping,
though. :)

Installation
------------

script/plugin install git://github.com/radicaled/can_has_assets.git

Notes
-----

can_has_* will include a file or snippet only once -- it is safe to call these
methods multiple times, where-ever required.

Alternatives
------------

If you're looking for more control, consider Needy Controllers by Michael Bleigh:

http://github.com/mbleigh/needy-controllers/tree


Example
=======

In your layout:

<%= stylesheet_link_tag :can_has_assets %>
<%= javascript_include_tag :can_has_assets %>

In your views:

CSS
---
<% can_has_css 'css_file' %>

<% can_has_css :sample_snippet do %>
.item {
/* some fake example css here */
}

Javascript
----------
<% can_has_js 'js_file' %>

<% can_has_js :sample_snippet do %>
function helloWorld() {
alert("Hello, world!");
}
<% end %>

Thursday, January 29, 2009

Discipline + Git = good awesome funtime!

(inflammatory rant about some Git users follows)

Git is awesome. If you haven't tried it yet, you should use it for your next non-critical project. Even if you're trapped using Subversion at work, the git-svn bridge will get you by and no one will be the wiser.

Just remember one very, very important thing: Git is not The End All.

I say this because I've noticed that some people, after migrating to Git (or Github), completely lose all discipline.

No branches.

No tags.

For these people, there is nothing but The Master Branch (dramatic thunderstrike!). There is no stable or unstable; there is only the master branch and its whimsical nature. Will the project work today? Will it work tomorrow? Did it even work yesterday? Who knows.

Here's a hint that you've gone horribly awry: if people need to track down the latest "stable" commit you made to the master branch by checking the timestamp on your announcement via Twitter about it, then you've royally fucked up and need to re-evaluate.

Rant over, as abruptly as it began.

Tuesday, January 27, 2009

Tag Aliases: get them, people.

This has been on my mind ever since I made this identi.ca notice:

# vs # -- AKA, "Why Tag Aliases are needed in every tagging system."


You'll notice that Rails and RubyOnRails are two seperate tags -- even though they both reference the same topic. This almost inevitably comes up when you're dealing with a tagging system where individuals supply the tags in question. Is it #sn or #socialnetworking? #rails or #rubyonrails?

The first time I saw tag aliases in the wild, they were on an imageboard for porn. Yes, all innovations have their roots in porn. Porn is the great innovator! All hail porn!

Tag aliases evolved out of necessity in the world of web 2.0 pornography: when dealing with certain topics, say fetishes for example, there are often two ways to reference the same topic: the technical nomenclamature, and the common name. So, what do you tag it under? Both, of course. Under the hood, the system tags these tag aliases together and presents one uniform tag, which can the technical tag, the common-name tag, or both (for usability).

As I've demonstrated, tag aliases are useful for more than porn. When you're dealing with microblogging, for instance, do you want to use a short name, for space, or a long name, for usability / readability? Without tag aliases the community really has to decide on one or the other. With tag aliases, it's just a matter of personal preference -- you may not want to use the shorter version of a tag if you have a readership unfamiliar with the topic at hand, for example.

So why the hell do I only see tag aliases on random pr0n imageboards and not where they're needed in other portions of the web 2.0 space? It might be a matter of mechanics. Who gets to decide what tags are aliased, where? Is it a Wiki-like system, or a trust-based system like StackOverflow?

...

...

...

That is all.

Mozilla Ubiquity: Metacritic Script

I developed this rarely used script to search Metacritic way back when, as my first Ubiquity script. Ever since I got it working I just kinda left it there. It's a total hack and it'll break when they change the way the page renders, but you, dear viewer, might find it useful.

Yes, Mozilla Ubiquity does rock. However, having no API to your site does not rock. It is the exact opposite of rock, in fact!


function __searchMetaCritic(pblock, searchText) {
jQuery.get("http://www.metacritic.com/search/process?sb=0&tfs=all&ty=3&x=0&y=0&ts=" + escape(searchText),
function(response) {
var resultsREGXP = /\[0-9]\.(.*)\<\/p\>/gmi;
var results = response.match(resultsREGXP);
found = true;

if (results == null) {
var msg = 'No results for "${what}"';
var subs = {what: searchText};

pblock.innerHTML = CmdUtils.renderTemplate( msg, subs );
return;
}
var tempElement = CmdUtils.getHiddenWindow().document.createElementNS("http://www.w3.org/1999/xhtml", "div");

tempElement.innerHtml = '<link href="http://www.metacritic.com/general.css" rel="stylesheet" type="text/css">';
tempElement.innerHtml = tempElement.innerHtml + results.join('');

var msg = 'Searching for "${what}"
${results}';
var subs = {what: searchText, results: tempElement.innerHtml};

pblock.innerHTML = CmdUtils.renderTemplate( msg, subs );
});

}

CmdUtils.CreateCommand({
name: "metacritic",
takes: {"what": noun_arb_text},
preview: function(pblock, what) {
__searchMetaCritic(pblock, what.text);
var msg = 'Searching for "${what}"';
var subs = {what: what.text};

pblock.innerHTML = CmdUtils.renderTemplate( msg, subs );

},
execute: function(what) { __searchMetaCritic(what); }
});

Saturday, January 24, 2009

My moment of revenge against L4D exploiters. :)

Left 4 Dead is Valve's newest zombie survival horror game. Everyone loves it. People that don't are lying and really zombies in meatmasks.

Anyway, the game's got some issues due to its physics engine -- the most notable issue is in the Versus mode where it's possibly for enemy zombies to intentionally block paths, making it impossible for the zombie survivors to move forward. It's an exploit, and beyond that it's a stupid thing to do.

So today I had the great fortune of joining a team that was blocking the sewer hole on No Mercy 2 like a buncha douches... except, just as I was about to leave, I spawned as the car-throwing Tank right next to my exploiting team-mates.

I'll let you figure out what happened next. >:)

Monday, January 19, 2009

I don't want to talk to you if I need to sign up for something new to do it.

I've been getting real lazy about communicating with people on the Web. There are some things I just don't do anymore, for no other reason than I just don't have the patience.

Like, take this post from the OpenMicroBlogging mailing list. It's about OMB Spec 0.2. When I read it, I instantly had questions about #3, HTML-rendered notice content. A: what the hell does that mean, and B: won't that lock-in OMB consumers to a particular implementation of @ replies and # tags?

Yet, I just can't bring myself to sign up for the mailing list to ask. I don't want to mess with another account on another site for something so trivial. I just don't have it in me anymore. I've even started designing my own small sites to accept OpenID or whatever else I can get my hands on to avoid making a unique account for myself.

I guess I'm all username/password'd out.

As for OMB -- no link, can't find a portal site for it -- my interest is easy integration of microblogging into client sites. In my mind, if a client breeds a community site, integrate microblogging as a communication stream, and expose it via OMB so they can "reach out" as a community into the Web. It's still a big foggy in my mental about it. For now I've just been watching its progress in case a relevant scenario pops up.

Friday, January 16, 2009

Monetizing Yahoo! BOSS.

This isn't a post about how to make money using Yahoo! BOSS; rather, it's just a link to the current policy of monetizing Yahoo! BOSS through third-party methods (Google Adsense, basically). I'm posting it mostly because I looked for this information for a long time when I had the opportunity to use BOSS, but couldn't find it, so had to opt for a customized site search instead.

Excerpted from this post about third-party monetization with Yahoo! BOSS:

Our current policy is, while we do not prevent you from implementing a third party monetization method in conjunction with your use of BOSS, we may at any time require you, for example, to implement and display Yahoo!'s Sponsored Search (or similar) advertising offering instead of a third party's. Alternatively, we are considering the option to pay a fee based on your use of the service; in this case, we would anticipate permitting the continued use of monetization methods from third parties.
Basically, Yahoo! reserves the right to fuck you up: any time, any place.

For small niche-like sites this is probably OK; they wouldn't bother trying to get any cheddar from you. If you run something moderately successful powered by BOSS you might have problems in the future.

I don't have a problem with having to display YPN ads or whatever. The real problem is not being able to support third-party monetization efforts. For instance, if you're running a site that makes good bread with CPA ads / Amazon affiliate links, removing those and replacing them with lesser YPN ads is a kick in your junk. What do you do then? Try to manage direct sales?

Something to think about.

Friday, January 09, 2009

The Microsoft Tag site...

...doesn't work in Firefox.

Even though it's powered by Silverlight, which means it should function identically in anything that runs Silverlight.

Seriously.

Visit http://www.microsoft.com/tag/ and try to click on 'Get it for your phone' or 'Make a tag' -- it Just Doesn't Work.

That is such a cold, cold burn.

Tuesday, January 06, 2009

Need design ideas? Surf Wordpress blogs.

I'm a terrible designer. As one of those people who can't close their eyes and imagine with clarity The Perfect Design, I'm forced to rely on other people who don't suck at makin' things pretty and useable.

One of the best resources I've found so far are Wordpress blogs. Some Wordpress blogs have the most ridiculously beautiful themes you will ever find. For instance, following a link from Hacker News got me to some dude's post about "Encouraged Commentary." Excellent ideas aside, the first thing that struck me was that his blog was freakin' beautiful. I mean, look at it. It is aesthetically pleasing and functional, to boot. Hell, look at what he does to images -- they're faded out until you roll over one, at which point the image becomes crisp and the caption pops up.

Another resource is the official Wordpress Themes site. Some gems hidden away in there.

I'm not saying steal these themes or anything -- far from it. But they can provide a jumping off point for the uncreative types to work with. For a certain site, I started with a pretty nice Wordpress theme and then modified it so much it looked nothing like the original... but without the original, I wouldn't have gotten even half as far as I did. It helps that most of the themes on the Wordpress site are liscensed liberally, even though I don't actually look at the underlying CSS. I actually cherry pick certain parts of the designs and incorporate them into one OK-looking site.

It provides enough momentum to get me going, at least.

Sinatra made me go ROOOOAARRRR.

So I wanted to give Sinatra a try today because I had to throw up, quite literally, a one-one dynamic webapp. No tests, no helpers, nothing -- just the one page with some Ruby-powered bits on the backend. The only reason I wanted Sinatra was because I wasn't in the mood to do a massive svn check-in of a vendored rails with the project.

So, sudo gem install sinatra and we're off to the races, right? Wrong. After about 10 minutes of debugging I realize that the Sinatra gem, a) doesn't work with the latest Rack (0.9), and b) seems to be updated infrequently judging by some blog posts I've read. They recommend grabbing Sinatra from github, but there's no stable Git branch available. I don't know if they're using the master branch as the stable branch or what. Doesn't matter, because I don't know what revision of Sinatra works with what copy of Rack. >:(

So I do the next best thing, which is to downgrade Rack to 0.4, which is what the Sinatra gem requires.

Which works. For a bit, until I need to serve up a static html file. I guess that functionality isn't in the Sinatra gem. Some blogs mention how to use the 'public/' directory, which I tried, and failed miserably at; I'm assuming that functionality is somewhere in the github version of Sinatra and not in the gem.

Right around that point I gave up and just cracked out a full-blown Rails project. I copied the logic over, had it up and running in about 7 minutes, which was a stark contrast to the ~2/hrs I spent trying to get Sinatra working.

Lesson?

Next time, just use the latest edge version of Sinatra and hope there are no bugs in it.

This time, I'll just waste two minutes watching the '...'s go by.

Friday, January 02, 2009

My Dirty Programming Secret #424

I develop Ruby on Rails...

...using Ubuntu...

...inside of a virtual machine.