Wednesday, March 12, 2008
iTunes and QTFairUse
<tangent>
am i the only one to notice a strange correlation between the timing of QT supporting the most current version of iTunes and iTunes prompting me to upgrade to a newer version that contains just fuckloads of new features. ever wonder why iTunes seems to be the only product that doesn't come with a 'what's new' document, or why you can't find any reference to this on their website? that's because, as far as i can tell, nothing new has been added since 6.0 - maybe even somewhere in the 5.x realm. why can't the assholes just admit that the only new feature is a new encryption key to keep the crackers (the computing type, not white people in general) off their tails for a few months?
</tangent>
that was the background, here is the problem: i upgraded to 7.5 and was able to download my music, but QT kept saying it couldn't find my music library. i navigated to my music folder and found an assload of .itl and .xml files with ' - copy (n)' and even some ' - copy (n) copy' appended to the filename, where n went as high as five or six. i assumed these were created by QT since there is an option to backup the current library and this option is selected by default. what i couldn't find was the non-copied version of my library, which is what QT was looking for. i moved all of these .itl and .xml files to a backup folder thinking that iTunes would prompt me for the location of my library and i could just rename my latest copy to the default name and put it back in the original location and everyone would be happy. this didn't happen. iTunes instead created a new .itl and .xml file with ' - copy (x)' (can't remember which it was) in the default location and the application came up with nothing in my music library.
solution: close iTunes, then hold down shift and launch it again. it will prompt you to use an existing library or create a new one. at this point, you can copy one of the backups to the default location, give it the default library name, and you will have all your music back in your library and the ability to strip your songs of evil, evil copyright protection once again
p.s if anyone needs either the installer for iTunes or QT, feel free to contact me.
Wednesday, February 13, 2008
classical mechanics problem: box on an incline
Q: a box of mass m sits motionless on an incline. what is the maximum angle Θ of the incline before the box begins to slide down?
A: all good little physics students know the first step is to draw a diagram and then add forces:

where Θ is the angle of the incline, μ is the coefficient of friction and N is the normal force
now lets disect the horizontal and vertical forces on the box:
ΣFx = horizontal component of gravity - friction = mgsin(Θ) - μN = 0 (box is stationary)
-> mgsin(Θ) = μN
ΣFy = vertical component of gravity - normal force = mgcos(Θ) - N = 0 (box is stationary)
-> mgcos(Θ) = N
we have two equations and three unknowns (Θ, μ, and N). the second equation gives us a N in terms of Θ, so let's plug it into the first equation and then solve for Θ:
mgsin(Θ) = μ(mgcos(Θ))
cancel out mg on both sides and get μ by itself:
μ = sin(Θ)/cos(Θ) = tan(Θ)
bring tan to the other side and we are done:
Θ = arctan(μ)
the solution tells us that the largest angle of incline before the box moves is dependent on the coefficient of friction of the incline.
mercy i loves me some classic mechanics :)
bubu made the rock band hall of fame
come to think of it, all the above mentioned people with the exception of good sir and winnie work with YEAHYEAH and i. i think this is one of the reasons that i love where i work - i like to hang out with my coworkers, be it going out boating, going out to a bar, hanging out late at work late and discussing business over a beer or just having everyone come over for some rock band jam'ins. at least half of tha dream's wedding last week was composed of coworkers. i genuinely consider these people friends and am eternally grateful that i work for a company that encourages this kind of environment.
the effects of changing a machine's name on sql server
SELECT @@servername
it will probably return the name of the machine (\instance name) before you renamed it. the fix is this:
sp_dropserver '{oldname}'
where {oldname} is whatever was returned by your first query. after that, run this:
sp_addserver '{newname}(\instancename)', 'LOCAL'
obviously only include (\instancename) if it is a named instance of sql server. restart the sql server service, then re-run your original query and it should return the correct name (you will have to either open a new query editor or re-connect the query editor screen you originally used as restarting the service will cause a disconnect).
Tuesday, February 12, 2008
damned system named constraints
solution: system tables aaaaaaaand ...
dynamic sql!!! weeeeeeeeeeeeeeeee
(i don't know why i got excited about something i genearlly preach against, but, as i've said before, dynamic sql is a necessary evil and can be very useful)
/*1. i think it is good practice to validate that something exists before dropping it (or does not exist before adding it). that way if a sql query that is part of a hotfix is accidentally run more than once, no errors should occur. this script simply checks to see if there is a constraint on a column named 'col_a' in table_a:*/
IF EXISTS (SELECT OBJECT_NAME(constid) FROM sysconstraints CN
INNER JOIN syscolumns CO
ON CN.id = OBJECT_ID('table_a') AND CO.id = CN.id AND
CO.name = 'col_a' AND CN.colid = CO.colorder)
BEGIN
/*2. the following sample then removes the constraint from the column:*/
DECLARE @Sql AS NVARCHAR(2000)
SELECT @Sql = 'ALTER TABLE table_a DROP CONSTRAINT ' + OBJECT_NAME(constid)
FROM sysconstraints CN
INNER JOIN syscolumns CO
ON CN.id = OBJECT_ID('table_a') AND CO.id = CN.id AND
CO.name = 'col_a' AND CN.coldid = CO.colorder
EXEC(@Sql)
END
/* to be extra safe, you may want to include the type of constraint you are dropping as part of the join. the type of constraint is contained in the pseudo-bit-mask value of the sysconstraints 'status' column. as an example, a default constraint will have a status value of '133141' */
Tuesday, January 29, 2008
preserving the stack trace when handling exceptions
here's the gist:
case i) if a method call within a try...catch block results in an exception, calling throw(with or without an exception instance) causes any code in the ...finally block to immediately execute and then execution continues on its jolly way up the call stack. if you want to log anything about the error, do so before calling throw. furthermore, calling throw by itself preserves the call stack, whereas calling throw with an exception instance causes the stack trace to restart from the method that re-throws the exception and you lose whatever precious debugging information you had about what was going on before the call.
case ii) if procedural code within a try...catch block results in an exception, you lose the stack trace whether you throw with an exception instance or without. you should log what you need to know about the error before you throw as suggested in case i) and additionally log the stack trace.
if you are truly masochistic/sadistic (not sure which but i'd lean towards the former), you can follow what some bloke by the name of Chris Taylor outlines here
Thursday, January 24, 2008
selective filtering, part iii - dynamic sql filtering
if you are using dynamic sql to filter a query based on an optional/nullable parameter, you have to provide something to your WHERE clause in the case that you receive all nulls. here is an example that will not work using the clever ISNULL technique i discussed in my first post:
DECLARE @sSQL nvarchar(4000)
SET @sSQL = 'SELECT col_a FROM table_a '
SET @sSQL = @sSQL + 'WHERE col_b = ''' + ISNULL(@param1, 'col_b') + ''''
exec sp_executesql @sSQL
GO
DECLARE @sSQL nvarchar(4000)
SET @sSQL = 'SELECT col_a FROM table_a '
IF @param1 IS NOT NULL
SET @sSQL = @sSQL + ' WHERE col_b = ''' + @param1 + ''''
exec sp_executesql @sSQL
GO
DECLARE @sSQL nvarchar(4000)
SET @sSQL = 'SELECT col_a FROM table_a '
IF @param1 IS NOT NULL
SET @sSQL = @sSQL + ' WHERE col_b = ''' + @param1 + ''''
IF @param2 IS NOT NULL
SET @sSQL = @sSQL + ' WHERE col_c = ''' + @param2+ ''''
exec sp_executesql @sSQL
GO
DECLARE @sSQL nvarchar(4000)
SET @sSQL = 'SELECT col_a FROM table_a '
SET @sSQL = @sSQL + 'WHERE 1=1 '
IF @param1 IS NOT NULL
SET @sSQL = @sSQL + ' AND col_b = ''' + @param1 + ''''
IF @param2 IS NOT NULL
SET @sSQL = @sSQL + ' AND col_c = ''' + @param2+ ''''
exec sp_executesql @sSQL
GO
now that you've specified a condition that's always true (WHERE 1=1), you can dynamically add additional filters as needed. pretty damn slick if i do say so myself
one last thing - i always declare @sSQL as nvarchar(4000) in my examples because sp_executesql only works with variables with data types of nchar, ntext and nvarchar and the maximum size of an nvarchar variable used with sp_executesql is 4000