ask the manowar fan



PortisHead rocks my socks. I love this album called Dummy.

 

Dr. Nic has this article on using XSS which really rocks my socks.

Because, if only I could switch NowPlayingLyrics.com to use XSS it would kill the signature and JAR and which would be oh so damn super cool.

"What have we got?"
Powerman 500- That's Entertainment

 

No sleep till Brooklyn

Posted In: , . By Sid

Snorting brain chemical could replace place sleep

This is the last straw. Now officially when anyones' sleep goes away, it won't hurt anything but ego, which is not cool. Not cool at all.

 



def sort(arr, crit, i)
final = []
arr = arr.sort_by {|a| a.send(crit[i])}
hash = arr.slice_into_groups(crit[i])
sorted_keys = hash.sort_by {|k, v| k}.gimme_firsts
if i < crit.size - 1
sorted_keys.each do |key|
final << sort(hash[key], crit, i+1)
end
else
final = arr
end
return final.flatten
end

class Array

def slice_into_groups(crit)
hash = {}
self.each do |a|
hash[a.send(crit)] = [] if hash[a.send(crit)].blank?
hash[a.send(crit)] << a
end
hash
end

def gimme_firsts
self.collect{|a| a.first}
end



And Tests for the Array code.



class ArrayTest < Test::Unit::TestCase
def test_slice_into_groups
objects = Model.find(:all)
assert_not_nil objects.size
old_size = objects.size

grouped_objects = objects.slice_into_groups('attribute')

sum = 0
grouped_objects.each do |k, v|
sum += v.size
v.each do |obj|
assert_equal k, obj.attribute
end
end
assert_equal old_size, sum
end

def test_gimme_firsts
assert_equal [1, 2, 3, 4, 5, 6, 7], [[1, 2, 3],[2, 2, 3],[3, 2, 3],[4, 2, 3],[5, 2, 3],[6, 2, 3],[7, 2, 3]].gimme_firsts
end
end



This is basically to keep tests in place for MySQL order bys ... which I know make absolutely no sense, but if there's a requirement and someone changes something I like a test to break to tell them I didn't put the order by in there for nothing.

The index passing down the call stack is fairly ugly but I need to find a better way.

"Open your eyes"
Metallica - Invisible Kid.

 

I never knew you could have a horrible Christmas day, I just never knew.

So yes, it's been an injuringly long day, and I'm this close to falling off and falling asleep but I promised myself I'd blog today, so here we go.

One, it's insanely hilarious how I promise myself I'll blog about inane shit like today, and not blog about the stuff I'm doing technology wise, must make note to blog about:
1. Signed Javascript Apps.
2. Deploying them.
3. Making a Rails plugin.

Two, I cannot dance. I'm just not cut out like that. No I'm serious man, I'm sure I'm defective in that way, and my sweet sister has asked me to dance at her wedding on a grand total of four songs. I swear, I was going to fall down and die when I heard that. I mean, yeah four whiskeys later I'm doing all kinds of things on the dance floor, but you're talking about serious choreographer stuff here. I know I'm part of my family and all ... but ugh man, I suck at dancing. The problem is we Sindhis take out wedding dances very very seriously. I remember a time when I was a kid, and dancing used to be fun and I used to be able to do hand stands and be funny and that was acceptable. Now ... well let's not go into that. I know two songs I'll be dancing on so far. Bring It On and Partner. Wheee.

Three, New Years' I will be in Bombay partying it up with friends, so whopeee!!

Four, Christmas ... I did fairly nothing. I've been adding a custom search to the lyrics website and it's not working out well, so I need to work on that a tonne.

Five, I've been playing Devil May Cry 3. And it is damn damn damn kickass.

I think I'll sleep now. I want tomorrow to be a nice day. A merry and nice day.

"Let's put a smile on that face"
The Joker - The Dark Knight

 

I love Windows

Posted In: , . By Sid

I recently chose to Upgrade to Windows XP.

Actually I was always using XP, never going around to the proprietary BS of Vista, I got Windows pre-installed with the work computer, if Skype worked as well on Linux I would never ever use Windows ... except for the occasional game ... and www.nowplayinglyrics.com ... and the DVDs ... and yeah, that's it I just use Linux for work :)

"Dawn of a new day"
In Flames - Dawn of a new day

 

Why So Serious? - The Dark Knight Trailer

Heath Ledger is a crazy person, I'm convinced. It's either that or he's a damn good actor. But seriously, this one promises to be something much more.

Either which way Batman Begins will always be close to my heart.

"Imagine there's no heaven,
It's easy if you try"
Imagine - John Lennon

PS: Creepy lyrics I know, but it just goes well with the motif ... plus I can't stop listening to this song. Have a nice day, put a smile on that face!!

 




Because they will go and get 4.3 Million for the other guy.

 

Now Playing Lyrics

Posted In: . By Sid

I wrote NowPlayingLyrics.com. Check it out. It grabs the Now Playing Song's lyrics for you.

"Zen"
Strapping Young Lad - Zen

 

Rails 2.0 is here

Posted In: , , . By Sid

No really, Rails 2.0 is here

*Jumps up, screams, runs around for a while with arms flailing in the air whilst sweating like a sprinkler. Assaults a two headed-lion, wins the battle, overthrows Ceaser (that little shit), ruins the Kingdom in general, runs into the wall of A-201, breaks the door of the Bossini showroom at Commercial Street in Bangalore. Barks for a day, sits down and installs Rails 2.0 ... because it's supposed to be that damn awesome (seriously read the new features they've pumped in, they even made fixtures better)*

 

There is a God

Posted In: , , . By Sid



And he's a bloody Metal ^%$#ing Head!!!

Metalheads Unite!

 

Gift List ... Final

Posted In: . By Sid

This time, ordered according to priority.

1. NYC vacation: No questions asked. This is and always will be number one.

2. MacBook Pro: I have decided I don't want to go to jail before the age of 30, hence killing Mr. Dude for his black MacBook Pro is not something I want to do.

3. iTouch: It's just so damn pretty. And plus music addiction is so my thang.

4. Books: Somewhat last on the list, because well ... I'm smart already, reading is for people who don't have MacBooks.

5. Uber - God like power: This I know I won't get. But what the hey. I want stuff like teleportation (most important), ability to read people's minds (very cool), super batting power (I'm Indian what to tell you), carrom skills (I just really suck at carrom)

So yes, beer makes me want gifts. You didn't know that did you?

 

Ruby StringIO and clone

Posted In: , , . By Sid


>> a = StringIO.new("abcd")
=> #<StringIO:0xb6e1b354>
>> b = a
=> #<StringIO:0xb6e1b354>
>> b.read
=> "abcd"
>> b = a
=> #<StringIO:0xb6e1b354>
>> b.read
=> ""


Notice the hash signature for b is the same as the hash signature for a. Which is why even though you re-assign it to point to a it's already read the contents of the StringIO you created and hence nils out.

Now see this.


>> a = StringIO.new("abcd")
=> #<StringIO:0xb70570a0>
>> b = a.clone
=> #<StringIO:0xb7055994>
>> b.read
=> "abcd"
>> b = a.clone
=> #<StringIO:0xb7053464>
>> b.read
=> ""


The first time you clone a and point it to b, it creates the hash signature as "#<StringIO:0xb6d968ac>" and the second time you clone it it creates a different hash signature "#<StringIO:0xb7053464>". Hence, multiple clone calls actually still point to different memory space, but it's still the same variable?

Now see this.

>> a = StringIO.new("abcd")
=> #<StringIO:0xb7042240>
>> b = a.clone
=> #<StringIO:0xb7040bfc>
>> b.read
=> "abcd"
>> b.rewind
=> 0
>> b = a.clone
=> #<StringIO:0xb703d1dc>
>> b.read
=> "abcd"
>> b
=> #<StringIO:0xb703d1dc>


Apparently when I clone an object, it still retains the property that StringIO has been read. Which behaves uniquely for StringIO considering the read pointer concept. But yes, somethings amiss.

"I came in with my word,
I will leave with my word intact."
Al Pacino - The Insider

 

Gift Ideas For Me

Posted In: . By Sid

Sammy Larby says it best at his blog


1. JetBrains' IntelliJ IDEA: Already have, use, love, adore.


2. Books:
a. Programming Ruby, Second Edition: Already have, read, slept with.
b. Code Complete 2: Not Read,
c. Agile Software Development: Live by.
d. Principles, Patterns, and Practices: Not Read.
e. My Job Went to India: THE IRONY!
g. The Branson Story: Personal Favorite.
h. The Kite Runner: Beautiful book.
i. The curious incident of the dog in the night time: Nice.
j. To kill a mocking bird: All time favorite.

3. Xbox 360: The office just bought one. So this is also off the list, although ... wouldn't mind having one at home.


4. MacBook Pro: I would kill for this. Like seriously, I might kill this guy I know. He's sitting five feet away from me on his black MacBook Pro, and dammit he keeps shoving his "my textdrive is so awesome and pretty for Rails" line in my face.


5. A Vacation: Now see. NYC, no questions asked.


But yeah, happy gift giving time. I'm gonna be saving up this time. This year has been great though, I'm in one of those resolution moods. *grin*

"A clear song rings in the blade
When steel meets hardened steel
I hear the sound of wood that breaks
A sword cuts through my shield"
Amon Amarth - Valhall Awaits Me

 

Are you smart enough?

Posted In: , . By Sid

Would you put lines on your resume that essentially say:

"(bullet point) I am smart"
"(bullet point) I am awesome"

The premise initially is you would only add a line that says you're smart if you think people wouldn't think that when they read your resume or met you.

But, if that's common sense, then are you smart enough to realize that smart people don't put lines on their resume that say they're smart, for people who don't have enough time to assess that. So, are you smart enough to say you're smart, when all the smart people are really scared of looking like they're trying to hard.

The real question is should I work, or should I work?

I should work.

"Like a bull in a China shop,
But the shelves have all been cleared.
A thief in an empty vault,
The sheep already sheared
A screen door on a submarine,
An eagle with a broken wing,
Hope in a dead man's dream,
The sound of a bell
that will never ring

You're just wasting time "
Lamb Of God - Foot To The Throat

"I like smart, what I don't like is a smart-ass"
Raw Deal

PS: I love today.

 



I don't know much about this, but I like this video particularly. Plus, there's the irony ... this is the internet.

 

Breakfast.

Posted In: , . By Sid

I eat kellog's chocos for breakfast everyday.



It makes me feel like the King of this bloody land.

"Shoot me again,
I ain't dead yet"
Metallica - Shoot Me Again

 

Who put kryptonite in my tea?

Posted In: . By Sid

Some days you wake up feeling like the man of steel. You feel like you take on a hail of bullets and have a Harry Potter to show for it.

Some days someone puts kryptonite in your tea. And you just want to kill something.

You know how some people just never have any luck ordering pizza. You know me then. I've never had a good experience ordering a pizza home, like ever! I don't know why I still do it. I just don't. Every single time I order a pizza it comes in late. So yeah, I can deal with it you know, I'm not exactly the kind of guy that likes to eradicate a people.

Pizza guys are great though, they do this thing with the "I'll give you a 50% off on your next purchase with us" which is so awesome!

Because well you get 50% percent off AND you have to be darft enough to order pizza home from the same idiots who got your pizza late to begin with. I never really followed up with the discount so I don't know if it would happen, but I'm willing to bet they would have got that late too.

What really gets to you though is when you throw your hands up and say:

"Dude, the pizza place is 10 minutes away from the office there really is no excuse for an hour and a half delay. I don't want a discount man, just do something about how you take your orders."

Now, somehow in some weird pigmy ass interpretation Mr. Pizza guy (nameless) interprets that as a "Please say something about discount offers that will insult me."

"Sir, I am prepared to offer you a 15% discount now .... or 50% off on your next purchase."

Honestly man, whoever came up with that kind of an offer should be shot. But more honestly, the guy who took either side of that offer should be mutilated.

Don't ever do that to anyone. Ever. It's just very very hollow. To incite that someone is being greedy is to err. But to incite that someone is being greedy and to make them choose between two options that both have "Sell your soul to me, because I deliver pizza late and throw money at people who complain" is just shit. Have some balls. Take some responsibility, it's okay to go hungry for one night but the satisfaction of telling the pizza guy to shove it makes my day anyday.

And one more thing, don't give in to the rickshawallahs ... ever! Stand your bloody ground, if you belong to Pune, make it your home. Don't let some asshole take it away from you because you're too lazy to walk a few minutes. Make the effort, it's always worth it.

"And then you'll know yourself."
Pantera - Goddamn Electric.

 

Useful Unix Tricks I Stole

Posted In: , . By Sid

Here's some useful Unix tricks I use/should be using at work everyday.

Useful Unix Tricks

Useful Unix Tricks Part 2

Big props to Paul Gross

 

If you have code that uses DateTime.now you ask yourself "How's my test supposed to pass?" and your pair says "I'd peg it at 1 out of ten times" and if your pair is Rohan Kini you know you have a way out.

Let's set it up right. I have this object:


class User

def initialize
@time_of_birth = DateTime.now
@name = "The dude"
end

def take_over_the_world
p "#{self.name} is taking over the world"
end

end


The tests for which look like


def test_if_use_is_born_with_right_defaults
the_dude = User.new
assert_equal the_dude.time_of_birth, DateTime.now
assert_equal the_dude.name, "The dude"
end


Now obviously a few milliseconds might have past since the execution of User.new so odds are your test will fail even though they should pass.

Here's how you change things around a bit.

In your user class you need to abstract the DateTime.now bit, so you can override things in your test


class User

def date
DateTime.now
end

def initialize
@time_of_birth = date
@name = "The dude"
end

def take_over_the_world
p "#{self.name} is taking over the world"
end

end


And in your test override the new date method you created.

NOW = DateTime.now

class << User

def date
NOW
end

end

def test_if_use_is_born_with_right_defaults
the_dude = User.new # Will use now because you've overridden User::date in the context of this test
assert_equal the_dude.time_of_birth, NOW
assert_equal the_dude.name, "The dude"
end