Friday, July 3, 2009

Search keywords in Firefox rock!

I just found a twitter search plugin for Firefox. Cool.

As many know, your non-default search providers show up by clicking a drop-down by the search box. At the bottom of this drop-down, you'll notice Manage Search Engines... link.

Click it. You'll see this.

Manage Search Engines Dialog

Notice the keyword column? Notice the Edit Keyword... button? WTF?

This Mozilla KB article explains it.

See the keywords I added above.

Typing "w Iowa" searches Wikipedia for Iowa.

Typing "t health care" searches twitter for health care.

Sweet!

Saturday, December 27, 2008

Parsing JSON with Unicode in Ruby and Rails

As I've done twice before, I'm going to try to save someone else a couple of hours of hair pulling.

I'm playing with some RESTful web services with a rails app as the client. The service returns JSON.

Cool.

As defined in the spec, JSON strings may contain Unicode characters escaped as '\u four-hex-digits'.

Let's say you had a JSON result with xml, like {"value":"<xml/>"}.

The service might return {"value":"\u003cxml/\u003e"}.

That's fine, except the default JSON parser in rails--ActiveSupport::JSON--doesn't (yet?) support unescaping the Unicode characters.

Boo!

A blog post pointed me to the stand-alone JSON rails gem.

That solved my problem.

Happy hacking, my friends.

Tuesday, November 25, 2008

20 questions/thoughts around MGrammar

I had a great time attending the PDC virtually. Azure, C#, Xaml—these all were cool. The tech I was most excited about was Oslo, specifically building custom DSLs with MGrammar.

Having spent a lot of time in Xaml and C# at Microsoft and migrating to a world of Ruby and JavaScript and HTML/CSS and HAML/SASS, I've had my hands in a lot of tools. And I have lots of questions and thoughts for the community. And, specifically, Chris, Don, Doug, Pinky, and the gang.

When I talk about a 'logical', I'm talking about MSchema in Oslo terminology--at least I think so.

  1. Where  is the MGrammar for C#?
  2. …for VB?
  3. …for CSV?
  4. …for VS Solution files?
  5. …for XML?
  6. Could C#/VB implement their compilers using MGrammar? Should they? Would they?
    • I’m imagining the tools I could write if I had the grammar…and could insert myself in pre-compile stage. Awesome.
    • What an amazing better-together with C#'s new compiler-as-service.
  7. There should be standardized or defacto escape mechanisms for existing grammars.
    • "If you want to inject your own magic into [C#|VB|XML|etc] use this (relatively) safe/constrained notation."
    • I'm thinking about a subset of SASS markup for WPF styles that I could in-line in XAML and have processed at build-time.
  8. Could the MGrammar for XAML just party off the MGrammar for XML?
  9. …could it be written without referring to 'physical' XML, and instead just refer to the XML MSchema model?
  10. If I had a MGrammar for HAML that could generate most of ‘logical’ XML, could I then 'infer' the 'XAML in HAML' using #9?
  11. Will there be tools to go back from a logical model (MSchema) to the input format? I'd like to store data in a logical model, but be able to allow editing via the text format.
  12. How about tools that allow the comparison of two grammars to see if they generate the same MSchema--perhaps with different labels. Perhaps with the ability to convert between them. Perhaps with the ability to identify strict sub- or super-set grammars.
  13. Where is the community site for MGrammar?
    • User-submitted grammars
    • User submitted and verified 'tests' against the grammars
    • Easy tracking of new (and old) versions
    • Easy tracking of forked/related grammars
  14. Want to have MGrammars.com? I registered it for Microsoft. I'll give it to ya'll for free. Just promise to make a great community site.
  15. I'll even build the site for you. It'll give me an excuse to use Azure. I'm happy to offer my consulting services.
  16. Any news with Mono? Is Miguel interested?
  17. Are you making a play to make MGrammar a standard? I've heard yes, but just wanted to confirm.
  18. How is the computer science behind MGrammar? Is it as good/better than existing tools? BNF? Lex/Yacc? Others? Is there a write-up? I'd love to see where MGrammar is pushing the state-of-the-art.
  19. Anyone pushing a normalized Wiki grammar? Like this? Yes, a weird point, but think of how much IQ in the world is stored in Wikipedia and it's next to impossible to parse because MediaWiki format has a bunch of random PHP parsing quirks. A great intern project.
  20. As you can tell, super excited about the project, guys. Keep it up.

Friday, November 21, 2008

Props to Silverlight CLR team: My Common DLL Just Works FTMP

FTMP = For the most part

In Visual Web Developer 2008 Express Edition SP1 .NET XP Live.

  • I created a new Silverlight control library, under my public SVN location.
  • I did the right-click ‘Add Existing Item...’ trick.
  • I navigated to J832.Common and added all of the CS files (except DBUtil and ReaderWriterLockHelper).
  • And I hit build and watch it compile.

The result is a very boring looking directory with great potential: I can now use all of my common tricks in Silverlight, too.

You know, if I happen to be working on something in Silverlight. Hypothetically.

Monday, November 17, 2008

First Project Shipped: What A Lovely Name


It's official.

After an amazing first collaboration with my friends at Jackson Fish Market, What A Lovely Name has launched.

Thanks to...
  • Jenny - what an amazing designer. It was an honor just to be able to set her graphics as div backgrounds.
  • Walter - in a word, brilliant. Turned hours of hacking into moments of enlightenment. He's made me a better [ruby|javascript|css|*nix] hacker and a better engineer.
  • Hillel convinced me to leave a comfortable job at an insurance company and start my own gig--with a story about half-priced pots. I'm not kidding. I'm not sure I would have done it without his encouragement--or prodding. Looking back over what I've done and what I've learned over the last 4+ months, I couldn't be more grateful.
Also thanks to...
  • MacBook Pro for being an amazing piece of hardware, even if it's not the new one.
  • Ruby and Ruby on Rails for challenging my sole devotion to statically typed and compiled languages
  • APIDock for being a great Rails reference.
  • Haml and Sass for making HTML and CSS fun
  • Prototype and script.aculo.us for some amazing Javascript tools
  • ImageMagick for server-side dynamic image generation
  • ssh - I now know how people on Unix get things done
  • git (and for a while Subversion) for version control.
  • pngcrush for making small pngs
  • Capistrano for making deployment easy
  • Mac Ports for making it scary easy to install unix tricks on a mac
  • Firebug for debugging everything. Amazing.
  • Firebox for having an extensibility story that supports things like Firebug
  • Safari for being more stable and more standards-compliant than Firefox a lot of the time
  • VMWare for letting me test IE7 compat without a Windows box
  • IE8 for emulating IE7 so nicely with something approaching reasonable dev tools
  • SliceHost for, well, hosting
  • TextMate for being an amazing editor
  • Skype and Adium for helping me stay in touch
  • Online Coffee Company for keeping me caffeinated
It's been a great ride. Can't wait for the next project.

Wednesday, October 29, 2008

ImageMagick, RMagick, Kerning, and baseline_shift

As I said on Monday, at some point there has to be the first person to blog a useful tidbit in the world of software.

So, for the second time this week, let me be the first.

I've been using ImageMagick--via RMagick--to generate dynamic PNGs on the server.

In general, it's working great, except in one case.

I'm drawing text with custom fonts. The fonts have custom kerning.

ImageMagick seems to handle this fine except when one uses baseline_shift, at which point ImageMagick forgets everything about kerning.

You can fake the baseline shift by using get_type_metrics.

Again, here's hoping this saves someone 20 minutes...or in my case, a few hours.

Monday, October 27, 2008

Ruby, Rails, Render, and the Content-Type HTTP header

Don't you hate it when you google for 30 minutes, trying to solve a simple problem, but for some reason the right combination of terms--or at least the combination of terms you think is right--fails.

It just happened to me with a simple problem: change the Content-Type HTTP Response Header for using standard Rails templates to be text/xml.

The solution is pretty straight-forward:
response.headers["Content-Type"] = 'text/xml'
...as I eventually found here.

Setting this hash value in your ActionController action method does the trick.

Here's hoping google picks this up and saves someone 20 minutes.