kyoto dreams
Saturday, March 25, 2006
  Degrees Famous people don't come from the Famous People Machine. They come from wombs of mostly not famous people and they grow up with mostly not famous people. We are surprised when someone we know knows someone famous.

Famous people are famous for differnet reasons, but we like famous people for one reason. Becuase they are familiar and shiny.

New is so we can tell what's old. Probably not, but it almost works. Different tells you that it's new. It's not new though, it's just different. Differently the same by most measures. 10 t-shirts mostly the same, different color and logo. Difference = very small. 
Wednesday, January 11, 2006
  Transformed Given the code below. Will it compile?

\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u0053\u0077\u0061\u0070\u0070\u0065\u0072\u0020\u007b
\u000a\u0020\u0020\u0020\u0020\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0020\u0061\u0072\u0067\u0073\u0029\u0020\u007b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0020\u006e\u0031\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0028\u0032\u0036\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0020\u006e\u0032\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0049\u006e\u0074\u0065\u0067\u0065\u0072\u0028\u0033\u0039\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u006e\u0031\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u006e\u0032\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0073\u0077\u0061\u0070\u0028\u006e\u0031\u002c\u0020\u006e\u0032\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u006e\u0031\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u006e\u0032\u0029\u003b
\u000a\u0020\u0020\u0020\u0020\u007d
\u000a\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u0073\u0077\u0061\u0070\u0028\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u006f\u0031\u002c\u0020\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u006f\u0032\u0029\u0020\u007b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u0074\u006d\u0070\u0020\u003d\u0020\u006f\u0031\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u006f\u0031\u0020\u003d\u0020\u006f\u0032\u003b
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020
\u000a\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u006f\u0032\u0020\u003d\u0020\u0074\u006d\u0070\u003b
\u000a\u0020\u0020\u0020\u0020\u007d
\u000a\u007d
 
  Caster 3 Given the class below. Will it compile?

If so, what's the output?

If not, how would you fix it?

public class Caster3 {
public static void main(String[] args) {
Object i = new Integer(32);
Integer o = (Integer) i;

out((Object) o);
}

static void out(Object o) {
System.out.println("Object out");
}

static void out(Integer i) {
System.out.println("Integer out");
}
}
 
  Caster2 Given the following class. Will it compile?

If so, what's the output?

If not, how would you fix it?


public class Caster2 {
public static void main(String[] args) {
Object i = new Integer(32);
Integer o = (Integer) i;

out(o);
}

static void out(Object o) {
System.out.println("Object out");
}

static void out(Integer i) {
System.out.println("Integer out");
}
}
 
  Test Consider the class below.

Will it compile?

If it would, what is the output?

If not, how would you fix it?


public class Test {
public static void main(String[] args) {
if (false) {
System.out.println("world peace");
}

while (false) {
System.out.println("fair and balanced");
}
}
}
 
  Finally Given the code below. What is the output?

public class Finally {
public static void main(String[] args) {
foo();
}

static void foo() {
try {
System.out.println("try");
System.exit(0);
}
finally {
System.out.println("finally");
}
}
}
 
  Invoke2 Consider the code below. What is the output?

public class Invoke2 {
public static void main(String[] args) {
Integer o = new Integer(47);

out(o);
}

static void out(Object o) {
System.out.println("Object out");
}

static void out(Integer i) {
System.out.println("Integer out");
}
}
 
  Caster Consider code below.

Will it compile?

If so what is the output?

If not, how would you fix it?


public class Caster {
public static void main(String[] args) {
Integer o = (Integer) new Object();

out(o);
}

static void out(Object o) {
System.out.println("Object out");
}

static void out(Integer i) {
System.out.println("Integer out");
}
}
 
  Invoke Consider the code below. What's the output.

public class Invoke {
public static void main(String[] args) {
Object o = new Integer(47);

out(o);
}

static void out(Object o) {
System.out.println("Object out");
}

static void out(Integer i) {
System.out.println("Integer out");
}
}
 
  Swapper Consider the code below. What is the output.


public class Swapper {
public static void main(String[] args) {
Integer n1 = new Integer(26);
Integer n2 = new Integer(39);

System.out.println(n1);
System.out.println(n2);

swap(n1, n2);

System.out.println(n1);
System.out.println(n2);
}

static void swap(Object o1, Object o2) {
Object tmp = o1;

o1 = o2;

o2 = tmp;
}
}
 
Friday, January 06, 2006
  Three The following code compiles and runs, but only 1 thread is ever created. What is the problem and how would you fix it?



public class T extends Thread {
public static void main(String []args) {
for (int i = 0; i < 10; i++) {
T t = new T();
t.run();
}
}



public void run() {
while (true) {
System.out.println(System.currentTimeMillis());

try {
Thread.sleep(1000);
}
catch (InterruptedException e) {}
}
}
}


 
Thursday, January 05, 2006
  Two Consider the code below.

When run, what is the output and why?


public class A {
private int count = 1;


public static void main(String []args) {
B b = new A().new B();
}

class B {
private int count = 2;

B() {
System.out.println(count);
}
}
}
 
  One Consider the code below.

1. Will it compile?
2. If so what is the output?
3. If not, why not, and how would you fix it?





public class Foo {
private int count = 1;

public static void main(String []args) {
new Bar();
}
}

class Bar extends Foo {
public Bar() {
System.out.println(count);
}
}
 
Thursday, August 18, 2005
  Talking out of both sides of your neck I hated Nick Cannon the first time I saw him. I can barely keep my Amy's Burrito Especial down when I see his bubble gum bullshit ass in a movie or on television, so I understand the natural, visceral revulsion that any sane person feels at the site of such a patently plastic, swimming in backstreet boys juice, made for tv personality. But I don't understand the recent hate being directed toward him because of his song, Can I Live. I smell bullshit.

His song, which I think most people would agree is pro-life, tells a story about a young woman who's pregnant and thinking of getting an abortion. It describes her feelings and is told from the perspective of the child/fetus/sperm bud/non-life/life/whatever inside of her who asks her the question, "Can I live?" The song is apparently about his mother who considered having an abortion when she was pregnant with young Nick.

A bunch of people are writing, and I assume saying, shit about how he's out of line and has no right to judge people. I won't go into how stupid it is to pretend to believe in someone's right to abort a child and at the same time claim that someone else doesn't have the right to judge them for it. That's simple bullshit.

The hate he's getting seems to be directed at him simply because he's voicing an unpopular popular culture opinion. That's ironic. I believe most of the people spewing the hate would defend, at least verbally and anonymously, his right to "tell his story" if "his story" involved smok'n weed, shanking niggas, and sticking his dick down some ho's throat. That'd be alright. That seems like bullshit. If it's ok to degrade yourself, your race, your family, your neighborhood, and women, then it's certainly alright to throw a couple of jabs at somebody whose choices you disagree with.

I'm pro choice, pro death penalty, pro euthanasia, pro viox, pro toxic shock syndrome, pro partially hydrogenated soybeen and/or cottonseed oil, pro jihad, and pro anything else that'll get another stupid motherfucker off this rock before me, but please be consistent. 
Monday, June 06, 2005
  42 lbs. About three years ago I weighed about 200 lbs. Today I weigh 242 lbs. That's 42 pounds of fat. Holy mother of God.

Being fat sucks and not for the popular reasons. Being fat sucks because it's physically uncomfortable. For instance, I get winded walking to my car, none of my clothes fit, it's hard to get out of chairs, and I sweat all the time (a situation exacerbated by living in the weather armpit of the United States). By the way, I know exactly why I'm fat. I'm not big boned, it's not a hormone thing, my family's not big, and I don't eat because I'm sad or lonely. I'm fat because I eat a lot and I don't move that much. I like to eat, and the not moving thing just works for me because it's easy.

But I guess the party's over, it's time to lose weight again. That's almost a shame though. Even though it's exhausting and uncomfortable, I think I'm gonna miss being big. I've been told that in some countries being large is a sign of wealth and in some others it's a state reserved for royalty (I have really bad sources). I can believe that though, I often feel like a king. But I'm definitely tired of pulling my shirt out of the sweaty fold in my neck, so it's time to hit the treadmill again.

The only reason I wrote this is because when I realized that I'd gained 42 pounds of sweet fabulous fat, I wondered what 42 pounds looked like. I couldn't find anything that weighed exactly 42 pounds, so I weighed a couple of things around the house. Here are my findings.

Container full of shoes, 34 pounds


Toddler picnic table, 15 pounds


Pile of books, 30 pounds


Mini-Disc/CD Player, 14 pounds


Vacuum cleaner, 24 pounds


Phone Stand, 16 pounds


Mini-Me, 30 pounds

 
Saturday, May 14, 2005
  It's just like magic it all starts with a simple idea. export playlists from itunes to my dlink media thingy so i can listen to my current batch of favorites.

seems rational to me. the dlink thingy supports playlists and itunes supports exporting playlists. let's go... several minutes later. bad news, flappy, the dlink thingy only supports playlists that are created on the dlink thingy via the lame ass, finger contorting, obviously designed for aliens remote control. that sucks.

well, me mate from work (mate because he's british) told me about a neato sounding media server called twonkyvision which claims to be compatible with the dlink. so i download the free version and get it running pretty quickly. it works great. sorry though, flappy, old chum, more bad news. the playlists exported from itunes aren't m3u playlists, which is what twonkyvision supports. ok, how bad could it be. i take a look at the file created by itunes.

G:\media-server>cat fourteen.txt
ÿ_N a m e A r t i s t C o
p i n g G e n r e S i
b e r D i s c C o u n t T r
u n t Y e a r D a t e M
t R a t e S a m p l e R a t

seems like a simple tab-delimited file.

i google for the m3u file format. The format is straightforward and clear and the page gives great explanations of the fields.

#EXTM3U
#EXTINF:111,3rd Bass - Al z A-B-Cee z
mp3/3rd Bass/3rd bass - Al z A-B-Cee z.mp3
#EXTINF:462,Apoptygma Berzerk - Kathy´s song (VNV Nation rmx)
mp3/Apoptygma Berzerk/Apoptygma Berzerk - Kathy's Song (Victoria Mix by VNV Nation).mp3
#EXTINF:394,Apoptygma Berzerk - Kathy's Song
mp3/Apoptygma Berzerk/Apoptygma Berzerk - Kathy's Song.mp3
#EXTINF:307,Apoptygma Bezerk - Starsign
mp3/Apoptygma Berzerk/Apoptygma Berzerk - Starsign.mp3
#EXTINF:282,Various_Artists - Butthole Surfers: They Came In
mp3/Butthole_Surfers-They_Came_In.mp3


both in and out look simple, so i vim a perl script to parse the itunes file and print the info to stdout as m3u. one test run and i can see this won't be as simple as i thought. seems the itunes file is unicode (as evidenced by the spaces between every character, doh!).

holy bleeding piehole, how's this gonna work. i know jack about unicode in perl. but wait! java is unicode from the inside out, right? one quick file parsing class later and the answer is quite obviously, no. same exact problem as before. oh no, i'm going to have to read some more. i take a quick look at the file in binary:

FF FE 4E 00 61 00 6D 00 - 65 00 09 00 41 00 72 00 ..N.a.m. - e...A.r.
74 00 69 00 73 00 74 00 - 09 00 43 00 6F 00 6D 00 t.i.s.t. - ..C.o.m.
70 00 6F 00 73 00 65 00 - 72 00 09 00 41 00 6C 00 p.o.s.e. - r...A.l.
62 00 75 00 6D 00 09 00 - 47 00 72 00 6F 00 75 00 b.u.m... - G.r.o.u.
70 00 69 00 6E 00 67 00 - 09 00 47 00 65 00 6E 00 p.i.n.g. - ..G.e.n.


it looks like the 2 leading bytes are significant because they don't seem to have anything to do with playlists. i google "FF FE unicode". bahm! some page on msdn reports that these 2 bytes are known as a byte-order mark:

EF BB BF UTF-8
FE FF UTF-16/UCS-2, little endian
FF FE UTF-16/UCS-2, big endian
FF FE 00 00 UTF-32/UCS-4, little endian.
00 00 FE FF UTF-32/UCS-4, big-endian.

a little more reading and i now know that the InputStreamReader class has a constructor that allows you to pass in the character set used by the stream being read. taking my cue from the above table i use:

new InputStreamReeader(fileName, "UTF-16");

everything goes well. a couple of tweaks later and wallah, all hail the rudimentary itunes2m3u utility. it works well enough. twonkyvision likes the m3u files and the dlink loves twonkyvision. i listen to music for 5 minutes and then go back to playing with virtualdub.

the whole adventure took about 45 minutes.

...24 hours later...

weeeehhhhhhhhhhhhh!!!!, ala pwned

some of the exports are not coming out as utf-16 any longer, so i changed the util to take the character set as an argument and default to us-ascii. i hate computers, i hate itunes, i hate programming, and i know it's really all my fault.


warning! crude code ahead
here's the utility for educational purposes :

import java.io.*;

public class Ipod2M3u {
public static void main(String []args) throws Exception {
String file = args[0];
String charset = args.length == 1 ? "US-ASCII" : args[1].trim();


BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
String line = null;

// throw away first line, it's a header
line = in.readLine();

System.out.println("#EXTM3U");

while ( (line = in.readLine()) != null ) {
//System.out.println(line);
String []fields = line.split("\t");

// if we're missing fields, it's probably
// because the info is split between 2 lines
if ( fields.length < 24 ) {
line = line + in.readLine();
fields = line.split("\t");
}

String name = fields[0];
String playSeconds = fields[7];
String location = fields[24];

System.out.println("#EXTINF:" + playSeconds + "," + name);
System.out.println(location);
}

System.out.println();

in.close();

}

ARCHIVES
May 2005 / June 2005 / August 2005 / January 2006 / March 2006 /


Powered by Blogger