Skip to content

Instantly share code, notes, and snippets.

Ben Nadel bennadel

Block or report user

Report or block bennadel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bennadel
bennadel / test.cfm
Created Aug 21, 2019
Calculating A Consistent Cache-Friendly Expiration Date For Signed-URLs In Lucee 5.3.2.77
View test.cfm
<cfscript>
/**
* I return the "monthly" bucket for the given date (defaults to now). This helps with
* expiration dates on signed-URLs that will be consumed as the origin of a CDN pull-
* through.
*
* @input I am the date being used to calculate the bucket.
*/
public date function getMonthlyBucket( date input = now() )
@bennadel
bennadel / CachingCdnService.cfc
Created Aug 20, 2019
Performance Case Study: Caching Cryptographically Signed-URLs In Redis In Lucee 5.2.9.40
View CachingCdnService.cfc
component
accessors = true
output = false
hint = "I wrap the CDN Service and cache URL generation results."
{
// Define properties for dependency-injection (for Framework One).
property cdnService;
property jedisPool;
@bennadel
bennadel / snippet-1.cfm
Created Aug 17, 2019
Upgrading A Built-In Function To A First-Class Citizen In Lucee 5.3.2.77
View snippet-1.cfm
<cfscript>
values = values.map( trim );
</cfscript>
@bennadel
bennadel / MANIFEST.MF
Created Aug 16, 2019
Installing User Defined Functions (UDF) As An Extension For Built-In Functions (BIF) In Lucee 5.3.2.77
View MANIFEST.MF
Manifest-Version: 1.0
id: "b6304293-81fa-4bcf-a6aa4bf9bd673697"
version: "1.0.0.0"
name: "TruthyFalsy"
description: "Decision functions based on JavaScript's notion of Truthy and Falsy values."
category: "Decision Logic"
@bennadel
bennadel / test.cfm
Created Aug 14, 2019
Playing With The Zip Virtual File System (VFS) In Lucee 5.3.2.77
View test.cfm
<cfscript>
// Let's check to make sure the Zip virtual file system is enabled before we attempt
// to use it to create a Zip archive file.
// --
// NOTE: I have this here simply as an exploration of the VFS metadata function.
if ( ! getVfsMetaData( "zip" ).enabled ) {
echo( "Zip VFS not enabled." );
abort;
@bennadel
bennadel / Application.cfc
Created Aug 13, 2019
Unexpected Variable Assignment Using Function LocalMode Modern With Nested Closures In Lucee 5.3.2.77
View Application.cfc
component
output = false
hint = "I define the application settings and event handlers."
{
this.name = hash( getCurrentTemplatePath() );
// By using "modern" localmode, any unscoped variable assignment will be applied to
// current Function's local scope (never to the Variable's scope).
this.localmode = "modern";
@bennadel
bennadel / build.cfm
Last active Aug 10, 2019
Using Function LocalMode To Render Templates During Static Site Generation In Lucee 5.3.2.77
View build.cfm
<cfscript>
(() => {
stopwatch variable = "local.timer" {
var data = new DataReader().parseJson( fileRead( "./data.json" ) );
// Define the directory into which we will be building the static site.
var exportPath = "./export/";
@bennadel
bennadel / template.cfm
Created Aug 8, 2019
Using Function LocalMode Modern To More-Safely Render ColdFusion Templates In Lucee 5.3.2.77
View template.cfm
<cfscript>
// Assert the expected values.
// --
// NOTE: Using param in this case as an excuse to declare more variables.
param
name = "categorization"
type = "string"
default = "My Friends" // Will assign this value if not provided.
;
@bennadel
bennadel / test.cfm
Created Aug 6, 2019
Fixing ImageScaleToFit() Invalid Size Errors In Earlier Versions Of Lucee CFML
View test.cfm
<cfscript>
img = imageNew(
source = "",
width = 16,
height = 2000,
canvasColor = "ff3366"
);
width = imageGetWidth( img );
@bennadel
bennadel / test.cfm
Created Aug 5, 2019
CachedWithin Function Memoization Can Be Applied To Closures In Lucee 5.3.2.77
View test.cfm
<cfscript>
/**
* I return a random integer between 1 and the given max value (inclusive).
*
* @maxValue I am the optional max value of the range.
*/
public numeric function getRandomValue( numeric maxValue = 10 ) {
return( randRange( 1, maxValue ) );
You can’t perform that action at this time.