Dumping Binary Content Field value into File

Here is a quick way to dump an image(binary) field value into a file:


DECLARE @SQL NVARCHAR(MAX)
SET @SQL = 'bcp "select [binaryfield] from [database]dbo.[table] where field = " queryout "c:\temp\output.jpg" -T -n -S ' + @@ServerName
EXEC xp_cmdshell @SQL

WHERE:
bcp => Bulk Copy Program (a utility that installs with SQL Server and can assist with large data transfers)

-T => Trusted Connection
-n => Native Type
-S => Server/Instance name

for more info on bcp type
bcp /? on command line

Detect IE10 using JavaScript

Here are possible ways to detect IE10 browser using Javascript:

Though the following aren’t perfect solution it could be a better start.

Method 1:


var ie10 = (navigator.userAgent.match(/Trident\/[6]/i));

Method 2:


var ie10 = (navigator.userAgent.match(/MSIE 10/i));

Method 3:



<!doctype>
<html>
<head>
<!--[if (gt IE 9)]><script type="text/javascript">window.ie10 = true;</script> <![endif]-->
</head>
<body>

<script type=”text/javascript”>
if(window.ie10)
document.write(‘IE 10 detected.’);
else
document.write(‘Browser is NOT IE10.’);
</script>
</body>
</html>

Extracting Text Between Words(Pattern) using Regex in JavaScript

Below are the ways to extract text between words in javascript:

Given the String “Name: John Berkins Address: LA, USA”


	var data = "Name: John Berkins Address: LA, USA";
	
	//using String.indexOf + String.substring
	var name = data.substring(data.indexOf("Name:")+6,data.indexOf("Address"));
	var addr = data.substring(data.indexOf("Address:") + 9);
	alert(name);
	alert(addr);	

	//using Regex (with the use of Non-Capturing Group(?:)
	var rname = data.match(/(?:Name:)(.+)(?:Address:)/)[1];
	var raddr = data.match(/(?:Address:)(.*)/)[1];
	alert(rname);
	alert(raddr);
	
	//Note: the regex  code above may not work if the data contains \n (newline character)
	//      this is because of the (.+) expression cannot disregards \n chars,
	//      the workaround is to change it to anoter expression or to remove the \n char before
	//		the extraction process: h
	//Example:
	//
	//data = data.replace(/\n/g,' ');
	//var rname = data.match(/(?:Name:)(.+)(?:Address:)/)[1];
	//var raddr = data.match(/(?:Address:)(.*)/)[1];