Split and Join: Using Ruby arrays and CSV files as databases 1
If you mess around with CSV or other text delimited files and you use Ruby, you should know all about String::split and Array::join. If you don’t, here’s a quick primer. Split allows you to break up a string into elements of an array based on a delimiter (it returns an array). Join will merge an array into a single string, using a delimiter to separate the array elements.
Determing File Paths for Action Caching in Rails
I just spent some “quality time” figuring out how to programatically determine the location of an action cache file in Rails. “cache_action” is a great tool and when applied properly can really save cpu. To find the file locations for this cache you could clearly hack your way in, but it’s harder than with page caches, because the *machine name* is included in path. Hassles!
HTML Tools I wish I didn’t need 2
Some tools no matter how great are just a bummer. The work that is implied by their existence outweighs their inherent, internal elegance. Charlton Heston / NRA has kindly pointed out that the gun is such a tool (though I don’t think they’re thinking of it in this way).
I use three excellent tools that I wish I had never needed to begin with - but HTML and HTML browsers being what they are, you might as well know about these tools too.
MP3 Playlist (M3U) File Creator 1
I’ve been using this little utility for a while and thought others might like it too. It’s a Ruby script that creates M3U files for MP3 Players - basically playlists. It’s not fancy but lets you script creation of arbitrary M3U files for any number of folders. It automatically processes subfolders as well.
GeoX Rails Geocoding Plugin 13
Science is happy to release an open source geocoding engine built in pure Ruby for the Ruby on Rails environment. You can down load the plugin by following instructions here. (Update 10/21/07 - new features!)
The engine is capable, out of the box, of using MapQuest, Google and Yahoo API’s. All you have to do is obtain a free API key from the provider of your choice. If you get one from all three, you can play around to see which one you prefer.
Your input and comments would be welcome.
Ruby ZLib buffer error on Windows 10
I have some utilities to read and write zip files in an application I maintain. I’ve been periodically running into “buffer errors” in the GZipReader library of Zlib. I’ve been working around the errors in various ways but today I finally got stopped cold and had to figure out what was going on. It turns out that the RubyGems people have also seen this error and wrote some code to solve it. So I adapted their code to my purposes and I’ll share what I’ve got in hopes that someone else can use this stuff too.
Obtaining a block of ids from a sequence in PostgreSQL 1
![]()
I had a need to obtain a block of ids from a sequence in Postgres. Sequences are used primarily for issuing unique id’s for primary keys. Normally they are issued one at a time. But periodically one needs to obtain a large block of ids. It’s possible to accomplish that just by looping over the sequence issuing function “nextval” sequentially until the correct number of keys has been issued - there’s no guarantee that you’ll get a block - you may get a non-sequential set depending on other table activity. So I talked with the postgres sql list about this and they helped me come up with the following solution, which appears pretty reliable and has relatively low downside.
Ruby: Defining Instance and Class methods in Modules 1
I wish someone had shown me how to use Module methods correctly for creating “multiple inheritance” like features in Ruby. The “Pickaxe” book does a pretty good job (pub. Pragmatic Programmers) but all the info was scattered around a little. I thought I’d share a short piece of code which demonstrates easily how to introduce module methods into classes. You can install them either as class methods or instance methods. When referencing variables in these modules (such as “self”) after you install them into a Class, those references will refer to variables inside the Class, which is very handy. Ruby uses quite a bit of this internally, to implement iterators and other functions across multiple classes - in fact you can implement Classes and mix-in iteration if you support a few underlying functions that the iterator module needs to function.
Suppressing output in Ruby/Rails 1
Sometimes external libraries send warning or console output without asking in Ruby. Very rude! It turns out there is a nice library out there that helps with this problem - and the good news is that this library is already built right into Rails so if you’re developing with this framework you have this tool at your fingertips.
