Thursday, October 06, 2011

Steve Jobs, 1955 - 2011

“Being the richest man in the cemetery doesn’t matter to me … Going to bed at night saying we’ve done something wonderful… that’s what matters to me.”

Monday, May 16, 2011

Visual Studio: ASP.NET MVC, Flip quickly through your controllers and views

This tip is specifically for those writing ASP.NET MVC applications using Visual Studio

As your MVC application grows, the number of views and controllers can grow pretty quickly and ctrl+tabbing through them gets pretty painful, sometimes only to discover that you don't have *that* view open, so you need to go find it. That's where this tip comes in, if you right click on your controller, there's a menu option to go to the view, likewise, if you are in the view and right click there's a menu option to go to the controller, now, if you are a mouse guy, this is enough for you, you can stop reading now, but there's a quicker way, you can assign a shortcut key to those options

Go to Tools, Options, Environment (first option), keyboard, and type "GoToView" (without the quotes) and assign the shortcut you want, chose one that is not being used, or one of a feature you don't use (there are  millions of those), for this type of thing that I do a lot, I like using keys that are easily accessible, put that F1 key to good use!!, do the same thing for the "GoToController"

Click OK and you're ready to roll, go to your controller and press your shortcut, you'll be flipping through your views and controllers like there's no tomorrow!

You're welcome J

Saturday, March 19, 2011

Kindle: We were unable to download the book... please try again later

A few days ago I installed Kindle on my Mac Book Pro, then only after a couple days of using it I suddenly got this error and was not able to open any of the two books I had just bought, I was able to open the books just fine on my iPhone and iPad, but the Kindle for Mac kept giving me this error message no matter how many times I tried clicking; a search on Google gave me 3 results and no solutions, so I uninstalled the App and reinstalled, got nothing. I tried the Tools menu, manage your Kindle from the Kindle app which takes you to the amazon site, noticed the "your orders" at the bottom and the options to download the content, tried that a few times, still nothing, another thing I noticed on the Kindle app was that the title was something like "???????????????? Home", I knew something was messed up bad, but even reinstalling didn't fix it, so in one last desperate attempt I checked out the Kindle preferences [Command]+, or under the Kindle menu, preferences, I clicked the only button there: "Deregister", agreed to the warning and selected "remove all licensed content from this device" and clicked "deregister" again on the warning window; a register button then showed up, I clicked it to register the app again, had to agree to some other warning, and that right there was the solution, I was able to get my books (had to download them again) and start reading, so I'm just leaving this out there in hopes it can help someone else; long story short, deregister the app, make sure to select "remove all licensed content from this device", then register again.

Wednesday, March 02, 2011

FluentNHibernate: "unable to locate persister:"

There's quite a bit of info out there for this error message, but all I could find refers to xml configuration, the recommendation being somewhere along the lines of:

  1. Make sure your mapping file is named *.hbm.xml
  2. Make sure it is set to an embedded resource.
  3. If all else fails, debug.

What most articles fail to mention is the root cause, which is the fact that NHibernate was not able to load the mappings for the class you are trying to use in your query, knowing that you can at least focus in a single area, in the case of fluent nhibernate, the configuration looks something like this:

public static ISessionFactory CreateSessionFactory() {
   return Fluently.Configure()
   .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("AppDb")))
   .Mappings(m => m.FluentMappings.Add<ProductMap>())
   .Mappings(m => m.FluentMappings.Add<CategoryMap>())
   .ExposeConfiguration(c => c.SetProperty("current_session_context_class", "web"))

The two .Mappings() lines are the bug in this case, any subsequent calls to it override the first one and you won't be able to query Products
There are two ways of fixing this, one you can tell it to load all the mappings found on the same assembly as the first map

   .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ProductMap>())

or if you want to be specific:

   .Mappings(m => { m.FluentMappings.Add<ProductMap>();
                    m.FluentMappings.Add<CategoryMap>(); })

Hope someone else finds this helpful

Monday, February 28, 2011

IE 9 : How to get your old address bar back

IE9 introduced a new address bar that is located on the same row as the tabs that are open, that may be useful for some people, but for everyone else it's just annoying, luckily they added an easy way to change it back to the same way it was before, all you have to do is right click on any tab or the tab area and you'll get a "show tabs on a separate row" option at the bottom

And that's it, you get your old address bar back :)

Friday, December 10, 2010

SQL: Group datetime by an arbitrary time interval

Yesterday, a co-worker came to me with a puzzle, he wanted to write a query that would group records by intervals of 5, 10, 15 minutes, ideally just passing a parameter to the query to specify the time interval, I sat down and after 5 minutes I came up with the solution:

declare @interval int
set @interval = 5
select datepart(hh, DateTimeColumn)
, datepart(mi, DateTimeColumn)/@interval*@interval
, count(*)
from thetable
group by datepart(hh, DateTimeColumn)
, datepart(mi, DateTimeColumn)/@interval*@interval

The trick is highlighted, though it looks like the division and multiplication eliminate each other, what is really happening is an integer division, which, multiplied by the same number, gives you the right intervals:

here's the (minutes) values pattern for an interval of 5

minute divided by 5 multiplied by 5
0 0 0
1 0 0
5 1 5
6 1 5
10 2 10
11 2 10
from there you can include more fields in your select criteria, make it prettier, etc

declare @interval int
set @interval = 5
select convert(varchar(8), DTColumn, 1)+' '
      +convert(varchar(2), datepart(hh, DTColumn))+':'
      +convert(varchar(2), datepart(mi, DTColumn)/@interval*@interval)
, count(*)
from the_table
group by convert(varchar(8), DTColumn, 1)+' '
      +convert(varchar(2), datepart(hh, DTColumn))+':'

      +convert(varchar(2), datepart(mi, DTColumn)/@interval*@interval)

which produces something like:

11/12/10 10:10    28

11/12/10 10:15    11

11/12/10 10:20    57

hope this is useful

Monday, November 29, 2010

VirtualBox VM won't release the mouse

Just a quick post to share this, I'm playing with VirtualBox on my OpenSuse 11.3, installing Windows XP on a VM, I decided to click inside the VM while it was still installing, hoping that the right [ctrl] key would release the mouse, but that didn't work, Googled a bit with no good results, there's many related articles about this issue, but no solution, I was ready to give up so I hit ctrl+alt+del and what do you know, that released the mouse :)

hope this helps someone out there

Tuesday, September 21, 2010

Apple intuitiveness: Upgrading OS X results in downgraded components

I just upgraded my OS X to Snow Leopard (yeah, a bit late), first of all I just can't wrap my head around the idea that OS X runs on a single hardware configuration (ok, maybe 3) yet it took over an hour to install, while Windows runs on millions of hardware configurations and can install in 15 mins (as in, ready to start using it), I just can't find that intuitive, it doesn't make sense; but anyway, one of the 3? 'big' features in this update is Safari 4, before installing I noticed I already had Safari 5, so I went ahead and did the install, to my surprise when it finally finished I had now Safari 4!! WTF? over an hour upgrading and they couldn't check if the components had a higher version than the one being installed? To be honest I was afraid to check if there was something else that got downgraded. Upgrading OS X results in a downgrade of it's components! how's that intuitive?
To top if off, after upgrading I went to check for updates, there were 776MB of updates (and these are the people who make fun of Windows updates?), and sure enough, Safari 5 was on the list.

So, to recap: I had Safari 5, I upgraded OS X, it got downgraded to Safari 4, then I had to get a 776MB update to get back to where I was before the upgrade. Intuitive or not, I'll let you be the judge xD.

Update. after another 10 minutes, more updates came up, this time an additional 200MB, requiring, of course, that I reboot again.