Skip to content

Instantly share code, notes, and snippets.

View paulklinkenberg's full-sized avatar

Paul Klinkenberg paulklinkenberg

View GitHub Profile
@paulklinkenberg
paulklinkenberg / CertificateUtil.cfc
Created January 31, 2022 22:32
Lucee/CFML utility component for reading and storing certificates to a JKS Java keystore
component {
public function addCertToStore(required string certBase64, required string keyStorePath, string keyStorePassword="insecure") {
if (not fileExists(keyStorePath)) {
throw(message='Path of [keyStorePath] does not exist!', detail="#keyStorePath#");
}
local.ks = getKeyStore(keyStorePath, keyStorePassword);
local.tempPath = getTempDirectory() & createUUID() & ".tmp";
fileWrite(local.tempPath, "-----BEGIN CERTIFICATE-----#chr(10)##certBase64##chr(10)#-----END CERTIFICATE-----");
@paulklinkenberg
paulklinkenberg / jvm-memory-details.cfm
Created January 19, 2022 15:31
Lucee / CFML code to display the available memory, allocated memory, and max memory in html
<cfoutput>
#getMem()#
</cfoutput>
<cfscript>
function getMem(){
var runtime = createObject('java', 'java.lang.Runtime').getRuntime();
var maxMemory = runtime.maxMemory();
var allocatedMemory = runtime.totalMemory();
var freeMemory = runtime.freeMemory();
@paulklinkenberg
paulklinkenberg / Web.config
Last active December 10, 2019 23:52
IIS rewrite config for Preside CMS
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<httpErrors errorMode="Detailed" />
<rewrite>
<rules>
@paulklinkenberg
paulklinkenberg / checkCase.cfm
Created February 24, 2016 20:53
CFML script to find broken links in cfml and html files, case-sensitive! Very useful when switching from Windows to Linux.
<cfset maxErrors = 500 />
<cfset root = expandPath('/') />
<cfset files = directoryList(root, true, "path", "*.cfm|*.cfc|*.html|*.htm") />
<cfset currErrors = 0 />
<cfoutput>
<p>#arraylen(files)# cfm/cfc/html/htm files found</p>
</cfoutput>
<table border="1">
<thead>
@paulklinkenberg
paulklinkenberg / barcode4j.cfm
Created February 15, 2016 14:20
barcode4j example in CFML / Lucee
<cfset jarsPath = expandPath('/java/barcode4j/') />
<!--- Path where the necessary jar files are located (downloadable from https://www.dropbox.com/s/skl9fwky2n7mnjr/java-files-barcode4j.zip?dl=0) --->
<cfset libraryList = arrayToList( directoryList(jarsPath, false, 'array', '*.jar') ) />
<cfset configBuilder = createObject('java', 'org.apache.avalon.framework.configuration.DefaultConfigurationBuilder', libraryList) />
<cfset barcodeUtil = createObject('java', 'org.krysalis.barcode4j.BarcodeUtil', libraryList) />
<cfset grayImageType = createObject('java', 'java.awt.image.BufferedImage').TYPE_BYTE_GRAY />
<!--- create custom config. See http://barcode4j.sourceforge.net/2.1/symbol-ean-13.html --->
<cfset configXml = '<barcode>
<!-- SQLDate:[2013-06-28 13:48:50 ########################## prodid not received ########################## -->
<!-- Exception in doEndTag() in tag com.openmarket.gator.jsp.assetset.Getattributevalues in page &#39;Staatsloterij/Content_C/renderBonProduct&#39; in element &#39;Content_C/renderBonProduct&#39; errno: 0 errdetail1: Exception in doEndTag() in tag com.openmarket.gator.jsp.assetset.Setasset in page &#39;Staatsloterij/Content_C/renderBonProduct&#39; in element &#39;Content_C/renderBonProduct&#39; errno: -500 errdetail: 0 com.openmarket.basic.interfaces.AssetException: Invalid type specified: Content_C errdetail: 0 java.lang.Exception: object lookup for myBon_Content failed! --></div><!-- End content -->
@paulklinkenberg
paulklinkenberg / gist:839431
Created February 22, 2011 21:26
Get random winner
<cfhttp url="http://blog.bittersweetryan.com/2011/02/post-some-cf-code-on-github-and-win.html" />
<cfset possibleWinners = {} />
<cfset commentsHtmlArr = rematch("<dt class='comment-author.*?</dd>", rereplace(cfhttp.filecontent, '[\r\n]+', '', 'all')) />
<cfset gistURLRegex = "https://gist\.github\.com/[0-9]+" />
<cfloop from="1" to="#arrayLen(commentsHtmlArr)#" index="arrIndex">
<cfset currHtml = commentsHtmlArr[arrIndex] />
<cfif refindNoCase(gistURLRegex, currHtml)>
<cfset gistURL = reMatchNoCase(gistURLRegex, currHtml) />
<cfset gistURL = gistURL[1] />