Saturday, December 18, 2010

How to fix Wii Virtual Console "black screen" issue

For:
- Wii (system Version 4.3U)
- component cables for A/V

Problem:
When trying to play downloaded SNES or NES games, the screen goes black and you may eventually be sent back to the home screen. When hitting the "home" button on your controller, you can see the game in the background behind the menu options.

Solution:
Make sure your Wii's screen resolution is set to 480p, not 480i.
- Wii Settings > Screen > TV Resolution > EDTV or HDTV (480p)

Friday, December 3, 2010

Two new haikus

ミシガンに
寒くなってる
初雪だ

大学は
期末試験が
迫り来る


Readings:
mishigan ni
samukunatteru
hatsuyuki da

daigaku wa
kimatsushiken ga
semarikuru


English translations:
In Michigan
It's getting cold
The first snow

College
Has final exams
Looming

Wednesday, July 21, 2010

SQL Server strange string lengths


I just thought I would document some very unintuitive behavior of SQL Server to watch out for. It's well known that SQL Server is not well-suited to string processing. This is one of the reasons why.

The LEN built-in function returns the length of a given string, however, it has quirks about the way it handles whitespace:


Command Result
SELECT LEN('abc') 3
SELECT LEN('') 0
SELECT LEN(NULL) NULL
SELECT LEN(' ') --one space 0
SELECT LEN('       ') --multiple spaces 0
SELECT LEN(' ') --one tab 1
SELECT LEN('
') --one newline
2
SELECT LEN('ABC ')3
SELECT LEN(' ABC')4


I tested these behaviors in SQL Server 2005.

I think the reason for this is because old string types like char are fixed-width, using spaces to fill in unused portions of the string. For example, if I wanted to store 'Hello world' into a char(20), SQL Server would actually store 'Hello world         '. Then, when you want the length of the string, you just want the length of the part before all the trailing spaces. However, I'm not sure why this is still the dominant behavior, since nvarchar and varchar are much more commonly used these days than char, and they don't use all the trailing spaces.

As the the newline, it uses two characters: carriage return (13) and newline (10).

Wednesday, July 14, 2010

Japanese Internet slang: w's

Japanese use their own kinds of Internet and texting slang, so today I'm highlighting one that puzzled me for a while. The w's.

You'll see it at usually the end of sentences and often several in a row: wwww.

"w" is actually short for the Japanese word 笑う "warau", which means to laugh. Sometimes you'll also see just the 笑 character by itself or ~笑 or ~笑う or something like that. It's kind of the equivalent of "lol" in English. The more w's, the more they're laughing, just like some crazy kids type "lololololol" in English :) .

Have a great day! ww

Tuesday, June 1, 2010

JavaScript: functions as objects vs. functions as functions


I ran into this interesting behavior today. I was passing a function to a list of functions to execute later, and I kept getting an error in firebug that said when it came to execute it that it "is not a function", but proceeded to completely successfully execute it as one anyway, doing exactly what I wanted it to. I wanted to get rid of the error message, since it was behaving properly.


Come to find out, it was listed as an object instead of a function. In short, the difference is that if you declare a function like this: function() { ... }, it will be returned as a function. If you declare it like this: new function() { ... }, it will be returned as an object. I just needed to take out the word "new" I had used.


I created the following simple HTML page to demonstrate this behavior. Feel free to try it out for yourself and tinker around with it:

<html>
<head>
<script type="text/javascript">
//setup
var tests = new Array();
tests[0] = new function() { return 'A is the best!'; };
tests[1] = function() { return 'B is better!'; };

var message = 'tests:';
for (var i = 0; i < tests.length; i++)
{
message += '\ntest[' + i + ']: ' + tests[i];
}
alert(message +'\n\nNext, we\'ll try to execute these as functions...');
</script>
</head>
<body>
<div id="divResults"></div>
<br />
<div id="divStatus">Testing...</div>
</body>
<script type="text/javascript">
//run the tests
var resultsDiv = document.getElementById('divResults');
for (var i = 0; i < tests.length; i++)
{
resultsDiv.innerHTML += 'test[' + i + ']\'s result: ';
try { resultsDiv.innerHTML += tests[i](); }
catch(ex) {resultsDiv.innerHTML += '<span style="color:red;">Test failed: ' + ex.message + '</span>'; }
resultsDiv.innerHTML += '<br />';
}

//we're done
document.getElementById('divStatus').innerHTML = 'The test is done. Reload this page to run the test again.';
</script>
</html>


I have confirmed this behavior in Firefox 3.6.3, IE 7.0, Chrome 5.0, Safari 4.0.5, and Opera 10.53.

Monday, February 8, 2010

Resolved: "uninitialized constant DBI::DBD::ODBC" in Ruby for Windows

Running:
  • Windows 2003 Server SP2
  • Ruby 1.8.6 patchlevel 383, i386-mingw32 (from RubyInstaller)
  • dbd-odbc 0.2.4
  • dbi 0.4.3
Problem:
I created a Ruby class that can run arbitrary SQL queries on remote databases of various kinds. It was working fine for a while, but then something changed so that whenever I would try to use it to execute some SQL, I'd get the following error:

DBI::InterfaceError (Unable to load driver 'ODBC' (underlying error: uninitialized constant DBI::DBD::ODBC)):
dbi (0.4.3) lib/dbi.rb:300:in `load_driver'
C:/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
dbi (0.4.3) lib/dbi.rb:242:in `load_driver'
dbi (0.4.3) lib/dbi.rb:160:in `_get_full_driver'
dbi (0.4.3) lib/dbi.rb:145:in `connect'
...

Resolution:
Make sure you have the dbd-odbc and dbi gems installed correctly.
For me, a couple of associated files were missing from C:\Ruby\lib\ruby\1.8\i386-mingw32: odbc.so and odbc_utr8.so. I had these files in my working Dev installation, so I just copied them from Dev to Prod, and it fixed the problem.

Commentary:
This comes from DBI trying to do a require dbd/odbc and not finding that file. When I googled around about the error, mostly people said to make sure you had the dbd-odbc gem installed, which I already did. I tried reinstalling the gem, as well as the dbi gem. This had no effect. The problem was happening on Prod, but I had the same thing set up on Dev, which was working. So, I checked to see what paths require uses like so:

C:\...>irb
irb(main):001:0> $LOAD_PATH
=> ["C:/Ruby/lib/ruby/site_ruby/1.8", "C:/Ruby/lib/ruby/site_ruby/1.8/i386-msvcr
t", "C:/Ruby/lib/ruby/site_ruby", "C:/Ruby/lib/ruby/1.8", "C:/Ruby/lib/ruby/1.8/
i386-mingw32", "."]

I checked through those directories to see what .rb files looked like ODBC-related things that were in Dev but not in Prod. That's how I found those two files. After I copied them to Prod, I tested it in IRB like so:

irb(main):004:0> require 'odbc'
=> true

After that, everything worked fine again. I hope this anecdote can help you! Good luck!

Friday, January 22, 2010

Thursday, January 14, 2010

How to restore an Oracle database from its original files

Background:
I recently had to bring an Oracle database online from its original files an old laptop hard drive. It had some data on it that I needed to get off, and as usual, Oracle is anything but straightforward. This post describes how I ended up doing it.
To start with, I had to connect the old hard drive to the machine. I did this with a USB-SATA2.5" external adapter. You can find hard drive multi-adapters like these on newegg or any other online hardware store for around $20 - $30.

Running:
- Windows XP SP3
- Oracle 10g

Solution Steps:
1) Locate your current Oracle database files. The default location for this is C:\oracle\product\10.2.0\oradata. Each folder in that directory contains the data files for the database by the same name.

2) I'll call the database you're trying to restore "OldDatabase". If the path for OldDatabase folder was different from your current Oracle data folders, this might not work (but of course the drive letter will be different if you're using an old disk drive via USB). If it doesn't work, see if you can install Oracle into a directory on the new machine that has the same path as the old one had.

3) Make sure you don't have any databases in your current Oracle installation that have the same name as OldDatabase. If they match and you continue anyways, things will get very screwed up. If you do have a match, see if you can migrate the matching new one to another new database with a different name. You might want to back up that db's files first.

4) Now, go ahead and create a new database with all the default settings and the same name as OldDatabase. You can do this via the Database Configuration Assistant that should have been included with your Oracle installation. I found mine under Start > All Programs > Oracle - OraDb10g_home1 > Configuration and Migration Tools.

5) Go into your Administration Assistant for Windows (in the same start menu folder as the Database Config Assist.) and find your newly created database, right click it, and choose Stop Service.

6) The data files for the new database you just created are now in your current oradata folder. Copy the contents of your old OldDatabase folder into the new one by the same name, replacing all files (you might want to back up your new folder first).

7) Back in the Admin. Assist., right-click your new database and choose Start Service. With any luck, you'll be able to connect to it in a few moments, and it will look just like your old database!

Hope this helps!