Skip to content

Instantly share code, notes, and snippets.

@adamcameron
adamcameron / Base.cfc
Created August 17, 2021 20:38
More <cfexit> shenanigans
// Base.cfc
component {
writeOutput("Top of pseudo-constructor of #getMetadata(this).name#<br>")
exit;
writeOutput("Bottom of pseudo-constructor of #getMetadata(this).name#<br>")
function init() {
writeOutput("In #getMetadata(this).name#.#getFunctionCalledName()#<br>")
}
}
@adamcameron
adamcameron / CF.out
Last active August 17, 2021 19:49
Showing difference in behaviour between CF and Lucee
Top of test.cfm
Top of inc.cfm
Top of f
Bottom of inc.cfm
Bottom of test.cfm
curl -vs http://blog.adamcameron.me 1> /dev/null
* Trying 142.250.180.19:80...
* TCP_NODELAY set
* Connected to blog.adamcameron.me (142.250.180.19) port 80 (#0)
> GET / HTTP/1.1
> Host: blog.adamcameron.me
> User-Agent: curl/7.68.0
> Accept: */*
>
// C.cfc
component {
static {
final static.staticProperty = "value"
}
final this.instanceProperty = "value"
public string function f(final required string s) {
// /var/www/src/miscellaneous/importTest/Base.cfc There is a mapping `cfmInDocker` to /var/www/src
component {}
@adamcameron
adamcameron / scriptInFunction.cfm
Created June 30, 2021 09:32
This function is 101 lines long. That said, it doesn't matter how long it is, CFLint never complains
<cffunction name="scriptInTagFunction101Lines"><!--- <cffunction /> & <cfscrtipt /> tags set the baseline overhead @ 4 --->
<cfscript>
x = "Function is now 5 lines long";
x = "Function is now 6 lines long";
x = "Function is now 7 lines long";
x = "Function is now 8 lines long";
x = "Function is now 9 lines long";
x = "Function is now 10 lines long";
x = "Function is now 11 lines long";
x = "Function is now 12 lines long";
@adamcameron
adamcameron / script.cfm
Created June 30, 2021 09:28
This function is 100 lines long
<cfscript>
function scriptOnlyFunction100Lines() {// function(){} set the baseline overhead @ 2
x = "Function is now 3 lines long";
x = "Function is now 4 lines long";
x = "Function is now 5 lines long";
x = "Function is now 6 lines long";
x = "Function is now 7 lines long";
x = "Function is now 8 lines long";
x = "Function is now 9 lines long";
x = "Function is now 10 lines long";
@adamcameron
adamcameron / script.cfc
Last active June 29, 2021 13:04
tags file triggers the "method too long" warning; script one does not
<cfcomponent>
<cffunction name="f">
<cfscript>
x = 0;
x = 0;
x = 0;
x = 0;
x = 0;
x = 0;
@adamcameron
adamcameron / devin_array.cfm
Created June 25, 2021 16:30
Code for Devin showing how to prune null values from array of structs
<cffunction name="null"></cffunction>
<cfset apiData = [
{hasValue="some value", noValue=null()},
{none=null(), anothervalue="something here"},
{nowt=null(), nothing=null()}
]>
<cfset prunedApiData = duplicate(apiData)>
@adamcameron
adamcameron / poc.cfm
Created June 24, 2021 13:32
For James Moberg
<cfscript>
jsoup = CreateObject("java", "org.jsoup.Jsoup");
htmlDom = jsoup.parseBodyFragment('<a href="/" target="_blank" alt="home" data-test="1">Test</a>');
aHrefs = htmlDom.select('a');
for (aHref in aHrefs) {
iterator = aHref.attributes().iterator();
while (iterator.hasNext()) {