Posts

Validate Date

Snippet: var msie = window.document.documentMode; /**** * Checks a controls value to see if it is a Date Value or not * * Parameters: * @cntrl - String; the Control ID value * @success - Function(); The Success function to execute * @fail - Function(); The Fail function to execute */ function ValidDate(cntrl, success, fail) { var valid = false; if (msie !== undefined) { var dtString = cntrlIDs[cntrl].value; var date = new Date(dtString); if (!isNaN(date)) { dtString = dtString.replace(/-/g, "/"); // Assumed pattern: MM/dd/CCYY var parts = dtString.split("/") var dd = parseInt(parts[1], 10); // Day Number var mm = parseInt(parts[0], 10); // Month Number var yr = parseInt(parts[2], 10); // Year Number if (dd === date.getDate() ...

Make CSS Inline

Scenario A client requested the ability to Copy/Paste the content of a report from the website to Word. Background The site in question was a compliance reporting website, where the information was being packaged together with other information to then be presented to the compliance agency.  This process occurred on a monthly, quarterly, and yearly basis. The current process, required the compliance "packagers" to copy the report results to Word and then "format" the contents to look as close to the website rendered format.  This process would consume close to a day, maybe two, pending on how many reports needed to be packaged. Problem After review of the situation, i noticed that the problem was occurring only in IE (Internet Explorer) browsers but not Chrome.  Since this organization was a Microsoft house and IE was the supported browser, they required the fix to be IE compliant. Once the problem was isolated to just IE, I started reviewing the ...

TSQL - String Concatenation

On current project, I ran into a scenario where I needed to concatenate a series of rows into a single string value.  Nothing major, just concatenate them with a delimiter and return the result.  As all of us Microsoft SQL developer's know and deal with is the lack of a SQL supported function that is able to assist us in this "minor" feature. As this is my knowledge dump for techniques and other methods used for the various platforms, here we go: Construct: The first step is to identify what information you want, the basic's of query design.   SELECT Email FROM Contacts Group By Email Group by is conditional, depending on your situation and how you organize your referential integrity. Stage Next, lets build our environment, not the SProc just the supporting actors in the process. declare @email varchar(max) = '' SELECT @email += Email + ', ' FROM Contacts Group By Email This simply concatenates each of ...

SQL Porosity - CSV Element Calculation

Image
Background: Recently "walked" into a scenario where a client was storing an variable sized CSV string in a field.  This field held data that would eventually be evaluated as a "pseudo" entity for reporting purposes. Problem Due to the need for performance and reliability, the normal practice of splitting the string into a result set and then performing a SQL Count on the result set, would be overly complex and may cause performance issues as the length is variable  (i.e. varchar(max) ) Solution After reviewing several search queries, which most ended up at my old faithful Stack Overflow .  I came across an approach that is nothing more than Porosity .  For my purpose, it fit the bill very cleanly without overly transitioning a single value into a data-set and then calculating the data-set. Net Result Data-Set : Source: SQL Data - Source Value SQL Data - Comma's Voided Math n -  Len([Field]) m  - Len(Replace([Field], ',', ...

Acquiring List of controls - Classic JS

Recently ran into a scenario where I need to use the low-level JavaScript parser, instead of JQuery.  During this venture, I ran across a situation where it would be easier for me to select all the HTML Elements with an ID, assign it to a variable as JSON, and then operate on it from that point. So using my previous short-hand experience with JQuery, I started constructing a similar type of format to be used. *********** JQuery *************** // One line and your done, pretty much var cntrls = $('[id]') // Later on, you simply access the element from the variable var val = cntrls['someID'].value *********** JavaScript *********** // Not so one-liner; put in the DOM.Ready event for JS var cntrlIDs = {} var root = document.getElementById('rootID').querySelectorAll('*'); for (i = 0, n = root.length; i < n; ++i) { var el = root[i]; if (el.id) { cntrlIDs[el.id] = el; } } // Later...

Executing a Stored Procedure....The Proper Way

As we develop in Microsoft's Entity Framework family, we will at times run into a situation, or by design, the need to execute a Stored Procedure from the database (most likely Microsoft SQL Server ).  As we have discovered, they (Microsoft) evidently do not want us to do this inherently.  They hid the direct SProc execution well down into the Database object (off the DbContext object ) and even then it has a few names: SqlQuery and ExecuteSqlCommand .  Of course, both of these have their equivalent ASync execution versions. To make matters even more fun and interesting, is the problem of Ordinal execution.  Any proper DBA will tell you, if asked, that Ordinal execution is a bad implementation pattern.  And you developers, will simply respond: Well then don't change the order in which the Parameters exist.  Then the DBA responds, and the banter battle begins between a Developer and a DBA. My simple solution to avoid this whole needless verbal battle...

HTML Compatability Modes

As a web-developer, I find it unfortunately necessary to force a browser(s) to conform to my preferred platform.  That being said, i have not been able (as of this posting) to find a aggregate knowledge base of all the available Meta values for the "X-UA-Compatible" header entry.  So below you will find my currently identified valid values. Syntax: <meta http-equiv="X-UA-Compatible" content="<value>"> Possible Values for <value>, by Browser: Internet Explorer = IE IE=5 Quirks Mode; pretty much anything less than IE 7 IE=7 IE 7 Mode IE=8 IE 8 Mode IE=9 IE 9 Mode IE=10 IE 10 Mode IE=11 IE 11 Mode IE=edge Highest supported document mode of the browser Quirks Emulate Values (If a valid <!DOCTYPE> declaration is present) IE=EmulateIE7 IE 7 Mode; otherwise, Quirks Mode (equivalent to IE=5) IE=EmulateIE8 IE 8 Mode; otherwise, Quirks Mode (equivalent to IE=5) IE=EmulateIE9 IE 9 Mode; otherwi...

SysInternals - BgInfo for ALL Users

Image
I have seen various sites that have been pretty good at getting close to the point of getting Background Information created by the tool BgInfo but none of them have actually solved my specific problem. Solutions currently out there include: Placing into the "All Users" folder This did not work for me, as our implementation does not contain an "All Users" folder in the "Users" folder for profiles. Reg-Hacking and HKCU or HKLM entry This is the worst of all the bad choices available.  I am experienced with Registry Editing and I still would not want or find a need to do this. Placing into the "Default" folder This is good going forward but what about those 20+ user profiles that are already logged in.  FYI, if your server has 20+ user account profiles in the "Users" directory you have larger problems than I am willing to assist with in this posting. The solution that worked for me, will be described below in pain-staki...

SQL - IsNullOrWhiteSpace Function

Just another SQL Code-snippet to check for NULL or whitespace value: -- ============================================= -- Author: John Wood -- Create date: 20151129 -- Description: Returns a boolean value -- ============================================= ALTER FUNCTION [Int].IsNullOrWhiteSpace ( -- Add the parameters for the function here @val sql_variant ) RETURNS bit AS BEGIN declare @ret bit if(SQL_VARIANT_PROPERTY(@val, 'BaseType') in ('varchar', 'nvarchar', 'char', 'nchar')) begin declare @char varchar = cast(@val as varchar) select @ret = iif(ltrim(rtrim(@char)) = '', 1, 0) end else begin -- Return the result of the function select @ret = iif( @val IS NULL, 1, 0 ) end return @ret END GO

Time Scalar Function

Everyone knows that you can use the Convert DML  to convert a DateTime data-type to a string evaluation for either split storage or display to an consuming interface. As most of us use the Date portion of a DateTime value for 90% of everything we are rendering the data to.  But what about that 10% where we either need to split render the Date & Time seperately.  After much review, we only have two quick and easy values to use and neither are really interchangeable. Option #1, with 2 forms: select convert(varchar(10), getdate(), 108) -- Produces: 13:53:15 select convert(varchar(15), getdate(), 114) -- Produces: 13:53:15:707 Now when using these forms of conversion, about 75% you have met the need for your requirement.  But lets say you need to use the Time string created for say a Filename ( sometext_[[TIME]].txt ), what do you do? Well the next code segment is what will be produced in order meet the FileName convention of special char...

Execute Functions...solo or Array

I have found myself multiple times having to "re-invent" this methodology to execute a single pass-through function or an array, pending on the situation.   For myself, and to share with others, I am posting this code-snippet for consumption. /**** @func - function() or [function(), function(),...] ****/ function ExecuteFunction( func ) { if ( typeof func !== 'undefined' && func != null ) { if ( typeof func === 'function' ) { func(); } else { if ( func instanceof Array ) { func.forEach( function ( fn ) { ExecuteFunction( fn ); } ); } } } } And yes you can have a nested array of functions.  If some crazy reason you wanted to do this: var func = [ function(){ //do something }, [ function () { ...

JSON/AJAX Helpers

Recently, had an implementation where I needed to implement ASP.Net Web API 2 and accompanied it with Javascript/JQuery AJAX communication.  In doing this i found myself making the same pattern calls with some varying value for certain properties for the AJAX data calls.  As such, i ended up building a few helper functions to simply the inclusion of these various minor quirks based on what was needed.  Below  you will find the various forms. 1: /********************************************************************* 2: @type - dataType, such as 'json', 'xml', 'script', 'jsonp' or 'html' 3: @contentType - string value, represents the HTML type of content 4: IE: 'application/json; charset=utf-8' 5: @url - API URL, such as 'api/tasks' should be constrainted to the 6: Web API Controller 7: @success - Function(data, status, xhr) handler, The logic to execute 8: on a 200 res...

Mustache Helper functions

Recently, implemented the Mustache Template processing framework.  As i worked through this implementation, i found myself creating the same JavaScript call and decided to simplify the overall execution into a single function signature and just call it multiple times. Root Mustache Call: 1: /********************************************************************* 2: @file - string value, Should be the HTML Template file. 3: @filterid - string value, Should the ID value of the Script tag inside 4: @file to obtain the HTML content. 5: @api - string value, Should be the URL to the API request 6: @dest - string value, Should be the destination selector, ideally ID 7: value of the control to load the Mustache Template into. 8: @func - (Nullable) Function value, If defined this will be executed 9: after the loading of the data into the Template. 10: --------------------------------------------------------------------...

Search Instance for a Stored Procedure usage

References: Peter Chamley MSSql Tips - Greg Robidoux: Listing SQL Server Object Dependencies Recently, I had the need to skim acrossed all the databases on a single instance.  In doing so I figured that the infamous 'sp_msforeachdb' undocumented stored procedure would be useful but was unsure on the methodology or pattern to implement.

SSMS 2012 - Template Modification

Ran into a situation where i needed to modify the standard templates that SSMS uses to Create Stored Procedures, Functions, and some other scripts. Problem: I did not know where to find these templates. First Solution: Goto Code Snippet Manager and modify snippets. Problem with this is that it requires you to create the XML snippet file and even then requires you to put it in, either the Public or Your Profile's, My Snippets folder. This does not solve the immediate problem as i would rather use the Context menu's New Stored Procedure (Function, etc). After-Thought: This solution though is great for things such as doing standard Select Statements for your organization.

SP2013: WebPart Attributes with Scope

Recently, I needed to find what Attributes i could use to either Enhance functionality or simply Lock down certain properties.  As such, I will start cataloging them in short with link-backs to MSDN. Seems to be a lack of a reliable Index, that i could find.  So as i find them I will be indexing them here, so at least i know its out there.

Cloud - Azure/SharePoint Development

Just created my Windows Azure free Trial. Wish me luck, going to see if i can really do the SharePoint Development i need with this, tentatively, Free Trial.

WebPart - InPlace Custom Property editing

Bear with the formatting, this Blog engine is old and getting on my nerves.  Time for an upgrade after 8 yrs :P Spent some time working on a WebPart implementation, where i wanted to edit the webpart in place instead of constantly clicking the glorious Edit WebPart for the WebPart object. So after some research, found a great article from  MATHIEU DESMARAIS  about the design patterns and logic flow. The main difference i had from his design, was i was prescribing the way the View/Edit Modes would be represented with the HTML syntax. I will not bore you with the details of getting up to this point, as there are numerous amounts of posts out there. I will although focus on the details of how i took Mathieu's implementation and modified for a Static set. Some of the pitfalls i had, probably because his was on demand control creation and mine is predefined. Notes to take mind of: This Implementation is for a SQL Connection Webpart. As such, you will notice...

Iterating through Workbook Tables

Nothing special just want to put a culmination of information available out there into one useful code-snippet 1: Dim wb As Workbook 2: Set wb = ActiveWorkbook 3: Dim ws As Worksheet 4: Dim lo As ListObject 5: Dim lc As ListColumn 6: Dim lr As ListRow 7: Dim frm As New frmListRanges 8: Dim txt As String 9: 10: For Each ws In wb.Worksheets 11: For Each lo In ws.ListObjects 12: txt = "" 13: For Each lr In lo.ListRows 14: txt = "{ " 15: For Each lc In lo.ListColumns 16: txt = txt &amp; " " &amp; CStr(lo.DataBodyRange.Cells(lr.Index, lc.Index).Value) &amp; "," 17: Next lc 18: Trim (txt) 19: If StrComp(Right(txt, 0), ",", vbTextCompare) Then 20: txt = Left(txt, Len(txt) - 1) 21: End If 22: txt = txt &amp; " }" 23: frm.AddNamedRange (...

Iterating through Excel Named Ranges

Simple code to iterate through named ranges 1: Dim fm as Form 2: Dim nm As Name 3: Dim val As Double 4: 5: For Each nm In ActiveWorkbook.Names 6: 'Check MacroType and Sheet References (in Name and Value) 7: 'If (nm.MacroType < 0 And InStr(1, nm.Name, "!", vbTextCompare) = 0 And InStr(1, nm.Value, "!", vbTextCompare) = 0) Then 8: 'If (nm.MacroType < 0 And InStr(1, nm.Name, "!", vbTextCompare) = 0) Then 9: If (nm.MacroType > 0) Then 10: 'Is not a standard XIXLMMacroType (1, 2, 3) 11: frm.AddNamedRange (nm.Name &amp; "( " &amp; CStr(nm.Value) &amp; " )") 12: 'frm.AddNamedRange (nm.Name &amp; "( " &amp; CStr(nm.MacroType) &amp; " )") 13: End If 14: Next nm 15: 16: frm.Show