Wednesday, June 1, 2011

Lightbox Issues

I decided to use Lightbox to display a simple list of images in a slightly more elegant way than just a boring ol' href.

However, I couldn't get it to work! It kept trying to push the images down to below the bottom of the main content and then wouldn't "un-grey" it properly so it could be used. Basically, the lightbox effect was broken.

After a long time of debugging (wherein I was a bit distracted because of a missing image file), I finally figured out the problem. I'm using .htaccess to change the css handler from the normal page to the PHP engine. All I had to do to fix the problem was add the following line to the top of the lightbox.css file:

<?php header("Content-type: text/css; charset: UTF-8") ?>
Boom. Done. Works like a charm now.

(p.s. Here's the Lightbox website: http://www.lokeshdhakar.com/projects/lightbox2/. Yes, it does work as easily as they suggest; you just have to not screw around behind the scenes).

Monday, May 16, 2011

Content-type in PHP headers

I'm working on a BREW program. I need to serve the content from an Apache server running PHP. I know this should work, but the application kept acting as if there was no xml content at all.

I played around with a variety of possible ideas on what the problem could be, but ended up narrowing it down to the fact that Apache/PHP returns Transfer-encoding: chunking. It took me a long time, but I managed to get rid of that by replacing it with Content-length.

The trick was getting the sucker to work. I had my php code totally in the wrong order for a long time; I was deceived by Firefox, which (via WebShark) was telling me there was data and it had length. Web-sniffer.net and other header reader sites kept returning 404 or zero content length header messages... as did the IWeb status.

Turns out, I was using the output buffer incorrectly.

My final code needed to be://setup here
//setup of data here
ob_start();
//header stuff here
echo $strOfStuff
header("Content-length: " . ob_get_length());
And that did the trick. I'd try to explain more, but it took me a long while to get to this point, and I'm still not sure if there is something within IWeb that I could have manipulated to make my life easier. I don't want to speculate at this time.

Sunday, April 17, 2011

g++ command line options

  • -o : name the output file.
  • -Wall : all warnings.
  • -pedantic : follow strict ISO C++ rules.
  • -Weffc++ : follow Scott Myer's Effective C++ solutions.
More to come as a I experiment with them.

'NULL' was not declared in scope

(and cout, for that matter).

  • For NULL: use #include or
  • For cout: use the scope operator: std::cout or put 'using std::cout' at the top of the file.

Local SVN create and import troubles

I have this problem every time I try to create a new repository to use for version control.

First:

svnadmin has this thing about the 'create' feature using a path, not a URL, so the command (on Mac OS X) should be:

$ svnadmin create /Users/adam/vc/code

where /Users/adam/vc was already created via the

$ mkdir /Users/adam/vc

command.

Second:

Say you want to import a folder to your newly created repository. Per the help, it should be as simple as:

$ svn import file:///Users/adam/vc/code

where it assumes that the base folder is '.'. You can use -m to create the initial import message, but I have it bring up Vim as my editor.

Yay, it works, though I did have to fuddle with the invalid URL message a few times.

Great, let me check out my nice shiny new code so it's actually under version control:

$ svn co file://Users/adam/vc/code

Damn! What the hell is: "svn: Unable to open an ra_local session to URL" and "svn: Local URL 'file://Users/adam/vc/code' contains unsupported hostname"?

or for that matter this list of other errors as I play with the command?

svn: Local URL 'file://Users/adam/vc/code' contains unsupported hostname
svn: ':/Users/adam/vc/code' does not appear to be a URL
svn: Client error in parsing arguments

To say the least, it's been a big hassle. Here is what worked.

  1. Delete the folder that you may have already created in the repository folder (in my case 'code')
  2. Create the repository using this command: svnadmin create /Users/adam/vc/code (note: no 'file://' protocol).
  3. Create a folder that has the code you want to put under version control. Make sure the files you want in it are backed up, because you're going to delete it later. I named mine 'code' in this example.
  4. Import the folder (you need to be outside of the folder when you run this): svn import code file:///Users/adam/vc/code
  5. Remove the folder: rm -r code
  6. Checkout the folder from the repository: svn co file:///Users/adam/vc/code
There, that should it. All your files should scroll past you as it creates a new folder (in my case 'code') that is now under version control.

Why is this so painful? Granted, I didn't pay attention closely this time, but I had just done this on a Windows machine (under Cygwin) with no problems at all, so I assumed it'd be the same (of course, forgetting past experiences).