Skip to content

Instantly share code, notes, and snippets.

@ryanvs
ryanvs / toTrioExponential.js
Created April 7, 2023 18:31
Formatting Exponentials in Javascript
// Formats the value as an exponential as a multiple of 3
// NOTE: The result is a string that is still a valid floating point number
function toTrioExponential(value, fixedDigits)
{
var mag = parseInt(Math.log(Math.abs(value) / Math.LN10);
var rem = mag % 3;
if (rem == 2)
++mag;
else if ((rem == 1) || (rem == -2))
--mag;
@ryanvs
ryanvs / Find SQL Changes.sql
Created May 19, 2021 17:33
Find SQL Changes
-- =====================================
-- ==== FIND CHANGES in SQL OBJECTS ====
-- =====================================
-- Optional: Find changes ig LOG Trace file
DECLARE @search_log bit = 1 -- 0=Do not search trace log; 1=Search trace log (WARNING: SLOW!!)
-- ============================================================================
-- Search sys.objects
SELECT TOP (10000)
<#
.SYNOPSIS
Returns the SID for the specified credentials
.DESCRIPTION
Returns the SID for a user name, using System.Security.Principal.NTAccount. If
no UserName is specified, then the current user name is used.
.NOTES
History:
@ryanvs
ryanvs / Create-Merge-Script.sql
Last active September 21, 2018 19:36
Create SQL Merge using XML
-- *************************************************************************************************************************
-- Name - Create-Merge-Script.sql
-- Description - Generates a SQL script to manage table data using XML with MERGE.
-- - Change variable @table to the desired output table name, and add @ignore_columns as necessary
-- - The output will be SQL lines that can be saved as a script
-- Author - Ryan van Slooten
----------------------------------------------------------------------------------------------------------------------------
-- Change Date Change By Ver. Changes
----------------------------------------------------------------------------------------------------------------------------
-- 2017-02-27 rjvs 1.0.4 Added comment block
@ryanvs
ryanvs / MW XML to EXEC SP.sql
Last active May 7, 2019 14:23
SQL script transform MES Middleware XML to EXEC PROC
-- Paste Middleware XML in @xml parameter value
DECLARE @xml xml = N'<request><object>QDC_sample</object><msgtype>getspec</msgtype><cmd>GetTableData</cmd><filter><start_time_utc>2017-11-16T12:02:51</start_time_utc><end_time_utc>2018-02-14T17:02:51.283857</end_time_utc><num_rows>180</num_rows><ent_id>32</ent_id><cols>&lt;columns&gt;&lt;column&gt;&lt;id&gt;Col1&lt;/id&gt;&lt;dataType&gt;Attributes&lt;/dataType&gt;&lt;label&gt;Shift&lt;/label&gt;&lt;attrId&gt;38&lt;/attrId&gt;&lt;operation&gt;Forming Machine&lt;/operation&gt;&lt;charId /&gt;&lt;field&gt;sa.attr_value&lt;/field&gt;&lt;QDCSpecification&gt;38946&lt;/QDCSpecification&gt;&lt;queryType&gt;sample_attr&lt;/queryType&gt;&lt;orderOrLocation&gt;valueNo&lt;/orderOrLocation&gt;&lt;valueNo /&gt;&lt;location /&gt;&lt;/column&gt;&lt;column&gt;&lt;id&gt;Col2&lt;/id&gt;&lt;dataType&gt;Attributes&lt;/dataType&gt;&lt;label&gt;Crew&lt;/label&gt;&lt;attrId&gt;35&lt;/attrId&gt;&lt;operation&gt;Forming Machine&lt;/operation&gt;&lt;charId /&gt;&lt;field&gt;sa.attr_value
@ryanvs
ryanvs / DropDownButtonBehavior.cs
Last active January 10, 2023 16:35
WPF Behavior for buttons to show a drop down context menu when the button is pressed. Uses Microsoft.Xaml.Behaviors (older code uses System.Windows.Interactivity) for Blend behavior. Possible solution to -- http://stackoverflow.com/questions/8958946/how-to-open-a-popup-menu-when-a-button-is-clicked
// This is free and unencumbered software released into the public domain.
// For more information, please refer to <http://unlicense.org/>
using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
// Newer code should use Microsoft.Xaml.Behaviors
using Microsoft.Xaml.Behaviors;
// Older code uses System.Windows.Interactivity