Monday, August 27, 2012
Oatmeal of the Gods
This stuff is so amazing I want to eat it all the time.
.5 Cup dried oats
1 Cup water
cubed pinapple
cinnamon
2 packets splenda
crushed walnuts
3 egg whites
1 egg
1) Make oatmeal according to recipe
2) Once it's done, put the egg whites and egg into a heated pan
3) Add oatmeal to the eggs and stir till the egg is cooked.
4) Remove egg and oatmeal mixture from pan and put it into a bowl. Add cinnamon, splenda, pinapple and walnuts (pretty much to taste).
5) ENJOY!
Monday, August 20, 2012
WARRIOR DASH 2012!
This morning I pushed through double quadricep strains and went up to the high country to compete in Warrior Dash. Got up there, and began pounding energy drinks. Finally after two bouts of pee breaks, we made our way to the starting line. A few switch backs and then about a quarter mile uphill and we got to the first obstacle.
1) Climb over 3 ft walls, under 2ft barbed wire, repeat x4
Whoo! The running is starting to catch up to me, but i push on through to obstacle... 2) balanced walk over a series of up down up down planks about 10 feet off the ground.
Crushed it, and look! I can see the next obstacle... wait, whats this quarter mile switchback I have to do? and why are my aforementioned quads stinging with every step? No time to bitch. Around the curve and up the next obstacle:
3) Climb up wooden rafters, then over the top, one rung down, you drop to the bottom.
more running.... 4) Run through tires
MORE RUNNING!
5) Jump over some fire.
Now comes the hellish ascent to the courses highest point. The grade gets gradually steeper and steeper and longer and longer, and to add insult to injury, there is another 6) up and over wooden steeple and 7) low pipes to crawl through. Made it to the top huffing and puffing, descend down a steep slope with ropes, and then get to obstacle...
9) Climb a rope over a wall, then drop down from the top of the other side to the ground.
Run some more (FINALLY DOWNHILL)
10) Cargo nets
run
11) swim through mud under barbed wire
Finish. Drink Beer. Wash. Rawr.
1) Climb over 3 ft walls, under 2ft barbed wire, repeat x4
Whoo! The running is starting to catch up to me, but i push on through to obstacle... 2) balanced walk over a series of up down up down planks about 10 feet off the ground.
Crushed it, and look! I can see the next obstacle... wait, whats this quarter mile switchback I have to do? and why are my aforementioned quads stinging with every step? No time to bitch. Around the curve and up the next obstacle:
3) Climb up wooden rafters, then over the top, one rung down, you drop to the bottom.
more running.... 4) Run through tires
MORE RUNNING!
5) Jump over some fire.
Now comes the hellish ascent to the courses highest point. The grade gets gradually steeper and steeper and longer and longer, and to add insult to injury, there is another 6) up and over wooden steeple and 7) low pipes to crawl through. Made it to the top huffing and puffing, descend down a steep slope with ropes, and then get to obstacle...
9) Climb a rope over a wall, then drop down from the top of the other side to the ground.
Run some more (FINALLY DOWNHILL)
10) Cargo nets
run
11) swim through mud under barbed wire
Finish. Drink Beer. Wash. Rawr.

Monday, July 30, 2012
Reset SQL Server 2008 SSMS Shortcuts
Recently I've been playing with gVim trying to get into the lightning fast editing that is said to come with using vi as an editor. Problem is, unless I'm mistaken (I'd be happy to be proven wrong here) it's difficult or impossible to add the common tasks I use with SSMS. F5 to execute, remove results pane, new/next window etc.
An addon I was trying out called ViEmu added a lot of great vi functionality to SSMS. It's something that I think users adept at using vi would love. Maybe even an SSMS user could learn to love. But I'm new, and like anyone starting out using vi, it's frustrating, so in lieu of the hundreds of projects looming which need to get done, I guess learning vi will have to wait.
What does this have to do with my posting? This addon (as do many other SSMS addons) remaps many commonly used shortcut. Ctrl-r to hide results pane, alt-w to access window switching, even ctrl-n for new query window. Begin google search for resetting keyboard shortcuts in SSMS.
Turns out for whatever reason, SSMS really doesn't like you being able to easily change your shortcut settings, and a surprising dearth of information was available on the interwebs on this topic. I got it to work, so let me distill what I can for you.
You have to go to your app data directory. Depending on your version and how your machine(s) is/are setup, your path may look something like this:
C:\Documents and Settings\ShayShay\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell
in there, you're looking for two .vsk files - User.vsk and/or Current.vsk. I found them both in the directory mentioned above, but it sounds as though they may be in slightly different paths in the SSMS app data dir.
Point is, close SSMM, delete those two files (or as i did, cut and paste them to my desktop to be safe) then start up SSMS. Try something simple like select 1 + f5 = ctrl-r (toggle results pane) or really whichever your previously existing shortcut was. If it's still borked, time to go hunting through your app data dirs for other offending .vsk
NOTE: I'm not sure what the result of deleting .vsk files at will are. So far, SSMS looks like it auto-remakes the necessary files wiht default settings (what I wanted) but always be careful snipping out random files. I'd really recommend cutting and pasting them to desktop or something so that if things go horribly wrong, you dont end up in a worse situation than you started in.
An addon I was trying out called ViEmu added a lot of great vi functionality to SSMS. It's something that I think users adept at using vi would love. Maybe even an SSMS user could learn to love. But I'm new, and like anyone starting out using vi, it's frustrating, so in lieu of the hundreds of projects looming which need to get done, I guess learning vi will have to wait.
What does this have to do with my posting? This addon (as do many other SSMS addons) remaps many commonly used shortcut. Ctrl-r to hide results pane, alt-w to access window switching, even ctrl-n for new query window. Begin google search for resetting keyboard shortcuts in SSMS.
Turns out for whatever reason, SSMS really doesn't like you being able to easily change your shortcut settings, and a surprising dearth of information was available on the interwebs on this topic. I got it to work, so let me distill what I can for you.
- SSMS doesn't store keyboard shortcut information in the registry but rather in local files so uninstallation won't necessarily help.
- the files are user specific so they are stored in AppData as opposed to somewhere in the install directory.
- SSMS stores keyboard shortcut data in .vsk files (two of which seem to be responsible for the settings concerning SSMS
You have to go to your app data directory. Depending on your version and how your machine(s) is/are setup, your path may look something like this:
C:\Documents and Settings\ShayShay\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell
in there, you're looking for two .vsk files - User.vsk and/or Current.vsk. I found them both in the directory mentioned above, but it sounds as though they may be in slightly different paths in the SSMS app data dir.
Point is, close SSMM, delete those two files (or as i did, cut and paste them to my desktop to be safe) then start up SSMS. Try something simple like select 1 + f5 = ctrl-r (toggle results pane) or really whichever your previously existing shortcut was. If it's still borked, time to go hunting through your app data dirs for other offending .vsk
NOTE: I'm not sure what the result of deleting .vsk files at will are. So far, SSMS looks like it auto-remakes the necessary files wiht default settings (what I wanted) but always be careful snipping out random files. I'd really recommend cutting and pasting them to desktop or something so that if things go horribly wrong, you dont end up in a worse situation than you started in.
Monday, July 23, 2012
Despite the fact that reality is really just a construct of the mind – filtered sensory input through a veil of individual experience, at least on a personal scale – most sane people have a good grip on what’s real to them. It’s really cool to think about what reality means to each of us. The same painting, song, phrase can have a profoundly different impact from person to person. When you think about the fact that we can play out what-if scenarios, imagine being in outer space, fantasize about island vacations or what might happen if we run this red light, reality is really just a single path, a single slit through which we choose to observe our reality flow through. In reality, the membrane separating what could be, what is, and what is not is razor thin. It may not, and in all likelihood, doesn’t exist, at least not in the sense that a traditional boundary might exist, but whatever interplay of neurons allows for the distinction, let us refer to it as a membrane. Somewhere however, we draw the line between fact and fiction and navigate the universe in a way which is coherent and stable. What happens when that membrane fails? When the stories created by sensory inputs are given equal credence to the next? When the conscious mind is unable to distinguish between the “right” and “wrong” paths? Right, in this sense means the version of reality which most closely lays on top of the functionality of the objective world. Certainly, there is no true “right” path, but as goes one of my favorite quotes, “it’s a little wrong to say a Tomato is a vegetable. It’s very wrong to say it's a suspension bridge”.
Somehow out of the massive amount of information which flows through our senses in a given period of time, we have to come up with a coherent view of reality. Additionally, we string individual moments together to tell an ongoing story, one which is guided by the preceding moments as well as the current. Take for example the idea of the butterfly effect. Assuming the collapse of the membrane between fact and fiction is instantaneous, the individual would instantly have to choose between what seem to be a very large set of congruent versions of reality. Once chosen, from moment to moment new realities will have to be chosen. In my entirely subjective opinion, if a coherent thread cannot be found, consciousness ceases to occur. Sensory inputs “short out” or fizzle to nothing as does the majority of the input which we don’t actively process. However within the noise, if the mind can catch on to a theme connecting realities, that story will begin to play out, however convoluted it’s path until the membrane can be reestablished and align thought with the past of most congruence.
If you’ve ever listened to someone paranoid about, say Big Brother spying on them, or perhaps listened to yourself as you hear the floorboards creak, the stories, objectively are pretty ridiculous. A car has been parked outside for a week. At the same time, your neighbor hasn’t been seen at home in roughly the same time. And who was on the other end of that hang-up call this morning? The stories contain a thread of continuity at least, and sometimes while floating through the realm of possible interpretations of reality, a thread of continuity is the only reference point we have to an underlying reality.
Like trying to follow a straight line on the ground in a strobe light, for the most part it’s doable. The faster the strobe or the longer the periods of illumination, the easier it is to trace the line of reality. Even in slower strobes, you can correct your course quickly enough so that the path is always within grasp. The longer the darkness however, the easier it is to stray away from the line without even knowing it. After a time your brain thinks you’re moving straight when in fact you’re far from the center. What happens if the light never turns back on? How do you know whether you’re actually on the line or whether your brain just wants to believe that it is?
Somehow out of the massive amount of information which flows through our senses in a given period of time, we have to come up with a coherent view of reality. Additionally, we string individual moments together to tell an ongoing story, one which is guided by the preceding moments as well as the current. Take for example the idea of the butterfly effect. Assuming the collapse of the membrane between fact and fiction is instantaneous, the individual would instantly have to choose between what seem to be a very large set of congruent versions of reality. Once chosen, from moment to moment new realities will have to be chosen. In my entirely subjective opinion, if a coherent thread cannot be found, consciousness ceases to occur. Sensory inputs “short out” or fizzle to nothing as does the majority of the input which we don’t actively process. However within the noise, if the mind can catch on to a theme connecting realities, that story will begin to play out, however convoluted it’s path until the membrane can be reestablished and align thought with the past of most congruence.
If you’ve ever listened to someone paranoid about, say Big Brother spying on them, or perhaps listened to yourself as you hear the floorboards creak, the stories, objectively are pretty ridiculous. A car has been parked outside for a week. At the same time, your neighbor hasn’t been seen at home in roughly the same time. And who was on the other end of that hang-up call this morning? The stories contain a thread of continuity at least, and sometimes while floating through the realm of possible interpretations of reality, a thread of continuity is the only reference point we have to an underlying reality.
Like trying to follow a straight line on the ground in a strobe light, for the most part it’s doable. The faster the strobe or the longer the periods of illumination, the easier it is to trace the line of reality. Even in slower strobes, you can correct your course quickly enough so that the path is always within grasp. The longer the darkness however, the easier it is to stray away from the line without even knowing it. After a time your brain thinks you’re moving straight when in fact you’re far from the center. What happens if the light never turns back on? How do you know whether you’re actually on the line or whether your brain just wants to believe that it is?
Monday, June 18, 2012
Wednesday, May 30, 2012
SQL XML SPID Settings
I found some nifty uses of xQuery and xPath expressions in SQL recently, but I also ran into some errors promoting to a server with some SPID settings. Turns out there's a page on MSDN with the exact settings that need to be set in order for things like xml.query() and xml.nodes() to work.
ANSI_NULLS ON
ANSI_PADDING ON
ANSI_WARNINGS ON
ARITHABORT ON
CONCAT_NULL_YIELDS_NULL ON
NUMERIC_ROUNDABORT OFF
QUOTED_IDENTIFIER ON
http://msdn.microsoft.com/en-us/library/ms188285%28SQL.105%29.aspx
ANSI_NULLS ON
ANSI_PADDING ON
ANSI_WARNINGS ON
ARITHABORT ON
CONCAT_NULL_YIELDS_NULL ON
NUMERIC_ROUNDABORT OFF
QUOTED_IDENTIFIER ON
http://msdn.microsoft.com/en-us/library/ms188285%28SQL.105%29.aspx
Monday, December 12, 2011
Replace tags in a string
I ran into a situation today where a client wants to be able to give us a string for a disclaimer, but they want to be able to add tags to the string which, after we work our magic, will be replaced with a value from a table, making the string somewhat dynamic in nature. Here's how I went about doing it.
First, I made a function to house the logic around the tags. I realize there are a few shortcomings here and currently, this means that you can't have a '<' in the text without it being the start of a full tag ending in '>', but there are a few adaptations that I feel would be easy enough to implement if this became problematic. The code is a modified version of a comma-delimited string parsing function I use a lot. Basically what this part does is gets the charindex of the opening and closing brackets and then length between the two. It cuts out the substring between them based on that length and pops it into a table. After it does that, it cuts off everything to the left of that closing bracket (or to be more accurate, it keeps the right side). This repeats until you have a table filled with the contents of all the bracketed terms in the string.
Once we've got the tags parsed out, we can get into getting those values from a presentation table. For the purposes of what I had to do, it will always come from the same table, but I suppose if one were so inclined, you could do some funky dynamic sql to be able to specify a table name too, but I won't go there (right now). I've built up some basic sample data so you can see this in action, but the idea behind it is to:
1) parse out the string using the above function
2) set a variable = the fact name parsed from the string
3) retrieve the value from the presentation table based on the fact name from step 2
Then, much to my dismay, using a loop, I go through the parsed table and replace instances of the tag with the values I just set. If there's a set based way to do this, I'd love to know it, but I couldn't think of a way that didn't involve dynamic sql and lots of nested replace statements. And given that these tagged values are probably not ever going to be more than a few tags here and there, the strain of RBAR is not too bad.
If anyone who reads this understands what the hell I just did, I'd be happy to hear any ways you think this could be done better.
First, I made a function to house the logic around the tags. I realize there are a few shortcomings here and currently, this means that you can't have a '<' in the text without it being the start of a full tag ending in '>', but there are a few adaptations that I feel would be easy enough to implement if this became problematic. The code is a modified version of a comma-delimited string parsing function I use a lot. Basically what this part does is gets the charindex of the opening and closing brackets and then length between the two. It cuts out the substring between them based on that length and pops it into a table. After it does that, it cuts off everything to the left of that closing bracket (or to be more accurate, it keeps the right side). This repeats until you have a table filled with the contents of all the bracketed terms in the string.
IF OBJECT_ID (N'dbo.TagParse') IS NOT NULL
DROP FUNCTION dbo.TagParse
GO
CREATE FUNCTION dbo.TagParse(@String varchar(max))
RETURNS @TagValues TABLE
(
ident int identity(1,1) primary key clustered,
TagValue varchar(100)
)
AS
begin
declare
@FragText varchar(255),
@OpenIndex int,
@CloseIndex int,
@FragLength int,
@StringLength int
--Get some relevant information about the frament length and position
select
@OpenIndex = CHARINDEX('<', @String) ,
@CloseIndex = CHARINDEX('>', @String),
@StringLength = datalength(@String)
select
@FragLength = @CloseIndex - @OpenIndex
while @CloseIndex > 0
begin
select @FragText = SUBSTRING(@String, @OpenIndex + 1, @FragLength -1)
select @String = RIGHT(@String, @StringLength - @CloseIndex)
insert into @TagValues(TagValue)
select @FragText
select
@OpenIndex = CHARINDEX('<', @String) ,
@CloseIndex = CHARINDEX('>', @String),
@StringLength = datalength(@String)
select
@FragLength = @CloseIndex - @OpenIndex
end
return
end
Once we've got the tags parsed out, we can get into getting those values from a presentation table. For the purposes of what I had to do, it will always come from the same table, but I suppose if one were so inclined, you could do some funky dynamic sql to be able to specify a table name too, but I won't go there (right now). I've built up some basic sample data so you can see this in action, but the idea behind it is to:
1) parse out the string using the above function
2) set a variable = the fact name parsed from the string
3) retrieve the value from the presentation table based on the fact name from step 2
Then, much to my dismay, using a loop, I go through the parsed table and replace instances of the tag with the values I just set. If there's a set based way to do this, I'd love to know it, but I couldn't think of a way that didn't involve dynamic sql and lots of nested replace statements. And given that these tagged values are probably not ever going to be more than a few tags here and there, the strain of RBAR is not too bad.
if OBJECT_ID('tempdb.dbo.#FactSet') > 0 drop table #FactSet
create table #FactSet
(
FactName varchar(100),
FactValue varchar(100)
)
insert into #FactSet (FactName, FactValue)
select 'FactName1', 'Test Value 1' union all
select 'FactName2', '3.14'
declare @Tags table
(
ident tinyint primary key clustered,
TagValue varchar(100)
)
declare
@String varchar(max),
@ident tinyint,
@MaxIdent tinyint,
@FactName varchar(255),
@FactValue varchar(255)
--This is the string that will constitute the disclaimer text they want to chop up
select @String = 'This is a test string. Field 1: , Field 2: '
--Parse the string into its constituent tags
insert into @Tags (ident, TagValue)
select ident, TagValue
from sysmon.dbo.TagParse(@String)
--Get the max ident through @@rowcount so I dont have to actually hit the @Tags table
select
@Ident = 1,
@MaxIdent = @@rowcount
while @ident <= @MaxIdent
begin
--Get the name of the fact name we parsed and assign it to @FactName
select @FactName = TagValue
from @Tags
where ident = @ident
--Get the value from the Fact Set table which corresponds to @FactName
select @FactValue = FactValue
from #FactSet
where FactName = @FactName
--We then replace any instances of the original tag with the value we just got.
--Enclosing the @FactName in <> to simulate the original tag syntax.
select @String = REPLACE(@String, '<' + @FactName + '>', @FactValue)
select @ident = @ident + 1
end
select @string
If anyone who reads this understands what the hell I just did, I'd be happy to hear any ways you think this could be done better.
Labels:
Dynamic SQL,
Parse,
Parsing,
RBAR,
Server,
SQL,
SQL Server,
T-SQL,
Transact SQL,
TSQL
Subscribe to:
Posts (Atom)