Tuesday, December 23, 2008

Hi from Home

Good to be in the Future Capital of Fun and Great Justice. Being able to sleep on average 10 hours a day being one reason.

Here's something interesting: I told my flatmates I'll be flying home on Friday, and for some reason I decided to get a ticket for Thursday instead. I imagine they'd be wondering where had Ryan gone after some time (they would at least do that!), so I posted a notice. Of course, it's no fun if there's not any hint of playfulness on it, so here's what I came up with:

One of them called at night, just after I left the airport for home, telling me to explain myself.

*

Now, here's another one of the family cats. Tutu:

Does he sleep with one eye open? Only if there's a suspicious looking person pointing a camera at him.

*

Remember the Lego turbine? I decided to take it home and just build it there, even taking into account the risk of feline attacks. It started with this:

After a couple hours, two instruction books, and some photographing:

It can move too, if fed 6 (six!) AA batteries. What it can't do is generate power to charge my gadgets or transform to a giant robot.

Thursday, December 18, 2008

Another Sample

Okay, that small snippet as sample output from the botched code last time wasn't so satisfying. Also, Blogger seems to hate html entities in compose mode, or I'm just too lazy to fix it manually (the acronyser function was bonkers). So, if anyone's going to use that code, be sure to debug it first, have fun trial-ing and error-ing.

So, next showoff output: Hitorigoto from Bump of Chicken. Hitorigoto means talking to one's self. That's one of my many hobbies, but let's not talk about that. Video right after the lyrics.

Hitorigoto

nee yasashisa tte nanda to omou boku sukoshi wakattekita yo
kitto sa kimi ni watasou to shitara konagona ni naru yo

nee kimi no tame ni ikita tte boku no tame ni nacchau nda
hontou sa boku ga waraitakute kimi wo warawaseteru dake nanda gomen ne

hito ni yoku omowaretai dake boku wa boku wo oshitsukeru dake
yasashiku nanka nai sou naritai narikata ga wakaranai

nee kokoro no naka ni nai yo boku no tame no mono shika nai yo
sou janai mono wo watashitai kedo watashitai boku ga iru

nee yasashisa tte nanda to omou sakki yori wakattekita yo
kitto sa kimi no shiranai uchi ni kimi kara moratta yo oboe wa nai deshou

minna yoku omowaretai dake jibun jishin wo urikomu dake
yasashiku nanka nai sou naritai boku ga ichiban hidoi

atama hen ni natta kamo iyaiya itatte matomo dayo
nozomi wa nozomanai koto boku ga shiranai uchi ni kimi no tame ni nareru koto

aa un iwarenakutatte kizuiteru boku chotto kangae sugi
arigatou warattekureta okage de boku mo waraeru

nee yasashisa tte shitteru nda watasenai noni moraeta nda
kitto sa hito to hito no kokoro no soto no naka dake ni aru nda
hitorigoto

kimi ni yoku omowaretai dake boku wa boku wo oshitsukeru dake
yasashiku nanka nai nare ya shinai naritai to omowanai

hitori de wa muri na koto dakara dareka to no aida ni aru kara
dochira no mono demo nai namae no nai sore dake ni deaitai

nee yasashisa tte nanda to omou mou kangaenakutatte ii ya
hontou sa bokura shiranai uchi ni bokura de tsukutta yo

futari deatta yo

Right, the video:

Next, the translation. See if it looks any similar to the word by word translation. The similarities decide how trustworthy are my posted translations so far. Of course, I disclaim accuracy.

Talking to Myself

hey, what do you think kindness is? I think I came to understand it a bit
surely, if I tried to hand it over to you, it would crumble to pieces

hey, even if I said I live for you, along the way it became for me
truly, it's just because I want to laugh myself that I made you laugh, I'm sorry

I want to look nice to people, I'm just pushing myself to them
no way I'm kind, I want to be, yet I don't know how

hey, there's nothing in my heart, there are only things for me
I want to give things that aren't so, but there's myself asking for them

hey, what do you think kindness is? I think I got it just now
surely, I must've gotten it from you when you didn't notice. See, you don't remember it

I want to look nice to everyone, I'm just marketing myself
no way I'm kind, but I want to be. I'm the cruelest

maybe my head's gone bonkers. reluctantly yet intensely, I'm sane and proper
my wish is to not wish, that when I don't notice it's all become for you

ah, yes. I noticed, you don't have to say it. I'm just thinking a little too much
thank you, it's because you laugh that I too am able to laugh

hey, I know what kindness is. It can't be given, but it can be received
surely, it exists in the space between people's hearts
I'm talking to myself

I just want to look nice to you, I'm just pushing myself to you
no way I'm kind, now way I can be kind, I don't even want to

for it's impossible to achieve alone, for it exists between people,
it doesn't belong to anyone, it doesn't even have a name. I want to meet you just like that

hey, what do you think kindness is? Nah, you don't have to think about it anymore
truly, we must've made it ourselves when we didn't notice,

then we met

The comment section of the Youtube page is filled with people saying they cried listening to the song, or something along the way. I guess there's no helping it, the song's pretty charged; I was actually pretty relieved the ending is somewhat a happy end.

Tuesday, December 16, 2008

Vandalising Words

With Python

Some less cloudy evening, I got a little idea: how about posting a song lyrics that if I hover my mouse on a word, I would get the word translation as a tooltip text. Then the idea grew a little: given a lyric and a file with word and translation pairs in it, how about automating the process? The next logical step would be: how about not a file with word-translation pairs, but lookup to one or another web dictionary, how about stemming? Super!

Yet, those logical steps weren't taken. I like instant gratification, so I just set out and try to get my tooltip text without the fancy lookup, stemming, and fancy ribbons. Anyway, with a goal in mind, it's Python time!

The idea is simple: open a lyrics file, break it down into words list. open a diction file (that word-translation pair), break it down into pairs and put them into a dictionary. For every word in lyrics word list, check if there is a data in the dictionary with that word as key. If yes, put it around acronym tag and write to output file, if no, just write the word to output then move along.

Now, at the risk of getting ridiculed by how sloppy it is, the code:

#everything here is put into a function,
#so the module can be imported nicely in command line

#head() is the main function.
#Then we have conditioner() for input conditioning,
#translator() for word lookup and writing output,
#and finally acronyser() that just fill acronym tags with the contents

def head():
  #first get an input romaji and diction file, and decide a name for the output
  inp = raw_input("input file: ")
  dic = raw_input("diction file: ")
  out = raw_input("output file: ")
  #try our best to open it and...
  try:
      inpfile = open(inp, 'r')
      dicfile = open(dic, 'r')
      outfile = open(out, 'w')
  #cry when something goes wrong
  except:
      print "Something went wrong with opening files :("
      return
  #condition the data see conditioner() for details, contains no shampoo
  inpdata, dicdata = conditioner(inpfile, dicfile)
  #we don't need the input files anymore, might as well close them
  inpfile.close()
  dicfile.close()
  #now the fun part, translation and writing output
  translator(inpdata, dicdata, outfile)
  #done! go look at the output and be satisfied

def conditioner(inpfile, dicfile):
  inpdata = inpfile.read().split('\n')
  i = 0
  while i < diclist =" dicfile.read().split('\n')" dicdata =" {}" line =" line.split(None,"> 1:
          dicdata[line[0]] = line[1]
  return (inpdata, dicdata)

def translator(inpdata, dicdata, outfile):
  for line in inpdata:
      for word in line:
          if dicdata.has_key(word.lower()):
              outfile.write(acronyser(word, dicdata[word.lower()]))
          else:
              outfile.write(word+' ')
      outfile.write('
')
  outfile.close()
  return

def acronyser(word, title):
  return "%s " % (title, word)

A little sample of the output from L'Arc~en~Ciel's Anemone:

azayaka na kisetsu aa hana ga saku no matsu koto naku fune wa yuku mada minu basho e shizuka ni moeru honoo wa dare ni mo kese wa shinai kara
Regardless if it's such a good idea in the first place, I had fun doing it.

Saturday, December 13, 2008

Escher Puzzle?

Here's a story: I was looking at jigsaw puzzles, thinking which one would generate the least "what the penguin!?" reaction if a sane person would randomly receive it. I was thinking seriously at getting something with pieces count on the order of 2000 or 3000 before noticing large, framed finished puzzles on the wall and asked how many pieces are they; they're the ones with 2000-3000 pieces, and they're HUGE.

Okay, if I would get one of those, at beginning of 2009 there's a chance I'd be crowned that one mister who ruined someone's holiday because he spent it all assembling a penguined puzzle, so I got a smaller one. That's not the end, of course.

As I was deciding which scenery is the prettiest and hardest to assemble, little boxes at the other end of the store caught my eyes: Ball puzzles, their complete form is a sphere. Now, I just have to try building one of these. My vote was for one with pictures of some of M. C. Escher's works (one of the most potent flummoxative agent known to civilization) on it. Here it is:

The pieces:

This puzzle can't be too hard; the pieces have numbers on the back, see:

I know, blurry picture and all. Believe me, those little black specks are numbers. With that fact in mind, I proceeded with a plan. After all, to fail to plan is to plan to fail.

It's good strategy, not lowly cheating.

Half assembled. By this time I began thinking: They really should make a death star version of this kind of puzzle, I'd hang it above my bed!

Very soon now, very soon.

Here it is. The picture is 'Relativity'. The other side below has 'Day and Night'

My only qualm is that it ends too soon. Anyway, this is not a Gundam kit, I can disassemble and reassemble it anytime with little to no remorse. Yippie?