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

Sunday, June 10, 2007

Cheap tricks to get a more popular blog

There are a few tricks that I have seen used more and more lately to try to get more attention to blogs

1) use adult content related words to refer to some technical topic (but not necessarily), some recent examples of such use recently:
  1. Computer Hardware Pornography
  2. ...What you're not getting about Ruby and why it's the tits
  3. "As a gay man and a gay journalist"
  4. "..Cierra la puta boca, gilipollas, Siesta, Fiesta, Cerveza, Real Madrid, Raúl, Hijo de Puta y Mierda."
you are likely to get some "google love" for sure with those keywords

2) get in a debate with some "big guy", this technique is getting used more and more lately, we have
Jeff Atwood vs Petzold's
Ayende vs Ted Neward's
Ayende vs Sam
Rob Conery vs Ayende
Nick vs Sam
heck, Ayende vs the rest of the world, J

etc, all you have to do is talk trash about something a guy posted on his blog, or about some of the work (usually open source) the guy works on, if your blog is not very popular, make sure to leave a comment on the other blog so the guy notices you

3) ask for link love, this specific case actually has a merit, this should be listed under "how to get a popular blog in 10 days", but the idea is the same

sigh... boring stuff, but I guess it works if all you want is to get more people to your blog (inflate your numbers), even if what they find is not exactly what they were looking for (first case)

Saturday, June 09, 2007

programming practices: never say never

Jan Bannister wrote this post: bool considered harmful, and writes:
Never Use Bool, or more specifically never user bool as a parameter. It is the most foolish of datatypes and conveys the smallest amount of information possible.
I can disagree with that in a number of ways, but the culprit was the "never use bool as a parameter", the biggest problems I see
- you would end up with hundreds of enums to replace your bool parameters, and then
- where do you put all those enums?
- at some point you would probably duplicate some of the required functionality

so, what do we do, bool is still "harmful", but not always, that's the key, I can think of at least 2 situations where you don't necessarily need to replace your bools with enums
- private methods: they are (hopefully) only used in that class... and the method is not that big, and the class is not that big, and you added comments for the method/parameters... sigh...
- functions with a single parameter that is just an on/off thing, e.g. SetVisible(true)

there, now it doesn't sound that bad, bottom line, never say never, don't abuse any technique

C# Quiz #1: overloads, strings, nullable types

*This is also a test of the latest Windows Live Writer

given this class definition:

public class Foo {
public void Bar(string x) {
Console.WriteLine("string x was called");
}
public void Bar(int? x) {
Console.WriteLine("int? 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");
}

*update: I messed up the code while trying to upload another post, I recovered the original post from my RSS feed

Wednesday, June 06, 2007

Filemon saves the day once again

I'm back, I had a head injury during a soccer game, I was very dizzy for over a week, but it's all good now

This time it was an ActiveX control (we're still fighting with ActiveX controls), I thought I had done everything I needed to do to get it up and working, but it would simply not load, so I loaded Filemon to see if it was even referencing the dll file, and it found two references, one to the GAC folder, and one to the program files\Internet Explorer, but no reference to where we actually copied the dll.

So I decided to copy the dll to where IE was looking for it, I copied the file to
c:\program files\Internet Explorer\
and everything started working wonderfully

I guess I could've added it to the GAC too, but I was very frustrated at that point since I thought I had tried that before and still wasn't working.

anyway... I guess that's another trick you can try when you have tried everything else deploying your ActiveX control, use filemon to see where IE is actually trying to load your dll from, and copy it there

and if you still don't know what filemon is, you owe it to your self, it's an amazing tool, it will save you many hours of headache (just not the ones caused by injuries during a soccer game J)

Tuesday, May 22, 2007

how to: fix google reader when it reports new items that we cannot see


every once in a while (happened to me twice today) google reader (for different reasons) reports that we have new (unread) items, but we cannot see them (because they don't really exist), to fix this problem simply
- click "all items"
- click "mark all as read"

GPS mobile phone tracking system, track any cellphone, anywhere

wow... Found this via Aldoara, you thought cell phone tracking was only possible in the movies?... go check it out

Friday, May 18, 2007

.NET user control not loading under https

keywords: .net user control, activex, ocx, IE7, IE, https, http, secure

Justin and I just had a heck of a week fighting ActiveX controls developed using C# in .NET 2.0, so we will be blogging about some of the issues that we found and their solutions (so we can remember later), the first one is about ActiveX controls running under https.

We developed our control, everything was fine, one of our clients wanted to try that over a secure site, so we said no problem... until we tried, and tried, and tried, and nothing worked, the control would just not load.

the solution ended up being really stupid (as is usually the case); when you include your control, you usually do something like this:

<object id="someId" classid="SomeDll#Namespace.ClassName"></object>

that's the way you'll find it in all the examples around the web, and that will work just fine (once you get past all the other stuff that is required to make it work) under http, but when you move that to https, it will simply not work.

the solution?

when you create your control, you assign a guid to it

[Guid("CAE67AEA-F489-4e52-956B-CCC774F40A3A")]
[ClassInterface(ClassInterfaceType.None), ComSourceInterfaces(typeof(IControlEvents))] // --Expose events
[ComVisible(true)]
public partial class MyControl : UserControl...

something like that...
well, to make it work on https, you simply have to use that GUID, not the class name, so you would just write this on your html code

<object id="someId" classid="clsid:CAE67AEA-F489-4e52-956B-CCC774F40A3A"></object>

done, hope we saved you hours of headache

Thursday, May 17, 2007

(humor) I'm a programmer...


a little humor

Tuesday, May 15, 2007

one hour of timezone difference doesn't always mean one hour of time difference

this is one of those "why didn't I know that?" stupid little things...

this caught me off guard as I was traveling, I went to a city that I knew was under the next timezone, so I adjusted my cellphone, but the time didn't change... I got confused for a little bit, then started changing to other timezones just to realize this fact

after that I verified the same behavior on my PC, if you still don't believe it you can try right now, switch your pc to different timezones, and you'll see the time changing unexpectedly

e.g. the actual time is the same at
(GMT-07:00) Mountain Time (US & Canada) and
(GMT-06:00) Central America

I know of at least one application where this actually causes a problem...

how to: easy way to see the methods and properties exposed in a TLB file

...just drag and drop the file in Visual Studio (at least in VS2005 it works), it will add it to the object browser and you can expand it to see it's methods and properties full definition

Wednesday, May 09, 2007

igoogle broken... again

a few days ago I saw that the google personalized pages (now called IGoogle) was broken, but mine was fine, so I laughed at all of those souls (just kidding), but today my igoogle is broken! aaarggh, nothing works, I can't minimize/close any gadgets, the gadgets are there but don't display anything, I can add new ones but they don't work

sigh...

fix your mom's computer for mother's day

I thought this would be all over the blogosphere by now, but is not, and I thought it was a good idea, this comes from Joel Spolsky

This Sunday is Mother's Day. Why not fix your mom's computer?

You know: remove the spyware and adware, install Firefox, and make it so that weird toolbar toast doesn't pop up every 15 seconds.

To make it easy, this Sunday we're making Fog Creek Copilot absolutely free.


for those of you who may not know, copilot is software that allows you to connect remotely to any computer, you don't have to worry about firewalls, etc, it just works

check it out