Where is map_with_index in Ruby?

Rubyists generally don’t use for loops, because using iterators (each, inject, map) is far easier, to both read and write. But sometimes, we fall back to using each as a for loop when we don’t have to. The enumerable module is pretty rich when it comes to dealing with collections and lists. each_cons, each_with_index, zip, select, reject, and transpose are ones I find myself using often, once I figured out what they were doing.

However, one that eluded me was why there wasn’t a map_with_index in Ruby? Ends up that it’s redundant, because you can simply do this:

%w(a b c d e).each_with_index.map { |val, ind| [val, ind] }

And voila! You have map_with_index. I wonder what other combinations I’m missing out on? Have any of you discovered any?

 

What gems depend on this gem?

The place where you can get information about gem dependencies, study their family tree and even build own graphs form your Gemfile.

Lately, I’ve been looking for various libraries for 3rd party integration to facebook, linkedin, etc, and unlike some areas of ruby gems (web framework = rails/sinatra), there are no clear cut winner that’s a head and shoulder above the rest

So that requires me digging around rubygems and github to find a viable candidate, not just to use, but to contribute to. Sometimes, I would find a great underlying library, like Typheous and wonder what other libraries are using it.

I had a commandline tool that answered that question, but it was slow, since it had to index the gemlist. And plus, I forgot what the command is now.

Behold! Enter GemFamily. This is great because I can look up “what gems depend on this gem?” and see if those libraries are also awesome.

HTTPS – is URL string itself secure??

So yes. The data contained in the URL query on an HTTPS connection is
encrypted. However it is very poor practice to include such sensitive
data as a password in the a ‘GET’ request. While it cannot be
intercepted, the data would be logged in plaintext serverlogs on the
receiving HTTPS server, and quite possibly also in browser history. It
is probably also available to browser plugins and possibly even other
applications on the client computer. At most an HTTPS URL could be
reasonably allowed to include a session ID or similar non-reusable
variable. It should NEVER contain static authentication tokens.

Been wondering this myself for a while, and had been too lazy to look it up until now. Interesting, a number a google services API do exactly this. I hope they eventually move away from it, because once a google account falls, the others fall very quickly.

But then again, AuthSub is deprecated, and OAuth is ridiculously overcomplicated.

Increasing webrick’s URI size when dealing with RequestURITooLarge

I managed to find the file to increase the maximum length in webrick (1.9.2). I changed the hardcoded numbers at lines 246 and 247. You can find the file: ruby-directory/lib/ruby/<version number here>/webrick/httprequest.rb, though i found the file is quite different in ruby 1.8.7.

I was looking for this, and apparently, the only way you can fix it is to change the hardcoded values in webrick. Either change to a different development webserver, or just hack it.