Skip to content

Instantly share code, notes, and snippets.

@wave2
wave2 / LongRunningQueries.sql
Created August 30, 2014 21:08
Microsoft SQL 2012 Extended Event - Long Running Queries
--SQL 2012 Extended Event
CREATE EVENT SESSION [Long_Running_Queries] ON SERVER
ADD EVENT sqlserver.sql_statement_completed(
ACTION(package0.collect_cpu_cycle_time,package0.collect_system_time,sqlos.task_time,sqlserver.plan_handle,sqlserver.sql_text,sqlserver.username)
WHERE ([package0].[greater_than_int64]([duration],(2000000)) AND [sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name],N'INSERT_DB_NAME_HERE')))
ADD TARGET package0.ring_buffer(SET max_memory=(131072))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO
@wave2
wave2 / ZipFiles.vbs
Created June 27, 2014 17:52
VBScript to 7Zip files based on extension (Requires 7Zip)
OPTION EXPLICIT
DIM strExtensionsToZip,strFolder
DIM objFSO, WshShell, MaxAge, IncludeSubFolders
' Folder to zip files
strFolder = "c:\myfolder"
'Include subfolders?
includeSubfolders = true
' File extension to search for
strExtensionsToZip = "txt"
@wave2
wave2 / CWTDownloader.rb
Created June 10, 2014 19:30
Chat With The Designers Podcast Downloader
require 'rss'
require 'open-uri'
url = 'http://www.cwtd.org/cwtd.rss'
folder = '/mypodcasts/'
open(url) do |rss|
feed = RSS::Parser.parse(rss,false)
puts "Lets go get: #{feed.channel.title}"
feed.items.each do |item|
if !File.file?(folder + File.basename(URI.parse(item.enclosure.url).path))
@wave2
wave2 / RequestResponseTimings.rb
Created February 14, 2013 08:02
This script was used to parse all logs in a folder and extract an ID along with request / response timings (for reporting purposes). It remembers the previous line as the logs were multi line entries and the time was stored on the line above the ID (fun). Quick a dirty hack that allowed Excel to finish the job.
require 'date'
files = Dir.glob('//myserver/myfolder/*.log')
files.each do |file|
previousLine = ""
requests = Hash.new
responses = Hash.new
@wave2
wave2 / fn_HexToInt.sql
Created November 14, 2012 11:38
MSSQL 2000 - Convert varchar hex value to integer (need to remove 0x prefix before calling)
CREATE FUNCTION fn_HexToInt( @HexValue VARCHAR(20) )
RETURNS INTEGER
AS
BEGIN
DECLARE @iOutput INTEGER
DECLARE @sChar CHAR(1)
DECLARE @iChar INT
SET @iOutput = 0
@wave2
wave2 / ExtractFromBlob.sql
Created October 26, 2012 11:26
Extracting content from JMS messages stored within OpenMQ HA DB
--
-- Here is a dissected view of one method to get at the JMS payload stored within a Blob column.
--
-- 1. First look within the Blob to find the word MyIdentifier and obtain the start position:
--
-- DBMS_LOB.INSTR(MESSAGE, UTL_RAW.CAST_TO_RAW('MyIdentifier'), 1, 1)
--
-- 2. Next pass the position from INSTR to the SUBSTR function and return 120 characters from the word 'MyIdentifier'
-- (needs to be less than the RAW limit of 2000 but enough to contain the info you want)
--