Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Nadel bennadel

View GitHub Profile
@bennadel
bennadel / array-left.cfm
Created Sep 24, 2020
ArrayPop(), ArrayShift(), And ArraySliceSafe() In Lucee CFML 5.3.6.61
View array-left.cfm
<cfscript>
// NOTE: The concepts of "left" and "right" on an Array mirror the existing concepts
// for Strings. Meaning, String.left( 1 ) gets index [ 1 ] on said string. As such,
// Array.left( 1 ) will also get index [ 1 ] on said array.
dump( arrayLeft( [], 3 ) );
dump( arrayLeft( [ "a" ], 3 ) );
dump( arrayLeft( [ "a", "b", "c", "d", "e", "f" ], 3 ) );
@bennadel
bennadel / app.component.html
Created Sep 21, 2020
Playing Zoom Bingo In Angular 10.1.2
View app.component.html
<!-- BEGIN: Play Mode. -->
<div *ngIf="( mode === 'play' )" class="content">
<nav class="actions">
<a (click)="gotoMode( 'edit' )">Edit phrases</a>
</nav>
<app-bingo-board
[phrases]="phrases">
</app-bingo-board>
@bennadel
bennadel / test.cfm
Created Sep 19, 2020
Creating Pixel-Art Of Ruth Bader Ginsburg Using CSS Box-Shadow In Lucee CFML 5.3.6.61
View test.cfm
<cfscript>
colorData = getColorData( "./rbg-elle.jpg", 7 );
// ------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------- //
/**
* I extract a two-dimensional array of colors ( rows x columns ) from the given
* image, using the given block size (ie, how pixelated is are the colors). A struct
@bennadel
bennadel / derived.sql
Created Sep 16, 2020
Using Derived Tables To Generate "Stats" For An Outer Query JOIN In MySQL 5.6.49
View derived.sql
SELECT
( u.id ) AS user_id,
( u.name ) AS user_name,
-- Get activity logs stats for this user.
( activityLogStats.logCount ) AS log_count,
( activityLogStats.maxCreatedAt ) AS log_createdAt
FROM
user u
INNER JOIN
@bennadel
bennadel / test.cfm
Created Sep 15, 2020
Code Kata: Creating A Fluent, Closure-Based "Builder" API In Lucee CFML 5.3.6.61
View test.cfm
<cfscript>
echo(
urlBuilder()
.withProtocol( "//" )
.withHost( "www.bennadel.com/" )
.withPath( "/people" )
.withParam( "bff" )
.withParam( "filter", "cool beans" )
.build()
@bennadel
bennadel / group-by-ip.sql
Created Mar 21, 2016
Grouping The MySQL PROCESSLIST By IP Address To View Connection Counts
View group-by-ip.sql
SELECT
tmp.ipAddress,
-- Calculate how many connections are being held by this IP address.
COUNT( * ) AS ipAddressCount,
-- For each connection, the TIME column represent how many SECONDS it has been in
-- its current state. Running some aggregates will give us a fuzzy picture of what
-- the connections from this IP address is doing.
FLOOR( AVG( tmp.time ) ) AS timeAVG,
@bennadel
bennadel / create.cfm
Created Sep 13, 2020
Accessing Cookies With The Same Name In Lucee CFML 5.3.6.61
View create.cfm
<cfscript>
// With "benben" as lowercase.
cookie[ "benben" ] = {
value: "lowercase for general",
domain: ".local.invisionapp.com",
secure: true,
preserveCase: true,
expires: "never"
};
@bennadel
bennadel / create.cfm
Created Sep 13, 2020
The First Cookie Wins When Conflicting Cookie Names Are Used With Different Settings In Lucee CFML 5.3.6.61
View create.cfm
<cfscript>
param name="url.type" type="string" default="full";
if ( url.type == "full" ) {
cookie[ "benben" ] = {
value: "woot woot (for .projects.local.invisionapp.com)",
domain: ".projects.local.invisionapp.com",
secure: true,
@bennadel
bennadel / ProbeHelper.cfc
Created Sep 10, 2020
Deleting Temporary Upload Files In Our K8 Operational Readiness Probe In Lucee CFML 5.3.6.61
View ProbeHelper.cfc
component
output = false
hint = "I help log JVM system data for the health-probe."
{
// ... truncated code ...
// ---
// PUBLIC METHODS.
// ---
@bennadel
bennadel / snippet-1.cfm
Created Sep 7, 2020
The Elvis / Null Coalescing Operator Can Sometimes Replace The Safe Navigation Operator In Lucee CFML 5.3.6.61
View snippet-1.cfm
<cfscript>
echo( "Foo exists: " & variables.keyExists( "foo" ) );
echo( ". " );
echo( foo.bar.baz ?: "Null value fallback" );
</cfscript>
You can’t perform that action at this time.