Skip to content

Instantly share code, notes, and snippets.

@chrisdpeters
chrisdpeters / complex_implode.php
Last active November 20, 2021 06:15
Building long HTML class names
<?php
function build_banner_class(int $age) : array {
$banner_class = ['banner'];
if ($age >= 21) {
$banner_class[]= 'banner--boogie';
}
$banner_class = array_merge($banner_class, [
"color-$color",
@chrisdpeters
chrisdpeters / autolink.cfm
Last active March 23, 2020 00:51
Using Extra CFC Attributes for Documentation
@chrisdpeters
chrisdpeters / _articles.cfm
Last active March 17, 2020 02:15
Aggregating RSS Feeds with Delicious, Yahoo! Pipes, FeedBurner, and CFML
<!--- URL to RSS feed --->
<cfparam name="arguments.articlesRss" type="url">
<!--- URL to Delicious page --->
<cfparam name="arguments.articlesUrl" type="url">
<!--- Number of items to display from feed --->
<cfparam name="arguments.numToDisplay" type="numeric" default="10">
<!--- Note: we are breaking the convention of data access in the view here so that we can cache this partial --->
<cfset articles = articles(arguments.articlesRss)>
@chrisdpeters
chrisdpeters / index.js
Last active May 18, 2019 19:18
Setting up all kinds of domain redirects in S3 and CloudFront http://blog.chrisdpeters.com/domain-redirects-s3-and-cloudfront/
'use strict';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
let uri = request.uri ? request.uri : '/';
if (request.querystring) {
uri += '?' + request.querystring;
}
component extends="Model" {
function init() {
table(false);
// Set property labels for form fields and related error messages.
property(name="startDate", label="Start");
property(name="endDate", label="End");
//...
}
adapter: sftp
host:
port:
username:
password:
path:
additional:
- css/app.min.css
- javascripts/app.min.js
<form action="action.cfm" method="post">
<p>
<strong>Your Name</strong><br />
<input type="text" name="yourName" />
</p>
<p>
<strong>Gender</strong><br />
<input type="radio" name="gender" value="M" />
Male<br />
<input type="radio" name="gender" value="F" />
<cfoutput>
<!--- Instead of a lame check like `<cfif get("environment") eq "production">`,
we can instead do whatever the environment is calling for --->
<cfif
StructKeyExists(server.ENV, "GOOGLE_ANALYTICS_TRACKING_CODE")
and Len(server.ENV.GOOGLE_ANALYTICS_TRACKING_CODE)
>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
@chrisdpeters
chrisdpeters / show-output-filtered.html
Last active August 10, 2017 13:14
Never output anything to a browser without a formatting filter http://blog.chrisdpeters.com/formatting-filter/
<h1>
<a href="/posts/fart">&lt;script&gt;>alert('All your base are belong to us!');&lt;/script&gt;</a>
</h1>
<p class="post-meta">
&lt;script&gt;sendCookieInfoToAnotherServer = function() { /* ... */ }; sendCookieInfoToAnotherServer();&lt;/script&gt;
</p>
<h2>Banana Comments</h2>
@chrisdpeters
chrisdpeters / Address.cfc
Last active August 10, 2017 13:13
Progressively enhancing your CFWheels form with nested properties and jQuery http://blog.chrisdpeters.com/cfwheels-with-nested-properties-and-jquery/
component extends="Model" {
function init() {
belongsTo("contact");
}
}