Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Life's a garden, dig it!

Ben Nadel bennadel

💭
Life's a garden, dig it!
View GitHub Profile
@bennadel
bennadel / test.cfm
Created Jun 29, 2022
Using An Array To Power Weighted Distributions In Lucee CFML 5.3.8.201
View test.cfm
<cfscript>
// Our build-function is going to return a generator function that produces values
// with the given weighted frequencies.
next = buildWeightedDistribution([
{ value: "a", percent: 10 },
{ value: "b", percent: 20 },
{ value: "c", percent: 70 }
]);
@bennadel
bennadel / Application.cfc
Created Jun 25, 2022
Namespacing Components With Per-Application Mappings In ColdFusion
View Application.cfc
component
output = false
hint = "I define the application settings and event handlers."
{
// Define the application settings.
this.name = "CompoundPathMappingTest";
this.applicationTimeout = createTimeSpan( 0, 1, 0, 0 );
// When referencing ColdFusion components, paths are delimited with "." instead of
@bennadel
bennadel / core-count.cfm
Created Jun 24, 2022
Looking At The Performance Overhead Of A Read-Only Lock In Lucee CFML 5.3.8.201
View core-count.cfm
<cfscript>
coreCount = createObject( "java", "java.lang.Runtime" )
.getRuntime()
.availableProcessors()
;
dump( coreCount );
</cfscript>
@bennadel
bennadel / array-out.txt
Last active Jun 23, 2022
Updating My Mental Model For Shared Array / Struct Iteration In ColdFusion
View array-out.txt
.... (truncated for post) ....
[INFO ] string 93: 99
[INFO ] string 90: 100
[INFO ] string 87: 100
[INFO ] string 94: 100
[INFO ] string 100: 99
[INFO ] string 99: 98
[INFO ] string 92: 100
[INFO ] string 97: 99
[INFO ] string 96: 99
@bennadel
bennadel / Flag.cfc
Created Jun 21, 2022
Considering A Stale-While-Revalidate Pattern To Caching In ColdFusion
View Flag.cfc
component
output = false
hint = "I provide access to a flag value which is refreshed asynchronously."
{
/**
* I initialize the flag value.
*/
public void function init() {
@bennadel
bennadel / test.cfm
Created Jun 20, 2022
Playing With Java Pattern's Named Capture Groups In ColdFusion
View test.cfm
<cfscript>
// The following pattern uses a VERBOSE Regular Expression flag to allow for comments
// and whitespace to make the pattern easier to read. In this case, we're attempting
// to extract parts of an email address using NAMED CAPTURE GROUPS.
pattern = "(?x)^
(?<user> [^+@]+ )
(
\+ (?<hash> [^@]+ )
)?
@bennadel
bennadel / test.cfm
Created Jun 19, 2022
Adding jreExtract() To Pluck Captured Groups Using Regular Expression In ColdFusion
View test.cfm
<cfscript>
jre = new JRegEx();
// The following pattern uses a VERBOSE Regular Expression flag to allow for comments
// and whitespace to make the pattern easier to read. This pattern attempts to capture
// the aspects of an HTTP URL.
pattern = "(?x)^
## Protocol extraction.
( https?:// | // )?
@bennadel
bennadel / Application.cfc
Created Jun 17, 2022
Ask Ben: Extending A ColdFusion Session On A Long-Lived Page
View Application.cfc
component
output = false
hint = "I define the application settings and event handlers."
{
// Configure application management.
this.name = "SessionHeartBeatDemo";
this.applicationTimeout = createTimeSpan( 1, 0, 0, 0 );
// Configure session management.
@bennadel
bennadel / snippet-1.cfc
Last active Jun 14, 2022
It's OK To Be Super Explicit In Your Data Access Method Names
View snippet-1.cfc
component {
public void function updateThing(
required numeric id,
string valueOne,
string valueTwo,
string valueThree
) {
```
@bennadel
bennadel / create-table.sql
Created Jun 10, 2022
A Relational Database Table To Prevent Double Form-Submissions In ColdFusion
View create-table.sql
CREATE TABLE `double_submission_token` (
`token` varchar(50) NOT NULL,
`expiresAt` datetime NOT NULL,
PRIMARY KEY (`token`),
KEY `IX_byExpiration` (`expiresAt`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;