/images/bio-photo-small.jpg

Shallow and Pedantic

A person/tech/code blog of a coder/techie/person. Like calculus in a kiddie pool, the author of this blog is known to be quite shallow and pedantic.

Three things I didn't know Ruby does

Edit: I was misled!

Illustrated here. Hints below.

>> def inspect_x_and_y(x,y); puts "x: %p, y: %p" % [x, y]; end
=> nil
>> inspect_x_and_y(y={"hello" => "world"},x=[1,2,3])
x: {"hello"=>"world"}, y: [1, 2, 3]

The bits I didn’t know about:

  1. "Format strings using a %% sign, %s, %s!" % [ "just like in python", "but with arrays" ]
  2. The %p formatting character is the same as inspect.
  3. You can call methods with method_name(param2=val2, param1=val1), also like in python. No you can’t! This code sets external variables called y and x.

How embarassing… :(

Gettext oddities with Ruby

I was having a lot of trouble with gettext in Ruby, mostly due to lacking documentation. Here are some useful things I figured out while writing TTime. I ended up having a single gettext_settings.rb, included from every file which uses gettext. Here it is (with some extra notes)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/ruby
begin
  require 'gettext'
  require 'pathname'

  include GetText

  # This fixes a swarm of problems on Windows
  GetText.locale.charset = "UTF-8"

  # Ruby's gettext acts in a sane
  # method - add a path to the set of paths
  # scanned.
  locale_in_data_path = Pathname.new($0).dirname + \
    "../data/locale/%{locale}/LC_MESSAGES/%{name}.mo"
  add_default_locale_path(locale_in_data_path.to_s)
  bound_text_domain = bindtextdomain("ttime")

  # For Glade, however, it only seems to
  # be possible to specify one path at a
  # time. Fortunately, gettext already
  # found it for us.
  my_current_mo = bound_text_domain.entries[0].current_mo
  if my_current_mo
    ENV["GETTEXT_PATH"] = my_current_mo.filename.gsub(
      /locale\/[^\/]+\/LC_MESSAGES.*/,
      "locale/")
  end
rescue LoadError
  def _ s #:nodoc:
    # No gettext? No problem.
    s
  end
end

One note for context: I use setup.rb (and ruby-pkg-tools) to package TTime. So my localizations go in data/locale.

That "Life" category there

I has it. Sorta.

A few weeks ago, the lovely NaNuchKa visited Israel for two and a half shows (the half-show was warming for Berry Sacharof). “Three shows in two weeks?”, people ask - well, yeah. They only come once a year. Their set is already too long to play all the songs I like, and that’s actually quite excellent - new EP and all. Great stuff :) Deep Purple should be coming to Israel this summer (holy crap!), and I need to see what I can do about getting tickets for that.

Been working on TTime

I’ve found myself working on TTime, the Technion Timetable Scheduler, quite a bit lately. Lots of cool stuff went in:

  • Boaz Goldstein’s TCal, a Cairo-based schedule renderer (could you believe the old version used MozEmbed?)
  • Sports courses are now correctly parsed
  • Ability to select specific lectures and groups for the automated scheduler
  • A manual scheduler - given an existing schedule, you can ask to show all alternatives at once, and hand-pick them. Some people (Tom, for example) prefer this.
  • Just for kicks - interoperability with Grandpa’s XML format

I’ve also cleaned up the packaging quite a bit - it can now be installed using setup.rb, or the updated Debian package. I think it may soon be time to tag a release :)

Tunelling even more stuff over SSH

Today at the CS department of the Technion is a particularily Bad Network Day (TM) for laptop users; none of the wired connections at the farm work, and wireless doesn’t seem to working for HTTP at all.

It does, however, work for SSH. Ka-ching! :)

Tunneling your browser over SSH is a pretty simple affair - SSH into somewhere which has a decent connection, and use the -D9999 flag (9999 works, but it can be any 16-bit number over 1024). Then, configure your browser to work over a SOCKS proxy at 127.0.0.1:9999.