Mar 31 2020

jQuery – set option by value

$('.selDiv option[value="SEL1"]').prop('selected', true)

source: https://stackoverflow.com/questions/314636/how-do-you-select-a-particular-option-in-a-select-element-in-jquery


Mar 17 2020

ASP: web.config redirect to another domain with no rules – v2


<rewrite>
  <rules>
    <rule name="redirect" enabled="true">
      <match url="(.*)" />
      <action type="Redirect" url="http://www.example.com/" appendQueryString="true" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

Mar 1 2020

JavaScript: Difference between two dates in days


var date_diff_indays = function(date1, date2) {
dt1 = new Date(date1);
dt2 = new Date(date2);
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()) ) /(1000 * 60 * 60 * 24));
}

SOURCE: https://www.w3resource.com/javascript-exercises/javascript-date-exercise-8.php


Nov 27 2019

jQuery – replace one element with another

$("#element_1").replaceWith("<div id="element_2">123<div>"); 

Nov 4 2019

MSSQL – aggregate function on ntext – group by

 SELECT min(CONVERT(NVARCHAR(max), my_ntext_filed)) AS my_agg_ntext_filed FROM tbl_test GROUP BY id  

Oct 31 2019

ASP: web.config redirect


<system.webServer>

<httpRedirect enabled="true" destination="http://www.google.com/" />

</system.webServer>

Oct 14 2019

JavaScript – string to boolean

var isTrueSet = (myValue == 'true');

Oct 4 2019

Classic ASP – Getting ID of new record after insert


Dim loConn, lsSQL, loRs
Set loConn = CreateObject("ADODB.Connection")

' Open a connection to the database
loConn.Open(application("DSN=myDSN;UID=something;PWD=Something;"))

' Insert a new record into the table
lsSQL = "SET NOCOUNT ON;" &_
        "INSERT INTO tbl_test (naziv) VALUES ('pero');" &_
        "SELECT @@IDENTITY AS NewID;"

' Execute the SQL statement
Set loRs = loConn.Execute(lsSQL)

' Get the inserted ID
myNewID= loRs.Fields("NewID").value

response.write myNewID

' Close the connection
loConn.Close()
Set loConn = Nothing

The SET NOCOUNT ON suppresses messages like “1 Row(s) affected” being sent back. These messages are sent back every time SQL statement is executed.

source: http://www.kamath.com/tutorials/tut007_identity.asp


Sep 25 2019

Classic ASP – URLDecode

FUNCTION URLDecode(str)
'// This function:
'// - decodes any utf-8 encoded characters into unicode characters eg. (%C3%A5 = å)
'// - replaces any plus sign separators with a space character
'//
'// IMPORTANT:
'// Your webpage must use the UTF-8 character set. Easiest method is to use this META tag:
'//
'//
Dim objScript
Set objScript = Server.CreateObject("ScriptControl")
objScript.Language = "JavaScript"
URLDecode = objScript.Eval("decodeURIComponent(""" &amp; str &amp; """.replace(/\+/g,"" ""))")
Set objScript = NOTHING
END FUNCTION

 

source: https://gist.github.com/gwobcke/2773779


Sep 20 2019

MSSQL – resource statistics

SELECT *
FROM sys.dm_db_resource_stats
order by end_time desc;