Programming

Seam Carving - OMGWTF want want want

The winner of the coolest thing I’ve seen today is the Seam carving demo video - content-aware image resizing.  OK, it’s not exactly aware, but it has a novel way of detecting “less important” areas of the image for stretching and shrinking a picture without distorting the crap out of it.  That was pretty cool, but when it got to the point where they started taking people out of the picture like they never existed, I got a little scared.

Programming

Comments (0)

Permalink

Getting Real sports a few new versions

37 Signals has re-released their Getting Real book in a few new formats: it was originally a $19 PDF, and now there’s a $29 book (via Lulu) and a free HTML version. Now I might finally get around to deciding how much of this “less” business is hype and how much is valid. I’m suspecting 25:75.

Coincidentally, I’ve got to start commuting today after a year and a half of maintaining a home office. Hello, Palm + Plucker!

Programming

Comments (0)

Permalink

For future reference… PDF reference cards!

Don’t you hate it when you find a great online resource, then time passes and you can’t find it again, and then you do finally find it, and so you slam it into a blog entry, which causes the sentence to magically morph into “don’t you love it”?

In this case, handy-dandy PDF versions of foldable reference cards, including the one for CVS that I thought I’d lost forever.

Now if only someone would make a reference card explaining double sided printing…

Technorati Tags: , ,

Programming

Comments (0)

Permalink

MSDN: Esposito on enums

Dino Esposito did a writeup over at MSDN on enumeration types. I was about to dismiss it, but then I realized that I don’t really use them in my code, so I should probably review them. Sure enough, I leaned a few things, particularly around using them as bitfields via the Flags attribute:

1 [Flags]

2 enum Foods : int

3 {

4 apples = 1,

5 pears = 2,

6 oranges = 4,

7 bananas = 8,

8 beans = 16

9 }

10

11 static void Main(string[] args)

12 {

13 Foods foods = Foods.apples | Foods.bananas;

14 Console.WriteLine(Enum.Format(typeof(Foods), foods, “g”));

15 Console.ReadLine();

16 }

That outputs “apples, bananas” which is a handy way out of writing an output loop with comma separators, but is kind of useless. Where it gets handy is the Parse operator, which can take “apples, bananas” from a string, say, for instance, a config string, and make it into a variable. Nice.

1 static void Main(string[] args)

2 {

3 Foods myFoods = (Foods)Enum.Parse(typeof(Foods), “pears, beans, oranges”);

4 Console.WriteLine(Enum.Format(typeof(Foods), myFoods, “g”));

5 Console.ReadLine();

6 }

Technorati Tags: , ,

MSDN
Programming

Comments (0)

Permalink

Fun with dead languages

I missed DemoCamp7 last night, which had me kind of bummed (true geek story: I was working all day on a laptop that was set to the wrong time zone, then wondered why I was feeling so hungry at only 5:30, when it was really 7:30…), mostly because Damian Conway was going to be presenting some Perl stuff, and then I saw this post on The Farm, which at first I thought was just a report on last night’s fun, but sweet mother of, well, whatever, Damian was giving a talk tonight!

After seeing Fun With Dead Languages, big one sentence paragraphs are all I’m capable of.   It’s been a long time since I’ve been so entertained while someone demonstrates how very smart he is.  OK, that was a 2 sentence paragraph.  Now 3.  Now 4.  Urg, need recursion.

Technorati Tags:

General
Perl
Programming

Comments (0)

Permalink

Jason’s new law of string manipulation coding

Never do in 65 lines of messy string manipulation loops what you can accomplish in 3 lines of RegEx code.

Backreferences rock.

For the curious, I was trying to “englishify” hours of business information, so a set of 14 open/close strings would be translated into stuff like “Mon. - Fri.: 9 - 5″ or “Mon., Wed.: 9 - 5, Fri.: 8 - 4″ or “Mon - Wed., Fri.: 9 - 5, Sat - Sun.: 12 - 6″ or whatever, and the only think that rocks harder than backreferences in a task like this is TestDriven.NET. I was able to write the messiest code ever while testing it out, get it working, and then make it pretty and maintainable. It’s nice to be able to skip step and go straight to the pretty code, but sometimes, particularly with algorithms, it helps to push the bits around the screen for a while.

Technorati Tags: , ,

.Net
Programming

Comments (0)

Permalink

Thrust Labs rule #1: use meaningful variable names

I should have committed this lesson to memory years ago after some kind of time wasting mix-up between a test script called “test” and the UNIX test command (which, in hindsight, may have been more of a path issue, but the other lesson was to not work on assignments at 4 am the night before they’re due), but here we go again:

Never ever ever use throwaway variable names.

Case in point: inspired by my earlier thoughts on desktop application development, I decided to try Cocoa programming. I’m just at the poking-around stage right now (I miss MSDN’s level of documentation already, even when it’s wrong), but I lost an hour or two on this gem:

- (void) loadPicture:(NSString *) filename
{

img = [[NSImage alloc] initWithContentsOfFile: filename];
if(img)
{
[pic setImageScaling: NSScaleProportionally];
[pic setImage: img];
[pic setNeedsDisplay:YES];

}
else
{

NSLog(@”img failed”);

}

}

“pic” was an NSImageView control, and there weren’t any errors, but the damned thing wouldn’t ever change its picture. Further debugging showed that messages weren’t going to it at all:

if([pic isEditable]) NSLog(@”YES”);
[pic setEditable: NO];
if([pic isEditable]) NSLog(@”YES”);

That yielded two consecutive YES entries in the log.

In the end, renaming “pic” to something more meaningful solved the problem. I’ve yet to find a Cocoa or Objective-C reserved words list, but I suspect pic is on it. Of course, meaningful names will avoid a good chunk of the need for such a list anyway.

Technorati Tags:

Cocoa
Programming

Comments (2)

Permalink