How to find multiple file types using linux’s "find"

I’ve always found *nix’s “find” and “grep” rather hard to use. Not only are there different flavors of regular expressions to use, but mainly different syntax. For find, the directory you’re searching for comes first. For grep, it comes last. To find the negation of something, you’d use “-not” and for grep it’s “-v”. pain.

Anyway, been trying to learn my tools better, and I found out how to grep and replace expressions across multiple files through emacs. Since rails uses all sorts of file extensions, naturally, I wanted to grep for find different files types. I had thought the -name options took regexs (it doesn’t), so I had tried it in regex (no go)…only to find that it’s something like this:


find . -name "*.rb" -o -name "*.rhtml"

the -o is the equivalent of a boolean “or”. small tip…

Advertisements

2D barcodes rebirth

Google just announced 2Dbarcodes for print ads, which prompted Joel to talk about the :CueCat, which was a large failure in the late 1990’s. Wired Magazine sent you these barcode readers shaped like cats with this one issue. The idea was that you could scan barcodes in print ads, and given the URL encoded in the barcode, it’ll take you there in your browser. I can hear wails of people going, “now why would I want to do that?” Of course, that’s from a lack of imagination.

Now, ideas are brilliant or stupid only in the right context. Joel is correct about his assessment of the :CueCat. However, there are instances where it works and is in widespread use.

Japanese print ads have 2D barcodes on them. Even blogs and webpages have 2D barcodes, so you can access information (URL or otherwise) from your phone.

There are a couple things different there. Most Japanese peoples’ access to the internet has been through their cell phones, rather than through their computers. Landlines are much more expensive than having a cell phone. In addition, the majority of Japanese are in urban areas where they use public transportation. That gives them a lot of down time to play with their phones. The print ads in the train have the 2D bar codes on them, so people can check out the ad while they’re riding the train. Given that unless you have a full keypad (real or virtual), it’s still harder typing in a phone, than using a 2D barcode.

That said, I don’t think Americans (Don’t know about europe) will find as much use for 2D barcodes for print ads, as we drive everywhere. The tech world has changed a lot since the :Cuecat was around, so I think most of the right players are in place for 2D barcodes. I don’t think having 2Dbarcodes in newspapers makes sense. It makes much more sense for print ads, you can see on the street in strictly urban areas, like New York City.

If I’m walking around town, I’d find it very handy to be able to check out how many tickets are left for a show and being able to buy tickets for the show from the URL in a 2D barcode on the print ad for a show across town. It would also be useful if sewn onto tags of pillows, clothing, other products, etc, so that would provide product information, or at least a URL that has the manual, or specs. That way, if some piece were broken, it’d be an easy way to order replacement parts.

I think it’s a tiny, tiny step into tying the real world with the virtual, and part of the move to form a Clickable Earth.

Making sure extra tasks get run when installing plugins with Piston

When I graduated college, I was a EE major that could code. However, in hindsight, I don’t think I was as good because I had no idea how to put together moderate sized systems or above. One of the things that I like about Rails is that they have a system for plugins. I was too uncouth to consider it before. Once you extract a plugin out, you essentially have to treat it as a separate library or package. This forces you to encapsulate, because it’s a bit of a pain changing plugins. I know you can extract code out to DLLs or Gems, but I never did it because it seemed like I didn’t need it–plus it was extra steps.

I eventually would want a programming language that lets me extract out libraries inside the language, and make its public interface RESTful, and auto-extern its path in SVN and whatever the equivalent is in distributed version control like git/darcs.

Recently, I’ve started using Piston. It’s a ruby plugin manager that’s essentially a wrapper around svn:externals. It’s been pretty easy to use. In addition, my plugins won’t get stale. However, when you install a plugin with piston, you only import the files. It doesn’t actually execute the install.rb file, like /script/plugin install would. I’ll try to see if I can submit a patch to piston later, but for now, simply run “install.rb” in the root of the plugin, and it should do the install for you. small tip!

Interfacing and distributing code as a language feature

Recently, I’ve been looking to send email from erlang. Despite all the cool things it does, its INets library doesn’t have an SMTP client in it. Trapexit happened to be down this week, so I ended up hunting around on the web (next time, I should just ask on newsgroups).

I found ErlMail as part of an Erlang Software Framework suite, and it had a simple SMTP client in it. I was glad I didn’t have to write one myself, but I found it didn’t do authentication. it was written cleanly enough that I was able to patch in authentication without much of a problem, and submitted it to the maintainer.

The short experience made me pretty thankful that SMTP protocol is in plain text, rather than bit-packed. Since much of our general purpose languages are pretty good at manipulating text, it’s comparatively easy to interface with it and write a wrapper for it.

However, it’s a pity that for every new language that comes out, a new wrapper must be written for an SMTP client. Same goes for REST/SOAP interfaces for any number of APIs that we see out there, from Google maps to facebook apps.

Part of the problem is the mismatch in syntax of the protocol/interface and the language the programmer is working in. Simply looking at REST interfaces, there’s no programming language that makes native method calls like /post?title=32?body=f1rst%20post. Not that would make sense to do so since there are other RPC (remote procedure call) protocols too.

The only way I can see out of it is for a language(or library) dynamically generate code that maps a native call syntax to a RPC syntax. For every new type of RPC interface (REST, SOAP, JSON, etc.), we’d have a single file that describes the mapping. Then, when a new service or platform comes out with a REST interface, you don’t need to write a new wrapper for that interface.

However, lots of languages have different method invocation capabilities. Some need types to arguments, others can take first class functions or blocks, and still others can take an unknown number of arguments. I don’t think it would be easy, but it’d be nice to have so we stop wasting our time writing interface wrappers. Maybe Lisp was on to something when it said code is data and data is code.

XMPP for machines

Jive Talks: XMPP (a.k.a. Jabber) is the future for cloud services

I found this great because it gave me a way to think about something familiar in a different way. I’m use to thinking about XMPP as just an IM and presence protocol, used by applications that let humans to communicate with other humans. But I didn’t take it one step further and think of it as a messaging service between machines, mostly because I was under the impression that polling problem was solved (by the likes of Comet).

If this is possible, then by the same token, one should be able to run a “IMsite” over XMPP, analogous to a “web site” over HTTP. It’s just that there currently is no “browser” for XMPP. If there were, you can technically send DOM updates or javascript (or whatever the browser can interpret) over XMPP. I imagine one should be able to take the mozilla engine and tack XMPP instead of HTTP in front (probably easier said than done).

That way we should be able to build browser apps that need near-real-time updates. The obvious one is chat. In fact, most of our XMPP clients are specialized to do that. Other applications are collaboration software, like a shared whiteboard (if sending SVG over XMPP would not be a bandwidth hog). Video lectures with auto advancing slides might be another one. Fleet tracking might be another. MMORPGs would also be easier to write on such a platform. It’d be interesting to see where this goes.

Update: Looks like people already tacked XMPP onto Mozilla

Getting inline-block working across browsers

In mobtropolis, there’s a gallery of pictures that I have to show. While, normally, it’s not too hard showing them as inline elements, if you just have pictures, it gets a bit tougher if you have a bunch of stuff that you have to inline correctly. Sites like facebook solve the problem by using a fixed layout, so you know the width of the area you can work in, and can thus use a table.

When you have a stretchable layout, however, that doesn’t work. And what you need to do is use CSS, “display: inline-block” The problem is, it doesn’t have consistent support across browsers. Only Opera and Safari use “display: inline-block” and “display: inline-table” correctly. IE6 and Firefox both use “display: inline” only and don’t recognize inline-table and inline-block.

So thank goodness for design blogs out there: Align List Items Horizontally with CSS . His solution is a bit of a work around, but it prevents me from writing any javascript when I didn’t need to.


.ib-fix li { display:-moz-inline-box; -moz-box-orient:vertical;
display:inline-block; vertical-align:top; word-wrap:break-word; }
* html .ib-fix li { display:inline; }
* + html .ib-fix li { display:inline; }
.ib-fix li > * { display:table; table-layout:fixed; overflow:hidden; }

I should add that you need to also add this to get it to work in IE6, and get rid of the weird padding on the left:


ul.ib-fix
{
list-style: none inside none;
padding: 0px;
}

Yay. small tip! As a bonus, I also found out about ie7.js, a javascript library that fixes incompatibilities in ie7 and ie6.