TIL
My Thoughts, Opinions, Learnings and Discoveries
-
Setting a minimum request timeout in CFML
You rarely want to set a request timeout to a particular value - meaning that you want it to time out if it takes a certain amount of time. What you do want is to declare that a particular process might take at least some amount of time to complete. This is what
<cfsetting>
’s requestTimeout parameter should be - saying that it is ok if it takes at least this long. A recent example of where I needed this is with running some longer running processes as part of a suite of unit tests. The individual method we are testing might take 60 seconds to run for example - but the entire request might take several minutes - when that method is run as part of a normal request lifecycle then the 60 second request timeout is fine, but when running the unit tests it ends my tests early!So here is a method that you can use instead - that will update the request timeout to be the greater of the existing timeout or the new timeout. So it will only ever extend, never shorten.
Credit to Brian Ghidinelli.
comments -
Find duplicate IDs in your DOM
With a dynamic application with lots of shared templates it can sometimes be easy to use the same ID for two different elements on the same page. Sometimes this can manifest itself by your JS not working quite right but it isn’t apparent what the problem is. Here is a quick script you can paste into your console to report any duplicates.
Math Busche covered the same topic last year, head over there to see how he tackled the same thing.
comments -
CFML Value Array
Occasionally in the CFML Slack channel (and the IRC room before it) someone asks about a
commentsvalueArray()
function - what they mean is that they want something like the terribly namedvalueList()
that you can provide a query and a column and get a column slice which will return an array instead of a CFML list.valueArray()
exists on Lucee but for ACF you’re stuck implementing it for yourself. Here is a way to do that properly (it’s easy to do it naively wrong). -
kth Percentile in CFML
I recently needed to analyze some data in CFML where there was a wide range of values but some real outliers - latency numbers for example. So I ported this
commentskthPercentile()
function. You pass in the percentile and an array of numbers -kthPercentile(99, [...])
will give you the 99th percentile for example -kthPercentile(50, [...])
is the same as the median. -
CFML Fuzzy Time
A friend asked recently how I would go about writing a function to do fuzzy time - something that formats time in a casual way, the way you would talk about it in conversation - “just now”, “a few minutes ago”, “2 days ago”, etc. He wanted it to be customizable, where they could define the groupings used. This is what we came up with:
comments