Skip to content

Instantly share code, notes, and snippets.

@davidsheardown
davidsheardown / xpath.sql
Last active November 8, 2023 09:45
XQuery/XPath in SQL Example Individual Elements and Rows
Given the XML down below, we can use a couple of queries to get individual elements (or attr) but also a list of other nodes/values:
;with cte
as
(
select
Id,
Filename,
@davidsheardown
davidsheardown / DecodeXML.vb
Created April 28, 2023 12:59
Decode or Encode XML where you are working with < or > sort of thing
Public Function DecodeXml(TextToDecode As String) As String
'Take text that has been encoded for XML and change it to normal text
Dim Res As String
Res = Replace(Replace(Replace(Replace(TextToDecode, "&quot;", """"), "&gt;", ">"), "&lt;", "<"), "&amp;", "&")
DecodeXml = Res
End Function
SELECT DATEDIFF(SECOND,'1970-01-01', GETUTCDATE()) AS 'UnixEpochTimestamp';
@davidsheardown
davidsheardown / MS-SQL Recover Suspect Database.sql
Created July 8, 2022 11:11
How to recover MS-SQL suspect database
SELECT DATABASEPROPERTYEX (N'SQL-Examples', N'STATUS') AS N'Status';
ALTER DATABASE [SQL-Examples] SET EMERGENCY;
GO
ALTER DATABASE [SQL-Examples] SET SINGLE_USER;
GO
DBCC CHECKDB (N'SQL-Examples', REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;
GO
-- Remember to set back to multi-user
@davidsheardown
davidsheardown / script.babel
Created April 15, 2022 16:36
Simple Draggable Canvas Circle - 39 Characters in ZIMjs
const frame = new Frame("fit", 800, 600, "#EEE", "#555");
frame.on("ready", ()=>{
zog("ready from ZIM Frame"); // logs in console (F12 - choose console)
// often need below - so consider it part of the template
const stage = frame.stage;
const stageW = frame.width;
const stageH = frame.height;
// REFERENCES for ZIM at https://zimjs.com
@davidsheardown
davidsheardown / how-to-build-a-responsive-bootstrap-lightbox-gallery.markdown
Created January 2, 2022 12:54
How to Build a Responsive Bootstrap Lightbox Gallery
@davidsheardown
davidsheardown / javascript-live.js
Created December 26, 2021 13:58
Javascript version of jQuery live (dynamic element) binding
function jslive(eventType, elementId, cb) {
document.addEventListener(eventType, function (event) {
if (event.target.id === elementId) {
cb.call(event.target, event);
}
});
}
// Params are: event type (click, mouseover etc), element to look for (id or class etc), callback function
jslive("click", ".my-class", function (event) {
@davidsheardown
davidsheardown / sp_add_image_to_SQL
Created November 2, 2021 09:49
Add image to SQL encoded it Base64
CREATE PROCEDURE [dbo].[sp_add_image_to_SQL]
@ImageId int,
@ImageFilePath nvarchar(255)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sql_string nvarchar(max) =
@davidsheardown
davidsheardown / ReturnISOdate.sql
Created October 5, 2020 13:39
Return ISO date the easy way!
/*
Replace "getdate()" with whatever date you need i.e. a field
*/
select convert(nvarchar(17),getdate(),127)+'00.00Z' as myISOdate
@davidsheardown
davidsheardown / jQuery DIV Toggle.html
Created July 30, 2020 15:46
Simple example of a div toggle (visible/in-visible) for quick ref
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<meta charset="utf-8">