Skip to content

Instantly share code, notes, and snippets.

@tparton42
tparton42 / SQLServerTestForConstraint.sql
Last active January 10, 2016 02:57
SQL Server method for determining if a specific table constraint exists.
DECLARE @constraintName varchar(200);
SET @constraintName = 'SomeConstraintName';
IF ( SELECT count(*) FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT'
AND OBJECT_NAME(object_id) = @constraintName) <> 0 BEGIN
PRINT 'FOUND Constraint: ' + @constraintName;
-- Perform some action...
END
ELSE
@tparton42
tparton42 / Java8-JodaDateTime-To-TimeZonedDateTime.java
Last active January 28, 2020 20:01
Java 8: Convert JODA DateTime to Java Time.ZonedDateTime
private java.time.ZonedDateTime convertJODADateTimeToJavaZonedDateTime(DateTime originDateTime, DateTimeZone originTimeZone) {
if (originDateTime == null || originTimeZone == zone) {
return null;
}
// Convert from JODA to Java 8 time
java.time.ZonedDateTime newDateTime = java.time.ZonedDateTime.ofInstant(
Instant.ofEpochMilli(originDateTime.getMillis()), java.time.ZoneId.of(zone.getID()));
return newDateTime;
@tparton42
tparton42 / keypress_position.js
Created December 6, 2013 04:32
Getting the cursor position of a keypress in JavaScript
$('alphaonly').keypress(function(e){
// Convert the character code to a string
var strIn = String.fromCharCode(e.charCode);
// The current cursor position is stored as: e.target.selectionStart
if(e.target.selectionStart == 0) {
// Setup our pattern, excluding anything other than a-zA-Z
var patt = /[a-zA-Z]/gi;
} else {
// Setup our pattern to allow alpha, spaces and dashes
@tparton42
tparton42 / ex_CF8_cfdocument_htmlBreak_error.cfm
Last active December 18, 2015 14:59
This gist demonstrates replacing multiple HTML BR tags in generated content that will be flushed to a PDF via CFDOCUMENT. This helps prevent a known error in ColdFusion 8 when multiple BRs encountered next to one another as well as when there are mixed formats of the BR tag.
<!--- Create a regular expression pattern to find BR tags --->
<cfset variables.patternHTMLBreak = "(<br[^>]*>\s*)" />
<!--- Replace all forms of the BR tag, To handle a wierd IO issue in CF8 using CFDoc with two consecutive BR's --->
<cfset variables.PDFPage = trim(reReplaceNoCase(variables.PDFPage, variables.patternHTMLBreak, "<br/>&nbsp;", "ALL")) />
@tparton42
tparton42 / ex_outputFromCFFunction_getFreeSpace.cfm
Created June 14, 2013 16:23
Example output from custom ColdFusion function, getFreeSpace()
<cfset variables.structTest = structNew()/>
<!--- Determine the current file path --->
<cfset variables.structTest.current_folder = expandPath("/") />
<!--- Lookup free space based on the passed in file path --->
<cfset variables.structTest.freeSpace = numberFormat(getFreeSpace(variables.structTest.current_folder)) />
<cfdump var="#variables.structTest#" label="structTest" />
@tparton42
tparton42 / ex_cfc_GetFreeSpace.cfm
Created June 14, 2013 16:21
Example of how to use the Java IO File class inside a ColdFusion Function to determine the amount of free space.
<cffunction name="getFreeSpace" displayname="getFreeSpace" description="Use Java.io.File to return amount of free space in target path" access="public" output="false" returntype="any">
<cfargument name="path" displayName="path" type="string" hint="File path" required="true" />
<!--- Create an instance of the Java IO File Class --->
<cfset var objFile = createObject("java", "java.io.File").init(arguments.path)/>
<!--- Return the amount of free space --->
<cfreturn objFile.getFreeSpace() />
</cffunction> <!--- End: checkFreeSpace() --->
@tparton42
tparton42 / ex_formatCurrencyInYUIDatatable.php
Last active December 18, 2015 12:29
YUI DataTable and Non-US Currency Formats - code sample for embedded JavaScript in PHP file.
<script language="javascript">
// Set your DataTable configuration, in your onLoad event
var myConfigs = {
currencyOptions : {
prefix: '<?php echo $this->currency->getSymbol($this->currency->getLocale()); ?>'
, decimalPlaces:2
, decimalSeparator:"."
, thousandsSeparator:","
}
};
@tparton42
tparton42 / example_cf_struct_mixed_case.cfm
Last active December 18, 2015 11:58
ColdFusion Example: Mixed case structure variable names
<!--- Create initial recordset --->
<cfset variables.structElementTest = structNew() />
<!--- Artist 1 --->
<cfset structElementTest.band1 = "MUSE" />
<cfset structElementTest["band1_website"] = "www.muse.mu" />
<!--- Artist 2 --->
<cfset structElementTest["band2"] = "Radiohead" />
<!--- Mixed case --->