Posts Tagged ‘programming’

DropDownList Drops The GridView Ball

Thursday, March 5th, 2009

When .NET 2.0 makes things easy, it makes them brain-dead easy. But when it makes things hard, you wish you were working as a greeter at Wal-Mart. Take GridView editing. If you accept Microsoft’s TextBox method of editing GridView cells, you’re golden. Sometimes you need DropDownLists in place of TextBoxes, and that takes a teensy bit more work:

[code lang="csharp"]


<%# Eval("Role") %>






[/code]

There’s a microscopic UI flaw in this approach: when the user clicks ‘Edit,’ the selected DropDownList item is the first (index 0), not the item that matches the cell’s text. Uniting the two is surprisingly harsh, since the text disappears before the DDL appears. After many unfruitful searches for an answer, one long blog post has a solution. A very dirty but awesomely easy solution. Use the DDL’s ValidationGroup field as short-term memory!

The CakePHP Is A Lie

Tuesday, July 1st, 2008

CakePHP is out of my life. For good.

After six weeks of microconfiguring .htaccess files and begging IRC’s #cakephp for help on inexplicably broken code, I had produced nothing of value. I am a patient man, but I expect some fruition from my studies. I am clearly not alone: my post about .htaccess files rocketed to the #2 spot on Google’s search for ‘htaccess cakephp’.

On Saturday morning I burned it all down, cleaned up the ashes, and started fresh with CodeIgniter, which has many similar qualities to CakePHP. Good news: it has a tiny footprint (one app is < 50kB) and no .htaccess files. Bad news: no AJAX helpers ((They’re working on it. In the meantime, do what I did and pick up jQuery.)), no templates, and CodeIgniter’s name makes inventing blog title gags nigh impossible. I’ll live.

To compare timeframes: In six weeks of study, I produced 10 lines of unjustifiably non-functioning code. In an hour and a half, I had CodeIgnite working with Eclipse (the small footprint helps) and had produced the test app CakePHP couldn’t handle. That’s 0.15% of the time.

OS X's Nervous Tics

Friday, June 20th, 2008

There are no shortage of metronome apps available for the Mac. One app, Dr. Betotte, is so hardcore I wouldn’t know the difference between it and a dialysis machine.

Each and every single Mac metronome is missing an excellent opportunity through the Apple Remote. A musician’s instrument of choice and his Macintosh may be several metres apart, so implementing Apple Remote functionality would avoid constant running back and forth to

  • start/stop
  • change tempo
  • change volume

I bring this up so any prospective developers looking to shove another clone into an oversaturated market (or, more likely, already-existing narcissistic clone developers googling their product) get the clue. Arguably I could write such a Cocoa app myself, but I never finished Metal Gear Solid 2, and I need to get on that first. Uh, yeah.

In fact, it’s not even as hard as Cocoa. Sofa Control is one of the few shareware apps I’ve ever registered, and it makes the process as easy as editing a flat file.

CakePHP and .htaccess, Enemies Forever

Saturday, June 7th, 2008

I reiterate last week’s post about CakePHP: the documentation sucks. They do not put nearly enough emphasis on troubleshooting, because for most adopters of the framework, setting up your first working app is rarely a straight shot.

Case in point. It took a week of research to pick up an important point: if any one of four .htaccess files are missing, bits of your CakePHP app will not work. Not might…will. For me, the symptom was broken CSS: the HREF in

pointed to nowhere, and nothing existed to forward it to a valid location.

Unfortunately .htaccess files tend to disappear easily, especially when manipulating directories. Filenames beginning with ‘.’ do not show up, so simple drag-and-drop operations from an operating system’s GUI leaves out .htaccess because you can’t see it.

Good news is in store, though. Working through this tutorial set me straight, and I have a flawless application once again.

Eclipse and CakePHP, BFF

Friday, May 30th, 2008

As popular and awesome as CakePHP is, there just isn’t enough documentation on it. I guarantee many hours or days learning to wrangle with it.

Using Eclipse to maintain CakePHP projects is even worse. Precisely one tutorial exists, and it just doesn’t, um, cut the cake. It left me more confused than before I started.

After spending an hour on IRC’s #cakephp, one very patient user guided me through the process. By the end of the session, all I really needed was a visualisation of the setup. He took a desktop snap and sent it to me. Bam! Eclipse and CakePHP were together in five minutes.

In the interest of aiding visual learners out there and filling in the gaps left by the CakePHP/Eclipse tutorial, I pass this image on to you.

Eclipse setup for CakePHP work

As the tutorial mentions, you will be creating two separate Eclipse projects: one for Cake core, and another for your project. Select everything inside /cake/cake and copy it into the core project; using /cake/cake as an include path works too. ((My biggest criticism yet of CakePHP: the developers didn’t spend any time thinking of the repercussions from naming a directory and its child the same thing.))

In your other project, use the core as an included project (right-click or whatever on Include Paths > Configure Include Path). Finally, select everything inside /cake/app and copy it into your project (again, including /cake/app is also valid).

That should work. If it doesn’t, feel free to comment below, though I’m likely to be of insufficient help. Otherwise, hum to yourself as you happily code away:

This was a triumph
I’m making a note here: ‘HUGE SUCCESS’…

Responses to comments after the jump…
(more…)

Butt Loop

Tuesday, May 13th, 2008

Artist unknown. I’ve always questioned the wisdom of certain programming keywords (for? try? catch? bunt?), so a puerile programming language makes just as much sense…maybe more.

Butt Loop


UPDATE: Much changes in a year. About February 2009 I added the webcomic Saturday Morning Breakfast Cereal to my daily RSS rounds. Revisiting this post today (almost May 2009), I immediately recognise the art as being from said comic. Another loose end tied up.

Will Code For Bacon

Saturday, April 26th, 2008

I encountered a man wearing this T-shirt at Eeyore’s Birthday Party today, of all places. It explains my position in life so well. I want one.

Will Code For Bacon

END;

Thursday, October 11th, 2007

I have particular trouble getting SQL triggers and procedures to work. They’re just syntactically grumpy. Tonight, for example, I spent an hour, perhaps two, debugging a syntax error in a four-line trigger. Given the examples supplied in the above links, how can I go wrong?

[code lang="SQL"]CREATE TRIGGER myTrigger AFTER INSERT ON table1
	FOR EACH ROW BEGIN
		INSERT INTO table2
		(
			foreignid,
			timestamp,
			zerogoeshere
		)
		VALUES
		(
			NEW.id,
			NOW(),
			0
                );
	END;[/code]

Only after brute experimentation did I discover the problem. If your trigger has only one statement (e.g., INCLUDE), not only are BEGIN-END; superfluous, they won’t work. Keep the statement by itself:

[code lang="sql"]CREATE TRIGGER myTrigger AFTER INSERT ON table1
	FOR EACH ROW
		INSERT INTO table2
		(
			foreignid,
			timestamp,
			zerogoeshere
		)
		VALUES
		(
			NEW.id,
			NOW(),
			0
                );[/code]

That’s utterly ridiculous. What if C++ returned a syntax error for typing

[code lang="cpp"]if (lameBoolFlag)
{
     cout >> "Your flag is true, shit-for-brains!" >> endl;
}[/code]

I hope this will help someone, somewhere. Lord knows Google searches save my ass every day whilst coding.