Thursday, November 19, 2015

Always Open Google Chrome with Default User Active from Taskbar

Users in Google Chrome are great. I wish every browser had a similar feature. If you have multiple browser windows open at once running different users (one for work email, one for personal, for example) a downside is that whichever browser window you close last will be the User that is used when you open Chrome again. However, by modifying the taskbar shortcut you can override this functionality and always have your "Default" user be used.


Right click on the Google Chrome taskbar icon, then right click on the "Google Chrome" entry in the popup menu.

(Apparently Windows Print Screen does not work if the taskbar is active, so I had to take a picture on my phone...)



In the Google Chrome Properties shortcut settings window that appears, append ` --profile-directory="Default"` to the end of the Target value.



And that's it. Now when this shortcut is used Google Chrome should open using the default profile no matter which User was associated with the last browser window was closed last.

Hope this helps,
Aaron


more info


Thursday, October 22, 2015

SQL Server vs .NET DateTime Leap Year Arithmetic

I recently refactored some code that was performing date arithmetic in SQL Server. The code was attempting to retrieve the "same day next year" by adding 365 days to the date provided. I was refactoring this logic out of SQL Server and in to .NET, and I was concerned that .NET's DateTime arithmetic wouldn't match SQL Server. I was pleasantly surprised that the results were the same. However, I should call out that perhaps in your situation adding 365 days to a given date is not appropriate for getting the "same day next year" value. I also compared this logic when preforming a "Add years + 1" and the results were also the same. (However, to be clear, adding 365 days differed from adding 1 year, but both SQL and .NET preformed the same given the method used.)

source code: https://gist.github.com/aaronhoffman/3d997390dab7f69e6597

results table:

MethodValueStartDate.NET ResultSQL Result
AddDays3652/27/20112/27/20122/27/2012
AddYears12/27/20112/27/20122/27/2012
AddDays3652/28/20112/28/20122/28/2012
AddYears12/28/20112/28/20122/28/2012
AddDays3653/1/20112/29/20122/29/2012
AddYears13/1/20113/1/20123/1/2012
AddDays-3652/27/20122/27/20112/27/2011
AddYears-12/27/20122/27/20112/27/2011
AddDays3652/27/20122/26/20132/26/2013
AddYears12/27/20122/27/20132/27/2013
AddDays-3652/28/20122/28/20112/28/2011
AddYears-12/28/20122/28/20112/28/2011
AddDays3652/28/20122/27/20132/27/2013
AddYears12/28/20122/28/20132/28/2013
AddDays-3652/29/20123/1/20113/1/2011
AddYears-12/29/20122/28/20112/28/2011
AddDays3652/29/20122/28/20132/28/2013
AddYears12/29/20122/28/20132/28/2013
AddDays-3653/1/20123/2/20113/2/2011
AddYears-13/1/20123/1/20113/1/2011
AddDays3653/1/20123/1/20133/1/2013
AddYears13/1/20123/1/20133/1/2013
AddDays-3652/27/20132/28/20122/28/2012
AddYears-12/27/20132/27/20122/27/2012
AddDays-3652/28/20132/29/20122/29/2012
AddYears-12/28/20132/28/20122/28/2012
AddDays-3653/1/20133/1/20123/1/2012
AddYears-13/1/20133/1/20123/1/2012


Hope this helps,
Aaron


Wednesday, September 23, 2015

Generate SQL Statements to Group By Each Column of Table Separately

When working with data with the intent to visualize, there are times when I'll want to group by every column in a table, separately, one at a time, to determine the possible values in that column.

I do this often enough I created a simple SQL Query to build these group by statements for me:


declare @table_name varchar(200) = 'dbo.mytablename'
select
'select ' + c.name + ', count(1) cnt from ' + @table_name + ' group by ' + c.name
from sys.columns c
where c.object_id = object_id(@table_name)



Hope this helps,
Aaron