A Place for my head

On Ruby, Rails, Concurrency and fiction

Archive for November, 2007

Posted in : java, rails | No comments

I had to recently write a smallish TCP/IP server in Java. It has to be written in Java, because of yet another obsession of corporate world with Java. The API that I had to use was javish, and although people who wrote it, would claim that API can be used easily in any language, it was not so. Whats more, I had to use that API from rails, so you can understand my situation.

Well, So i googled and found the book for “Java Network Programming, Third Edition”.
Java Network Programming

What a crap. My main issues were:

  • I hate a book, which pretends that its examples are ready to run, but they don’t run, because they need tinkering. I am all for snippets, that demonstrate a thing or two. But when you are saying, ok this example is ready to run, with import and everything in place and It doesn’t run on actual machine, it just freaks me out.
  • Although the book has 776 pages, its surprisingly free from useful stuff. Seriously, when I compare this with book by Richard Stevens, this book looks like shit. Although author had more scope here on how to write REALLY scalable networking applications. He wasted 776 pages, talking nothing and perhaps reserved good stuff for “Advanced Network Programming with Java” ( Soon, after reading the book, I found that indeed there is a book on Advanced Network Programming )
Posted in : rails | No comments

Our flash guy, uses usual loadVars for loading external data in a flash movie and do some funky stuff like plotting of nice looking portfolio charts.
Portfolio Chart

But somehow, we saw some issues with loading of charts in IE6 running flash. A quick ethreal packet sniffing showed us, that although client is making
request with “Accept-Encoding: gzip,deflate”, its not able to decode the gzip response of web server. And parsing of gzipped response at flash obviously fails.

This is quite a corner case, I suppose, but I did this, to prevent Content-Encoding for that particular controller.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class OutputCompressionFilter
  def self.filter(controller)
    controller.response.headers['Content-Encoding'] = 'identity'
  end
end
 
class FlashController < ApplicationController
  no_pref true
  after_filter OutputCompressionFilter
  layout :set_layout
  include REXML
  def index
  end
end
Posted in : Uncategorized | No comments

Heck, my all attempts to manage a todo list has failed.

I tried these in order:

  • dev-to: A command line todo list handler
  • Emacs-org mode
  • gTodo : A Gnome TODO thingy
  • Tomboy: Tried few times
  • Evolution: todo thingy

What does it indicate, time to write yet another todo manager for gnome?

Posted in : Radiohead, boc | No comments

I mean and I really mean, these guys are brilliant. I can’t really say, what I like in their music, but all their tunes sound oddly familiar and coming from a distance, like a bazooka from past. I love it, I wish I could do that.

Terrifying thing is, they are not afraid to release their albums in numbers like 100 or even 5. Now, how the hell, a poor guy sitting in India would ever get his hands on something like that. I am yet to see any of their records on a music store shelf.

Here Marcus talks about artists who are too fucking big:

“No. We think they’re brilliant,” Michael demurs. “I think Kid A’s the best thing they’ve ever done,” adds Marcus in his thicker Scots slur.
“Artists whose status is somewhere between Radiohead and God,” answers Marcus, mystifyingly

Above quote is the context, when Marcus criticizes mainstream musicians or rather musicians who make
music based on pop culture. The interviewer prompts,

“Who are these Bigger Guys, Radiohead?”

Needless to say I hate this moron of interviewer.

Posted in : Radiohead | No comments

I was listening to this song for quite sometime and was wondering, what the hell it means?
Then suddenly it came. I am not sure, if i am on the mark:

I am the next act
Waiting in the wings
I am an animal
Trapped in your hot car
I am all the days that you choose to ignore

I think, “I” is not a person, but its your innocence, its your playful spirit, who
has been lost in this material world. I know, you would say,
this theme has been repeated so many times, so
whats new?

Really isn’t it, “The song remains the same!”? True, I love the song.

Another paragraphs is:

I am a moth
Who justs wants to share your light
I am just an insect
Trying to get out of the dark
I will stick with you, because there are no others

Awesome. Is there a hope?

Posted in : backgroundrb, rails, ruby | 1 comment

Assuming nobody is reading this, I would quietly mention that, I released new version of BackgrounDRb plugin today.
Checkout full announcement here:

http://rubyforge.org/pipermail/backgroundrb-devel/2007-November/001043.html

Here is a sample worker:

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
class FooWorker < BackgrounDRb::MetaWorker
  set_worker_name :foo_worker
  attr_accessor :count
 
  def create
    puts "Starting Foo Worker"
    @count = 0
    add_periodic_timer(4) { increment_status}
  end
 
  def process_request p_data
    user_input = p_data[:data]
    result = self.send(user_input[:method],user_input[:data])
    send_response(p_data,result)
  end
 
  def increment_status
    puts "Registering status"
    register_status("stuff #{rand(10)}")
  end
 
  def foobar
    puts "Invoking foobar at #{Time.now}"
  end
 
  def add_values user_input
    p user_input
    return eval(user_input)
  end
end
 
=begin
  problems, with existing things.
=end
Posted in : REM | No comments

I don’t want to disappoint you
I’m not here to anoint you
I would lick your feet
But is that sickest move?
I wear my own crown and sadness and sorrow
And who’d have thought tomorrow could be so strange?
My loss, and here we go again
REM

Posted in : ruby | No comments

If you have any hopes of becoming a Ruby guru, then regular dose of ruby-talk is a must. In this post, I would try to summarize some of the cool stuffs being discussed on ruby-talk.

  • In Ruby, having method names that contain “-” can be PITA. So David Black and others were quick to point following approach of doing so:

    1
    2
    3
    4
    5
    
    irb(main):002:0> class C
    irb(main):003:1>   define_method("x-y") { puts "Weird method" }
    irb(main):004:1> end
    # At which point, the only way to call it is:
    irb(main):005:0> C.new.send("x-y")   # Weird method

    In other words, it’s not worth the trouble and you should find some
    other solution.

  • Trans asked on ruby-talk, how can we know, which files are loading or requiring this file. Ara pointed following solution:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    p Kernel.requiree('main')
     
    require 'b'
     
    p Kernel.requiree('main')
     
    BEGIN {
      module Kernel
        h = Hash.new
        define_method(:requiree) do |of|
          h[of]
        end
     
        r = method :require
        define_method(:require) do |*a|
          r.call *a
          h[a.first] = caller
        end
      end
    }

    The interesting bit around, should be noted.

    1
    
      r = method :require

    When you call method and pass method name as a parameter, it returns a closure. Although as pointed by someone it breaks “Rubygems”, and above approach shouldn’t be used. Rather, one should use:

    1
    
      alias_method :old_require, :require