Thursday, December 01, 2016

The following is the JavaScript code to display the ASCII character codes for each character of a given string.


function ascii(str) {
    return str
          .split('')
          .map(function (char) {
              return char + ": " + String(char.charCodeAt(0)) + "\n";
          })
          .reduce(function (current, previous) {
              return current + previous;
          });
}
 
alert(ascii("Hello World!")); 
 


Thursday, July 17, 2014

Scripting the display of dependencies for an object for SQL Server 2008 R2

Scripting the display of dependencies for an object for SQL Server 2008 R2 is hard to know how to do. I've done a little research, and found that there is no one way to do it, so the best way to do it is to load the different ways into a temp table and display them that way.

If you want to see how Microsoft does it in SQL Server Management Studio (SSMS):
mssqltips.com/tipimages/1294_sqlcode.txt


DECLARE @TableName nvarchar(50)
DECLARE @TableNameSchema nvarchar(50)
DECLARE @TableNameDb nvarchar(50)
SET @TableName = N'Product'
SET @TableNameSchema = N'dbo.' + @TableName
SET @TableNameDb = N'DbNameHere.dbo.' + @TableName

CREATE TABLE #dependents (obj_name nvarchar(255), obj_type nvarchar(255), obj_source nvarchar(30))
CREATE TABLE #msdependencies (oType nvarchar(255), oObjName nvarchar(255), oOwner nvarchar(255), oSequence nvarchar(255))

INSERT INTO #msdependencies (oType, oObjName, oOwner, oSequence)
    EXEC sp_MSdependencies @TableNameSchema, null, 1315327

INSERT INTO #dependents (obj_name, obj_type, obj_source)
    SELECT
        oOwner + '.' + oObjName AS obj_name,
        CASE oType
            WHEN 1 THEN 'function'
            WHEN 4 THEN 'view'
            WHEN 8 THEN 'table'
            WHEN 16 THEN 'stored procedure'
            ELSE '(other - ' + CAST(oType as varchar) + ')'
            END AS obj_type,
        'sp_MSDependencies' AS obj_source
    FROM #msdependencies

DROP TABLE #msdependencies

INSERT INTO #dependents (obj_name, obj_type, obj_source)
    SELECT DISTINCT
        OBJECT_SCHEMA_NAME(so.id) + '.' + so.name,
        CASE so.[type]
            WHEN 'TF' THEN 'table function'
            WHEN 'IF' THEN 'inline function'
            WHEN 'FN' THEN 'scalar function'
            WHEN 'V' THEN 'view'
            WHEN 'P' THEN 'stored procedure'
            ELSE '(other - ' + so.[type] + ')'
            END AS obj_type,
        'sysComments'
    FROM syscomments sc
    INNER JOIN sysobjects so ON sc.id = so.id
    WHERE charindex(@TableName, text) > 0

INSERT INTO #dependents (obj_name, obj_type, obj_source)
    SELECT DISTINCT
        SPECIFIC_SCHEMA + '.' + SPECIFIC_NAME,
        CASE ROUTINE_TYPE
            WHEN 'FUNCTION' THEN 'function'
            WHEN 'PROCEDURE' THEN 'stored procedure'
            ELSE '(other - ' + ROUTINE_TYPE + ')'
            END AS obj_type,
        'information_schema.routines'
    FROM information_schema.routines ISR
    WHERE CHARINDEX(@TableNameSchema, ISR.ROUTINE_DEFINITION) > 0

INSERT INTO #dependents (obj_name, obj_type)
    EXEC sp_depends @objname = @TableNameDb
UPDATE #dependents SET obj_source = 'sp_depends' WHERE obj_source IS NULL

-- Also, less useful, but could be added:
-- SELECT * FROM sys.dm_sql_referencing_entities (N'dbo.Product', N'OBJECT')
-- SELECT * FROM sys.dm_sql_referenced_entities (N'dbo.Product', N'OBJECT')

--SELECT DISTINCT obj_name, obj_type, obj_source FROM #dependents ORDER BY obj_name, obj_type, obj_source
SELECT
    obj_name,
    CASE WHEN MIN(obj_type) != 'function' THEN MIN(obj_type)
         ELSE MAX(obj_type) END AS obj_type,
    CASE obj_type
        WHEN 'inline function' THEN 'function'
        WHEN 'scalar function' THEN 'function'
        WHEN 'table function' THEN 'function'
        ELSE obj_type
        END AS obj_category
FROM #dependents
GROUP BY
    obj_name,
    CASE obj_type
        WHEN 'inline function' THEN 'function'
        WHEN 'scalar function' THEN 'function'
        WHEN 'table function' THEN 'function'
        ELSE obj_type END
ORDER BY obj_category, obj_name

DROP TABLE #dependents


Thanks to Greg Robidoux:
mssqltips.com/sqlservertip/1294/listing-sql-server-object-dependencies/

Thanks to Pinal Dave:
blog.sqlauthority.com/2010/02/04/sql-server-get-the-list-of-object-dependencies-sp_depends-and-information_schema-routines-and-sys-dm_sql_referencing_entities/

Wednesday, July 16, 2014

How to use select2 to create a multiple item selector

How to use select2 to create a multiple item selector

<link href="//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.css" rel="stylesheet" type="text/css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/3.5.0/select2.js" type="text/javascript"></script> 
 
<input type="hidden" id="e2"/>
<input type="button" value="Go" id="btnGO"/> 
 
<script type="text/javascript">
    container.Content.find("#e2").select2({
        createSearchChoice: function (term, data) {
            if ($(data).filter(function () {
                                return this.text.localeCompare(term) === 0;
                            }).length === 0) {
                return {
                    id: term,
                    text: term
                };
            }
        },
        multiple: true,
        width: '400px',
        data: [
            {id: "AL", text: "Alabama"},
            {id: "AK", text: "Alaska"},
            {id: "CA", text: "California"}
        ]
    });
 
    container.Content.find("#btnGO").click(function () {
        console.log("Val=" + container.Content.find('#e2').val());
    });
</script>
 

Tuesday, July 08, 2014

Adding TortoiseSVN commands to Visual Studio 2010

How to integrate TortoiseSVN (Subversion) into Visual Studio 2010

Tools --> External Tools... --> Add button

Title: Subversion Diff
Command: C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe
Arguments: /command:diff /path:"$(ItemPath)"

Others I added:
Subversion Check for Modifications
Arguments: /command:repostatus /path:"$(SolutionDir)" /notempfile

Subversion Update
/command:update /path:"$(SolutionDir)" /notempfile

Subversion Show Log
/command:log /path:"$(SolutionDir)" /notempfile

Subversion Revert
/command:log /path:"$(ItemDir)" /notempfile

Adding these external tools should make them show in your tools menu. You may need to add them to the menu (using Tools --> Customize) if you have deleted other Add-Ons.




Additionally, you can add items to the context menus in the Solution Explorer or to the tabs of files:
















You can do this by adding the items using the Tools --> Customize. You can add to the context menu of files using "Item" and add to the context menu of folders using "Folder":



This site really helped me do this:
http://tortoisesvn.net/visualstudio.html

This site also helped:
http://3dmpengines.tistory.com/652

Friday, June 13, 2014

CSharpPad.com for writing simple C# code online

http://csharppad.com/gist/2711c117666faa563f8e
http://csharppad.com/gist/333405964a24ee36a07d
http://csharppad.com/gist/84a787039938ef21f730

List digits = new List(new int[]{0,1,2,3,4,5,6,7,8,9});

DateTime birthDate = new DateTime(1973, 1, 29);

int index;
while(digits.Count > 0)
{
    index = digits.Count - 1;
    Console.WriteLine(digits[index]);
    digits.RemoveAt(index);
}

string userInput = Console.ReadLine();

Console.WriteLine("userInput={0}", userInput);
Console.WriteLine("birthDate={0}", birthDate);
Console.WriteLine("birthDate compare={0}", DateTime.Compare(birthDate, DateTime.Today));
Console.WriteLine("birthDate diff in seconds={0}", (DateTime.Today - birthDate).TotalSeconds);
Console.WriteLine("Birth Time={0}", DateTime.Parse("1973-01-29 09:30"));
Console.WriteLine("1 Trillion seconds old={0}", (DateTime.Parse("1973-01-29 09:30") + new TimeSpan(0, 0, 1000000000)));
Console.WriteLine("1.5 Trillion seconds old={0}", (DateTime.Parse("1973-01-29 09:30") + new TimeSpan(0, 0, 1500000000)));
Console.WriteLine("2 Trillion seconds old={0}", (DateTime.Parse("1973-01-29 09:30") + new TimeSpan(0, 0, 2000000000)));


Monday, March 03, 2014

Standard looking buttons with different colored backgrounds

<style type="text/css">
    #ContinueButton#CancelButton {
        backgroundlinear-gradient(to bottom, #FFF 0%, #EEE 9%, #E7E7E7 44%, #DDD 45%, #CCC 91%, #FFF 100%);
        background-webkit-gradient(linear, left top, left bottom, from(#F6F6F6), to(#DDD));
        -moz-appearancetextfield;
        border-radius3px;
        -webkit-border-radius2px;
        border1px #999 solid;
        padding2px 6px 3px;
    }
    #ContinueButton {
        backgroundlinear-gradient(to bottom, #FFF 0%, #ECF2EC 9%, #E5EBE5 44%, #DBF1DB 45%, #CAD0CA 91%, #FFF 100%);
        background-webkit-gradient(linear, left top, left bottom, from(#F4FAF4), to(#DBE1DB));
    }
    #CancelButton {
        backgroundlinear-gradient(to bottom, #FFF 0%, #F2ECEC 9%, #EBE5E5 44%, #F1DBDB 45%, #D0CACA 91%, #FFF 100%);
        background-webkit-gradient(linear, left top, left bottom, from(#FAF4F4), to(#E1DBDB));
    }
</style> 
 

Tuesday, January 14, 2014

How to format a date exactly as you want M/d/yyyy

I was having issues formatting a date in ASP.NET MVC3, and I tried everything to get my dates formatted M/d/yyyy. It turned out I needed to set the datatype to text. Before I did that, my dates had leading zeros, which is exactly what I did not want.
[DisplayName("Date Start")]
[DataType(DataType.Text)]
[DisplayFormat(DataFormatString = "{0:M/d/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DateStart { get; set; }
Remember to use @Html.EditorFor to get the formatting to come through. TextBoxFor will not look at display format, even if ApplyFormatInEditMode is true.

Monday, December 03, 2012

jQuery plugin: showKeyPressed

jQuery plugin: showKeyPressed

This plugin allows you to show the user the characters typed (temporarily) in a password field. The following would run on any password fields with the secure class.

Usage: $(":password.secure").showKeyPressed();

____________________

(function($){
    var ShowKeyPressedLib = {
        show: function (e, refNum, source)
        {
            e = e || window.event;
            var refId = "KP__" + refNum;
            var keycode = e.which;
            if (keycode == 32 ||
                keycode >= 41 && keycode <= 44 ||
                keycode >= 47 && keycode <= 111 ||
                keycode >= 146)
            {
                $(".keypressed").remove(); // Remove all previously shown first
                var coords = $(source).offset();
                var addPixels = 6 * source.value.length;
                $("<div></div>").attr("id", refId)
                                .css({ top: (coords.top - 20) + 'px', left: (coords.left + addPixels) + 'px' })
                                .addClass("keypressed")
                                .html(String.fromCharCode(keycode))
                                .appendTo("body");
            }
        },
        hide: function (refNum)
        {
            $("#KP__" + refNum).remove();
        },
        counter: 0
    }

    $.fn.showKeyPressed = function(){
     return $(this).bind('keypress', function(e){
            var refNum = ShowKeyPressedLib.counter++;
            ShowKeyPressedLib.show(e, refNum, this);
            setTimeout(function(){ ShowKeyPressedLib.hide(refNum) }, 999);
        });
    };
})(jQuery);

Thursday, June 28, 2012

Display the results of any query in Classic ASP

Display the results of any query in Classic ASP:

    If rs.EOF Then
        %>No record found<%
    Else
        Response.Write "
"
        Response.Write ""
        For i = 0 to rs.Fields.Count -1
            Response.Write ""
            Response.Write ""
            Response.Write ""
            Response.Write ""
        Next
        Response.Write "
Login Info
" & GetFieldName( rs.Fields(i).Name, fGeekMode ) & "" & rs.Fields(i).Value & " 
"

        %>
       

        Note: "Minutes Logged In" is not accurate if the session is not active, or if the session is inactive,

        and the user didn't logout (i.e., they closed their browswer instead of clicking Logout).

       

       

        Click Here to Kill This Login Session

            You would want to kill a session if the user is getting Read-Only access, and does

            not want to wait for their current session to time-out. Beware, this will log out the user if

            they are still using this session.
        <%
    End If

PRE
    If rs.EOF Then
        %>No record found<%
    Else
        Response.Write ""
        Response.Write ""
        For i = 0 to rs.Fields.Count -1
            Response.Write ""
            Response.Write ""
            Response.Write ""
            Response.Write ""
        Next
        Response.Write "
Login Info
" & GetFieldName( rs.Fields(i).Name, fGeekMode ) & "" & rs.Fields(i).Value & " 
" %>
Note: "Minutes Logged In" is not accurate if the session is not active, or if the session is inactive,
and the user didn't logout (i.e., they closed their browswer instead of clicking Logout).
 
 
Click Here to Kill This Login Session
    You would want to kill a session if the user is getting Read-Only access, and does
    not want to wait for their current session to time-out. Beware, this will log out the user if
    they are still using this session. <% End If
End

Thursday, February 16, 2012

My HTML is not updating during multiple AJAX calls

http://amolnw.wordpress.com/2009/10/08/ie6-offsettop-issue-and-solution/
http://stackoverflow.com/questions/1397478/forcing-a-dom-refresh-in-internet-explorer-after-javascript-dom-manipulation
function flushThis(id){
   var msie = 'Microsoft Internet Explorer';
   var tmp = 0;
   var elementOnShow = document.getElementById(id);
   if (navigator.appName == msie){
      tmp = elementOnShow.parentNode.offsetTop  +  'px';
   }else{
      tmp = elementOnShow.offsetTop;
   }
}


Element.addMethods({
  redraw: function(element){
    element = $(element);
    var n = document.createTextNode(' ');
    element.appendChild(n);
    (function(){n.parentNode.removeChild(n)}).defer();
    return element;
  }
});

You may also use some kind of addClass/removeClass combo. That would result into the same effect but without creating unused DOM elements. We use this method in qooxdoo and it works well.

Tuesday, January 24, 2012

Non-8dot3 format of a Windows path

I was trying to find out to get the non-8dot3 format of a Windows path to a file, and found this blog post that said at the bottom of the page:

1. start -> run: cmd
2. go to desired folder, i.e. cd "C:\Documents and Settings\All Users\Start Menu\Applications"
3. type command.com you'll get command prompt like C:\DOCUME~1\ALLUSE~1\STARTM~1\APPLIC~1>

Runner up: dir /x 

Monday, October 24, 2011

"Prepend" doesn't mean what you think it means

For years, I thought prepend text meant something similar to append text, accept it meant to add text to the beginning instead of the end of a word. Turns out that even though lots of other people seem to think the same thing, it actually means something else:
"Prepend" is a very obscure word which means literally to premeditate, as in, "He looked at her with malice prepended."
Source: http://cygwin.com/ml/cygwin/2001-07/msg01544.html Now I'm going to have to retrain my brain to start using another word. I'm not even sure what word works best here. Prefix text?

Thursday, February 17, 2011

Finally got a regular expression to validate a number between zero and eleven, allowing a leading zero. It allows only two digits to be entered maximum, and you can put one whitespace character before or after a single digit. Tested in Firefox 3.6 and IE 6.

It should be simple, but "simple" wasn't working in Firefox 3.6. I didn't bother testing other browsers with the one that didn't work in Firefox.

<asp:RegularExpressionValidator ControlToValidate="txtNumberOfMonths"
ErrorMessage="Months At: Please use a rounded number from 0 to 11"
ValidationExpression="^[\s]*((0?[0-9])|(1[0-1]))[\s]*$" runat="server"/>

The simple regex that didn't work was: "\s*(0?\d|1[01])\s*