Skip to content

Instantly share code, notes, and snippets.

View craibuc's full-sized avatar

Craig Buchanan craibuc

View GitHub Profile
@craibuc
craibuc / gist:5813835
Created June 19, 2013 12:15
List of Oracle sessions for current user.
SELECT SID, USERNAME, SCHEMANAME, OSUSER, MACHINE, TERMINAL, PROGRAM, TYPE, MODULE, ACTION, LOGON_TIME
FROM V$SESSION
-- current user
WHERE USERNAME = USER
@craibuc
craibuc / epichospitals.xsl
Last active December 19, 2015 14:39
Convert HTML table at http://epic.usergroup.healthitsocial.com/page/epic-hospitals to XML using a YQL query with this XSLT.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="//table[@width='623']">
<locations>
<xsl:apply-templates select="descendant::tr" />
</locations>
</xsl:template>
<xsl:template match="//tr">
<location>
<xsl:attribute name='name'>
@craibuc
craibuc / Base10ToBaseN
Last active December 30, 2015 10:19
Convert a base-10 number to a base-N number.
Function (Numbervar base_ten, Numbervar base_n)
// quotient
Local Numbervar q;
// remainder
Local Numbervar r;
// converted values
Local Numbervar Array slots;
do (
@craibuc
craibuc / FractionToDecimal
Created December 5, 2013 22:50
Converts a fractional value in the format of Numerator/Denominator or Whole + Numerator/Denominator to a decimal value.
//Assumes values in the following formats:
//99 - integer value
//99.9 - decimal value
//N/D - numerator/denominator
//M N/D - whole + numerator/denominator
Function (Stringvar value)
Local Numbervar whole := 0;
Local Stringvar fraction;
@craibuc
craibuc / sql-dates
Last active December 30, 2015 10:19
Useful, dynamically-generated dates for SQL Server.
--[1st day of current month]: use the GetDate(), Month(), and Year() functions to determine the current month and year. Build a string using these values in MM/01/YYYY format. Convert the String to DateTime.
CAST( CAST( Month(GetDate()) AS Char(2) ) + '/01/' + CAST( Year(GetDate()) AS Char(4)) AS DateTime)
--[Last day of current month]: add a month to [1st day of current month], then subtract a day.
DateAdd(m, 1, CAST( CAST( Month(GetDate()) AS Char(2) ) + '/01/' + CAST( Year(GetDate()) AS Char(4)) AS DateTime)) -1
--[1st day of prior month]: subtract a month from [1st day of current month].
DateAdd(m, -1, CAST( CAST( Month(GetDate()) AS Char(2) ) + '/01/' + CAST( Year(GetDate()) AS Char(4)) AS DateTime))
--[Last day of prior month]: subtract a day from [1st day of current month].
@craibuc
craibuc / ArrayContains
Last active December 30, 2015 10:19
Determines if a string value is contained in an array of strings in Crystal Reports.
Function (Stringvar Array Items, Stringvar Value)
Numbervar i;
Booleanvar flag:=False;
If Ubound(Items)>0 Then
For i := 1 To Ubound(Items) Do (
If Items[i]=Value Then (
flag:=True;
Exit For
@craibuc
craibuc / greater
Last active December 30, 2015 10:28
A SQL Server, scalar-value function that returns the greater of two dates.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/*----------------------------------------------------------------------------------------------------
Author: Craig Buchanan
Date: 2/6/2006
Description: Returns the greater of two dates
Parameters:
@Date1 - datetime to be compared
@craibuc
craibuc / lesser
Last active December 30, 2015 10:28
A SQL Server, scalar-value function that returns the lesser of two dates.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/*----------------------------------------------------------------------------------------------------
Author: Craig Buchanan
Date: 2/6/2006
Description: Returns the lesser of two dates
Parameters:
@Date1 - datetime to be compared
@craibuc
craibuc / copy-infoobject
Created December 5, 2013 23:10
Use the BusinessObjects SDK to copy files between two InfoObjects. This is useful when the source is a ‘template’ object (e.g. Crystal Report) that will be deployed to one or more targets.
'get the source and target infoObjects
Dim sourceInfoObject As InfoObject = infoStore.Query("SELECT SI_ID, SI_NAME, SI_FILES FROM CI_INFOOBJECTS WHERE SI_ID=" & sourceId)(1)
Dim targetInfoObject As InfoObject = infoStore.Query("SELECT SI_ID, SI_NAME, SI_FILES FROM CI_INFOOBJECTS WHERE SI_ID=" & targetId)(1)
'get the desired file from FRS
Dim sourceFile As File = sourceInfoObject.Files(1)
'create buffer and size appropriately
Dim buffer As Byte() = new Byte(sourceFile.Size) {}
# remove for asciidoctor (Ruby) implementation
# require 'asciidoctor'
# require 'erb'
#
# Purpose: automatically run scripts when any .ADOC file changes; creates OS X (Mavericks) notifications
# Requires:
# - Ruby (https://www.ruby-lang.org)
# - guard (https://github.com/guard/)
# - guard-shell (https://github.com/hawx/guard-shell)