Friday, March 28, 2008

Programming Challenge

About.com has a Programming challenge to hide a message inside a text file.

So decided it would be fun to try....

Here's my overview from the code:


OVERVIEW:
Spaces are used as carriers to "hide" a message in a file.
Only spaces following a period are candidates for carriers.

As the file is parsed periods followed by spaces are
adjusted to the following:
.[space] = 0 bit
.[space][space] is a non carrier
.[space][space][space] = 1 bit

The message is then written as bits into the carriers distributed
sequentially in the text file.

Thus the message can be hidden at nearly any point in the text file,
and a '.'s can be skipped randomly to reduce detection.

Open Source contributor

Finally after several revisions with my MySQL mentor, my code is going into version 6.0. Kinda cool.

All the other code I've written has disappeared behind corporate doors. I think I like this better.

Colors

It's no secret I'm not the best at colors. No I'm not completely color blind but looking at my Mac it sure FEELS that way.

How do I change the colors? Silver and pale blue who thought of that? Why not brown and green? Or better yet pink on purple! Great color scheme Apple.

Ok, rant's over. Back to your irregularly scheduled blog.

Saturday, March 22, 2008

New Mac

So I'm the proud owner of a Mac Mini. Ten minutes after getting it up and running and I find myself asking "Now what?"

Wednesday, March 19, 2008

Sunday, March 16, 2008

Working at home


Seven monitors, a big desk, and a comfy chair.

That's why I love working at home.

Wednesday, March 12, 2008

VS 2008

What's the deal with VS 2008? I'm working along compiling the latest and greatest code at work and suddenly the message pops up that the linker has crashed. I can't remember the linker ever crashing, heck I've been using Visual Studio since the first version (1.4 I think it's been a while) in Dos/Windows 3.1.

Hit build and the second time works. This worries me nothing has changed, identical source, objs, libs, etc., why would the linker work this time? Well MS what's going on?

I submitted my first patch to MySQL

Here it is:

Hi All,

This is my first attempt to contribute.

(patch details included below)

SUMMARY:

This patch adds the code for the Windows exe to lookup the network MAC for use by the UUID() function. It uses the same API as the windows command ipconfig.exe. (IPHLPAPI) It searches for network cards in the same order as ipconfig, which is handy for testing/verification on systems with multiple network cards.

It looks like there is not an automated test for the UUID function, as least not yet :).

To test the function manually on windows:

On a console window on the server under test run:

> ipconfig /all

Note the "Physical Address" of the first Ethernet adapter.

>From MySQL client run:

> SELECT UUID();

Compare the last 6 hex bytes of the uuid to the results from ipconfig above.
If they are the same the function passes.

Testing Caveat: Will fail under Win95,98 and WinNT 4 < sp4 the MAC will not be read, UUID generates random # instead.

This was fun...your comments, questions and input are appreciated.

Regards,
-Chris


-------------------------------------------------


--- /home/chris/my_gethwaddr.c 2008-03-10 18:55:00.000000000 -0600
+++ my_gethwaddr.c 2008-03-07 06:46:29.000000000 -0700
@@ -102,115 +102,11 @@
}

#else /* FreeBSD elif linux */
-
-#ifdef __WIN__
-
-/*
- There are header conflicts with ras.h and mprapi.h. The following
- definitions keep those from being included and defines the one constant that
- is still required.
-*/
-#define _RAS_H_
-#define __ROUTING_MPRADMIN_H__
-#define MAX_INTERFACE_NAME_LEN 256
-
-#include
-
-/*
- The following typedef is needed since we are dynamically loading
- iphlpapi.dll. Dynamic linking is used because static linking would cause
- problems with older versions of windows (WIN95, WIN98 and WINNT4 < SP4).
-*/
-
-typedef DWORD (WINAPI *pfnGetIfTable)(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder);
-
-/*
- my_gethwaddr - Windows version
-
- @brief Retrieve MAC address from network hardware
-
- @param[out] to MAC address exactly six bytes
-
- @return Operation status
- @retval 0 OK
- @retval <>0 FAILED
-
- @todo
- Resolve the header conflicts (affects more than just this file) -*/ -my_bool my_gethwaddr(uchar *to)
-{
- HINSTANCE hIphlpapi;
- pfnGetIfTable fnGetIfTable;
- PMIB_IFTABLE pIfTable;
- MIB_IFTABLE ifTable;
- PMIB_IFROW pIfRow;
- DWORD dwSize;
- DWORD dwRetVal;
- my_bool rval;
- int i;
-
- rval= 1;
-
- hIphlpapi= LoadLibrary("iphlpapi.dll");
-/* Iphlpapi is not available on WIN31, WIN95, or WINNT4 < sp4. */
- if (!hIphlpapi)
- goto error1;
-
- fnGetIfTable= (pfnGetIfTable) GetProcAddress(hIphlpapi,"GetIfTable");
- if (!fnGetIfTable)
- goto error1;
-
-/* Ask GetIfTable if one is enough. */
- dwSize= sizeof (MIB_IFTABLE);
- if (fnGetIfTable(&ifTable,&dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER)
- {
- pIfTable= (PMIB_IFTABLE) my_malloc(dwSize,0);
- if (!pIfTable)
- goto error2;
- }
- else
-/* One is enough we don't need to alloc. */
- pIfTable= &ifTable;
-
-/* Get the hardware info. */
- if ((dwRetVal= fnGetIfTable(pIfTable,&dwSize,FALSE)) == NO_ERROR)
- {
- for (i= 0; i < (int) pIfTable->dwNumEntries; i++)
- {
- pIfRow= (MIB_IFROW *) & pIfTable->table[i];
- if (pIfRow->dwType == IF_TYPE_ETHERNET_CSMACD)
- {
-/* Stop on the first network card detected. */
- memcpy(to,pIfRow->bPhysAddr,6);
- rval= 0; /* success */
- break;
- }
- }
- }
-
-/* Clean up memory allocation. */
- if (pIfTable != &ifTable)
- my_free(pIfTable,0);
-
-error2:
-/* Perform library clean up. */
- FreeLibrary(hIphlpapi);
-
-error1:
- return rval;
-}
-
-#elif
-
/* just fail */
my_bool my_gethwaddr(uchar *to __attribute__((unused))) {
return 1;
}
-
-#endif
-
#endif

#else /* MAIN */

Sunday, March 9, 2008

It works - first MySQL bug fixed.

I've always found the best way to learn a new program is to just dig in and fix a few bugs.

My first bug is fixed, the server needs some code to find the MAC address for the network card in Windows. Now I'm reviewing my code to see if I've followed their coding style, etc.

It was supposed to be an easy bug from the report. The bug wasn't quite as simple as implied. First there are three methods in the public domain and on the internet that are really just hacks and were bad choices. I finally picked apart ipconfig and found the API it uses to list all network hardware.

Next problem, if I just linked in the function used to find the MAC address it would cause MySQL to crash when running on the oldest versions of Windows.

So I dynamically loaded the iphlpapi.dll. A benefit to dynamic loading is that it won't add to the exe loading time.

Now to submit the fix.....

Technorati Post

Technorati Profile

Saturday, March 8, 2008

MySQL command line magic

When debugging MySQL (VS 2005) a few helpful command line arguments:
--console ## display server output on a console window (console is nice, debugging services can be painful)
--basdir="C:\MySQL" ## path to root of the DB

I also needed: --skip-grant-tables

Since I forgot the root password to the DB I copied to my dev. box I had to set a new one.
After starting MySQLd.exe with the --skip-grant-tables I took the following steps:

> mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 6.0.5-alpha-pro-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> UPDATE mysql.user SET Password=PASSWORD('xxxxx')
-> WHERE User='root';
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> quit
Bye


Restart without the --skip-grant-tables option and we are back in business.

It's so cool when things work!

Friday, March 7, 2008

Learning the internals of MySQL

I've been playing with MySQL recently, most of my data base work has been with MS SQLServer. But I need a less expensive solution for one of my pet projects, MySQL fits perfectly.

I want to really understand the internals, so I'm actually buiding the source code. So far there have been a few hurdles to jump. But ultimately my goal is to compile and debug completely on windows.

#1 for non Linux developers (that don't work at MySQL), you have to use Bitkeeper's free Linux client to download the code.


I'm primarily a Windows developer so I wanted to avoid putting cgywin on my main dev box. No problem right? Just use linux in a virtual machine, I have VMware pro. that should work. I tried several vmware linux appliances, every one I tried wouldn't boot up or had some other catasrophic problem.

Finally I installed a fresh copy of Ubuntu in a virtual machine, it works perfectly. In fact I'm close to taking Vista (I HATE VISTA!) off my laptop and going to Ubuntu.

So I got the latest version of the code downloaded. I was able to compile and test it from inside of the VM. One step closer to my goal. Next I copied the source to my Windows dev box.

#2 Build the .sln project file so Visual Studio can build the project. I install CMake, and Bison no problem. So I run win\config

C:\Work\MySQL\mysql60\sql>win\configure WITH_INNOBASE_STORAGE_ENGINE WITH_PARTITION_STORAGE_ENGINE MYSQL_SERVER_SUFFIX=-pro
then I run: win\build-vs8.bat and an error occurs in Configure.data
a bug has already been entered for this, but it appears that the fix has yet to be added to the source tree. Edit the file and continue on. Now we have a .sln file.

#3 Even though the docs say they are building a VS 2008 .sln file VS wants to convert it from 2005. This happens with minor issues.

#4 Ok, now we're compiling..... Oh crap there's a compile "error '_vsnprintf': attributes inconsistent with previous declaration" several of them. Looks like Microsoft decided to define _vsnprintf in the newest version of stdio.h. For now I just revert to VS 2005 and everything compiles fine.

--More to come--

Thursday, March 6, 2008

Moving into the 21st century

I work for a small engineering company. This company has been using antiquated technology for some time.

My job, in part, is to modernize everything. Moving these guys to new technologies is kind of like watching snails cross a sidewalk.

The old system (still in use) runs on a 6502 microprocessor, the same one that made the Apple II and Commodore 64 work.

Choosing new technologies is also a challenge, I have to find solutions that they will be comfortable with. No one in the company except me has a clue about Linux. So I rejected embedded linux on a Spartan FPGA embedded processor early on even though it was a perfect fit. They all have Windows PCs on their desks the natural choice was embedded XP running on a small via powered motherboard.

chris' shared items

Twitter Updates

Official blog of Chris Lee Runyan

Fastest C++ in the west.