Skip to content

Instantly share code, notes, and snippets.

<?php
class Tester {
function testUser(User $user): void {
$user->returnsUserInterface();
$user->returnsUser();
}
function testUserInterface(UserInterface $user): void {
@adamcameron
adamcameron / dediff.php
Created February 14, 2025 12:57
dediff.php
<?php
$fromLive = fopen('../var/tmp/from_live.csv', 'r');
$fromTest = fopen('../var/tmp/from_test.csv', 'r');
$fromLiveSame = fopen('../var/tmp/from_live_same.csv', 'w');
$fromTestSame = fopen('../var/tmp/from_test_same.csv', 'w');
$fromLiveDiff = fopen('../var/tmp/from_live_diff.csv', 'w');
$fromTestDiff = fopen('../var/tmp/from_test_diff.csv', 'w');
while (($lineLive = fgets($fromLive)) !== false) {
@adamcameron
adamcameron / gist:4d5d53f0a71f1bd7a0104e51129e92aa
Created February 1, 2025 12:34
Decorator interface with _call to handle method decoration
<?php
interface WrapperInterface {
}
class Wrapper implements WrapperInterface {
public function __construct(private readonly Wrapped $wrapped) {}
public function __call(string $name, array $arguments): mixed {
@adamcameron
adamcameron / Application.cfc
Last active May 20, 2024 12:38
Demonstrates integer types in CFML
component {}
@adamcameron
adamcameron / roundingVariants.cfm
Created December 28, 2023 14:29
Shows how various functions round in CFML. For comparing CF to Lucee
<cfscript>
numbers = [511.925,512.925,654.925,655.925]
functions = [
"decimalFormat(##x##)",
"right(dollarFormat(##x##), -1)",
'numberFormat(##x##, "9.00")'
]
</cfscript>
<cfoutput>
<table border="1">
@adamcameron
adamcameron / code.txt
Created September 6, 2023 08:23
php-fpm direct call code. TBC
export SCRIPT_NAME="/ping"
export SCRIPT_FILENAME="/ping"
export REQUEST_METHOD="GET"
cgi-fcgi -bind -connect localhost:9000
<cfscript>
data = [
{ org: "A0", path: [0,0,0] },
{ org: "A0->B1", path: [0,1,0] },
{ org: "A0->B1->C1", path: [0,1,1] },
{ org: "A0->B1->C2", path: [0,1,2] },
@adamcameron
adamcameron / query.cfm
Created April 12, 2023 14:34
Query using tag islands for param
<cfscript>
query name="getData" {
```
<cfsavecontent variable="sql">
SELECT * FROM test WHERE id =
</cfsavecontent>
```
writeOutput(sql)
```
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="101">
@adamcameron
adamcameron / mixed.cfm
Created April 12, 2023 14:08
mix of script and tags in one statement
<cfscript>
```<!---
make
hyper text
transfer
protocol
request
--->```
http
@adamcameron
adamcameron / daftery.cfm
Created April 12, 2023 13:39
Tag Islands par excellence
<cfset level = 0>
<cfscript>
level++
```
<cfoutput>Hello from level #level#<br></cfoutput>
<cfscript>
level++
```
<cfoutput>Hello from level #level#<br></cfoutput>
<cfscript>