Sunday, June 22, 2008

Welcome to the family



I have joined the club, went to the store and bought the iMac 24" 3.06 GHz =o), the screen is awesome, makes my "old" 21" monitor look tiny

So far I have been quite a bit disappointed by the "usability" of the Mac, I guess I had really hight expectations for it, just the fact that the first application you have up there is the "finder", tells me something is not quite there, my biggest problems so far:

- short cut keys are different
- you install some application, then is just gone, you have to find it using the finder
- right click, where the #$%&** is my right click!!! - got it, you have to "ctrl+click"
- mouse buttons (or lack of)
- window resizing, why can I only resize from the bottom right corner??
- lack of "window restore", after maximizing the window

Right now I'm downloading Vista to install it on Fusion, we'll see how everything goes after I get familiar with it

the "welcome to the family" is what they told us at the store when we bought it, will keep you updated about my rants experiences

Wednesday, May 14, 2008

Twitter is down, I blame http://www.tweetwheel.com

Twitter is down again, at this pace is going to be pretty hard for another popular social network to take twitter off the #1 position as the worst social network (uptime); you can check it out here

Social network downtime Jan-Apr 2008

I blame it on tweetwheel.com, who do you blame it on?

Tuesday, March 25, 2008

No anchor member was specified for recursive query *

I got this error while working on a recursive CTE query, I entered the error message in google/live and got zero results so I had to do some more study on CTEs and I thought I'd share the answer to this problem.

From the MS documentation we read:
The first invocation of the recursive CTE consists of one or more CTE_query_definitions joined by UNION ALL, UNION, EXCEPT, or INTERSECT operators. Because these query definitions form the base result set of the CTE structure, they are referred to as anchor members.
CTE_query_definitions are considered anchor members unless they reference the CTE itself. All anchor-member query definitions must be positioned before the first recursive member definition, and a UNION ALL operator must be used to join the last anchor member with the first recursive member.

Basically you cannot make a recursive call before you have defined the initial data set, let's see with an example:

This would be valid:

with example(col1, col2, iteration) as
(
--first, we defined the base set
select col1, col2 from someTable where col1 is null
union all
--then we can make the recursive call
select t1.col1, t1.col2
from example t1 inner join SomeTable t2 on t1.Col2 = t2.Col1
)
select * from example

and this would generate the error

with example(col1, col2, iteration) as
(
select t1.col1, t1.col2
from example t1 inner join SomeOtherTable t2 on t1.Col2 = t2.Col1
--ERROR:we have not defined a base set before making the recursive call
union all
select col1, col2 from someTable where col1 is null
)
select * from example

Hope this helps someone out there

Thursday, March 13, 2008

Do you not want to exit? yes, no, cancel, FileNotFound

This article refers to UI best practices

The title of the post is of course an exaggeration of asking negative questions but serves as a perfect example for what I'm trying to tell you
I thought the title of this post was an exageration, but after seeing that dialog...

Don't ask the user negative questions

More often than not you'll confuse that crap out of the poor user; users are already too scared of answering questions to still bother them with the opposite of what they want, it's a simple and basic rule, but I still see a lot of software (and developers) that use negative questions/options for data input.

The most common use of negative options is probably disabled

just compare:
Label X visible?
Field X Enabled?

To:
Label X Invisible?
Field X Disabled?

That subtle change makes it much harder to answer the question correctly; so prefer Enabled over Disabled, Visible over Invisible, Active over Inactive, etc

The same concept applies when naming variables or methods, in very few cases the negative is a better option, so just go with the safer option, it's easier to process, we are used to answer "positive questions" and the opposite usually causes us to think which makes things not intuitive

Thursday, January 24, 2008

Puzzle

Justin came up with this problem as part of an actual project and it puzzled me the simplicity of the problem and definition of the solution in your head, yet the complexity of the expressiveness in code for the solution, maybe another language would be better suited to solve this problem?

you have an array of the Doc class which has a DocIndex property, for which the property is not set, some elements of the array may be null

//*** small version of the Doc class, just for the puzzle
class Doc {
public int docIndex;
}

Doc[] docs = new Doc[] { new Doc(), new null, null, new Doc() };

then you have an array of ints that represent the indexes that are already taken, e.g.

new int[] { 2, 3, 5, 7, 9 }

your job is to assign the indexes to the Doc[] that are not "taken" (exist in the array)

so, for these examples:



The expected output would be:
existing :
2 3 5 7 9
docs :
0 1 4 6 8

existing :
0 1 2 3 4
docs :
5 6 7 8 9

existing :
5 6 7 8 9
docs :
0 1 2 3 4

what do you think of this problem for a code interview?

Saturday, January 19, 2008

find all tables with column name *

Applies to: SQL
Tested on: SQL 2005
Keywords: SQL, column, all, tables

I'm going to need this quite often...

just execute these queries on the same database where the tables reside

--get all table names for a specific column name
SELECT o.name as TableName
FROM sysobjects o inner join syscolumns c on o.id=c.id
WHERE c.name = 'YOURCOLUMNNAMEHERE'

you can also perform like queries

--get all columns and table names for a 'like column' query
SELECT c.[name] as ColumnName, o.name as TableName FROM sysobjects o inner join syscolumns c on o.id=c.id
WHERE c.name like 'COLUMN%'

Thursday, January 10, 2008

C# vNext wishlist: comma less argument list

Mitch Denny has a post about his feature request for the next version of C#

he wants to have a shortcut to format strings, which would basically allow you to go from this
string s=string.Format(”{0}{1}{2}”, a, b, c);
to this:
string s=@(”{0}{1}{2}”|a|b|c);

I don't think I like the proposed alternative, all you are doing is replacing the "," with the "|" character and making the name shorter.
You could always write your own little wrapper:
//*** you could call it "f" if you wanted
static string fmt(string format, params object[] parameters) {
return string.Format(format, parameters);
}

and get
string s=fmt("{0}{1}{2}",a,b,c);

which is almost the same as the proposed solution

another problem is that this proposal solves a very particular problem which is string formatting and we can get pretty much the same by writing our own little wrapper

but anyway, it gave me an idea for my own feature request
comma-less arguments

string s=fmt("{0}{1}{2}" a b c);

The scope of this change is much wider and actually "desugars" the language

now this change will most likely not happen, since this is a C family language and would take a significant change to the parser but this is my own wish/feature request so there you have it

Monday, November 19, 2007

VS2008 download complete

now burning using the RKTools (poor's man cd/dvd burner tools)

downloading VS2008...

is not listed in the msdn subscriber downloads section yet, we got it through clicking "sign out", then we got to this page, (you you have to use IE) and down at the bottom you'll see a list of top subscriber downloads, you click there on the "Visual Studio 2008 * Edition...", you sign in, and are taken directly to the download

11% so far... have to go get some DVDs =o)

Sunday, October 21, 2007

This application has failed to start because js3250.dll was not found.

This has been a long known issue with Firefox, and so far it doesn't seem like there is an answer, the error messages are:

"This application has failed to start because js3250.dll was not found. Re-installing the application may fix the problem."
"The Procedure entry point in JS_HasInstance could not be located in the dynamic link library js3250.dll"

some suggest uninstalling/reinstalling Firefox, creating a new profile, removing FF completely before reinstalling, downloading a new js3250.dll file, deleting a trojan file ipv6monl.dll, etc; some solutions work for some people, some work for others, here's what worked for me

In my case the problem only happened under a restricted (non-admin) user, I looked in the C:\Program Files\Mozilla Firefox folder and the js3250.dll file was there, so I ran the firefox.exe directly from there and it ran ok, then I replaced the shortcut I had to point to that location and it's working so far

hopefully this will help some other soul

Wednesday, October 17, 2007

My predictions (about Leopard) for next week

- Apple will have their biggest software/hardware (MacPro, MacBookPro & Leopard) sale in history.
- There will be people camping out, waiting to be the first ones to get Leopard.
- They will run out of stock in a few stores.
- Adoption of Macs grows at least 25%.
- Very soon we'll start seeing problems (and updates) in a few applications.
- We'll also see quite a few (a lot?) security problems in the OS and applications for the rest of the year and there after actually

...and I hope to contribute to the cause! =0), and I know quite a few others in the blogosphere will too

Monday, October 15, 2007

small refactoring for working with nullable types

the article applies to: C# 2.0

C# 2.0 brought a new feature: nullable types, you already know they are cool and have been using them for a while, however, how many times have you seen (or written) something like:

//SomeClass.SomeObject.BoolProperty is of type bool?

if (SomeClass.SomeObject.BoolProperty.HasValue && SomeClass.SomeObject.BoolProperty.Value)...
//something

because you can't write:
if (SomeClass.SomeObject.BoolProperty)...

That will not compile

The problem I have with that code is that it is repetitive, and is long, so what can we do?
you can write this instead:

if (SomeClass.SomeObject.BoolProperty??false)

much better, isn't? if BoolProperty has a value and the value is true, it will return true, otherwise it will return false; now, of course you can use the same technique with other types:

string firstName;
public string FirstName { get{ return firstName??""; }}

this code would ensure that FirstName will never be null (I'm pretty sure you've seen lots of "object reference not set blablabla" because of this)

Other examples:
int? result;
...
return result??-1; //if result was not set, return -1
---------------------------------------------------
bool? result;
...
return result??false;
---------------------------------------------------

That's it, hope you find it useful
Remember that the best code, is no code at all

kick it on DotNetKicks.com

Thursday, September 27, 2007

Get last day of month

applies to: C#, .NET
In the spirit of sharing code, and I think this is the second time in this week that I need this function

DateTime GetLastDayOf(DateTime date) {
return new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
}

Thursday, September 06, 2007

google (reader) search, finally

woohoo! you can finally search on your google feeds, plus 2 little features

  • you can see 1000 items (instead of 100)
  • you can hide the sidebar using the mouse
You can search all your feeds, the feeds from a folder or the posts from a single feed. In fact, you can perform two searches: one for a folder or feed and another search for the posts that contain some keywords and are from the folder or feed you've previously selected. The results are sorted by date and it takes a couple of seconds for them to show up.

This might not be available to all users right now, mine got updated on the fly (without the page being down or having to reset/reload at all), I saw the new features announced but mine was still on the old version, then started working on some code and went back to check my feeds and I had the new version

so when are you going to let me highlight stuff?
that would be a killer feature

Friday, August 10, 2007

I don't need any help!

But I do need my F2 key to rename stuff J

I had to use this keyboard because my pc broke, long story short, made me realize how much I use the keyboard

Wednesday, July 25, 2007

is my password too complex?

this post from Scott reminded of a few days ago, when I changed my msn (live?) password and the next day I wasn't able to log back in because the hotmail (msn/live) passwords only allow a length of 16 characters and for some reason I was double typing 2 characters without noticing, after a while I figured it out and realized that I am using the maximum length allowed for passwords, and of course I use upper case, lower case, numbers and symbols... and of course I have categories of sites and the passwords I chose for them, depending on the importance and the security they implement

no wonder a number of people have looked at me like I'm some weirdo when they've seen me typing my passwords... mmm...

am I a freak, or is this normal among geeks? maybe... but there is no security in this world, so all we can do is raise the bar a bit

Tuesday, July 24, 2007

blog.Resume();

wow, it has been over a month since my last post; at work we went live with our first customer and it got intense, we had some critical things that needed to be fixed for the particular environment, and we did it quickly and successfully, I am part of a great team and we're pulling it out together.
UAT anyone?... better not talk about it, it's almost back to normal now, we are finding new features that need to be developed, but things should slow down and this blog will continue it's "regular" operation, at the personal level I've had some rough situations lately as well, but is also pretty much over; I've been so busy that I even missed my 11th birthday at the company I currently work for.

So meanwhile I still need to catch up with my blog reading, you can see some of the stuff I have been reading as I catch up.

I did not get an iPhone, nor am I planning on getting one anytime soon, but I do hope to get a Mac when they release Leopard in October, I do have a feeling that we will start seeing a lot of vulnerabilities in the Mac OS soon though (just remember you read the prediction here J)... just like Firefox is getting hammered right now (you should actually go read this now, it's pretty bad)

'til next time

Friday, June 15, 2007

concatenating strings and nulls in SQL

let's start with a table from scratch

create table test(
firstname varchar(10) null,
lastname varchar(10) null
)

we then insert some data (sorry about people with these names)

insert into test values ('john', 'smith')
insert into test values ('john', 'doe')
insert into test values (null, 'perez')

we're ready to concatenate some strings:

select lastname + ' ' + firstname
from test

but we get:

1 smith john
2 doe john
3 NULL

what happened?

in SQL, when you concatenate strings, if one of the strings is null, the result of the concatenation is null.

At first you might think this is bad, but it can actually help you more than it hurts, you just have to know the trick, so what do we do to fix the query?

select isnull(lastname, '') + ' ' + isnull(firstname, '')
from test

now we get:

1 smith john
2 doe john
3 perez

ok, but how is that helpful?

well, let's suppose you want this format:

lastname, first name

but only if there is a first name, if the first name is null you just want the last name with no comma

let's say there is a rule on the database that the last name cannot be null, so we can write the query as:

select lastname + isnull(', '+firstname, '')
from test

and we get:

1 smith, john
2 doe, john
3 perez

see, I concatenated the comma with the first name, and if the first name is null, the the comma gets eliminated as well

Just one more trick for your bag of tricks

Tuesday, June 12, 2007

C# quiz #2: objects, strings, null

this is a continuation from the previous quiz; given this class definition:

public class Foo {
    public void Bar(object x) {
        Console.WriteLine("object x was called");
    }
    public void Bar(string x) {
        Console.WriteLine("string x was called");
    }
}

what will be output to the console with the following code:

Foo f = new Foo();
try {
    f.Bar(null);
}
catch {
    Console.WriteLine("no method was called");
}

Extra points for explaining why

Monday, June 11, 2007

how to tell google to NOT load the country specific page

Scoble is having this issue right now, I've had it in the past and forgotten to post this here, google tries to play smart and load the country specific page, so if you are in Mexico and you go to google.com, you'll get google.com.mx instead, to fix it just go to this url

google.com/ncr