Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Peters chrisdpeters

View GitHub Profile
@chrisdpeters
chrisdpeters / index.js
Last active May 18, 2019
Setting up all kinds of domain redirects in S3 and CloudFront http://blog.chrisdpeters.com/domain-redirects-s3-and-cloudfront/
View index.js
'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;
}
@chrisdpeters
chrisdpeters / _call_to_action_view.html.erb
Last active Jul 17, 2017
Alchemy CMS: great for websites integrated with Ruby on Rails http://blog.chrisdpeters.com/alchemy-cms/
View _call_to_action_view.html.erb
<%- cache(element) do -%>
<%= element_view_for(element) do |el| -%>
<div class="cta">
<h3 class="cta-heading">
<%= el.render :headline %>
</h3>
<%= el.render :description %>
<div class="cta-actions">
@chrisdpeters
chrisdpeters / Address.cfc
Last active Aug 10, 2017
Progressively enhancing your CFWheels form with nested properties and jQuery http://blog.chrisdpeters.com/cfwheels-with-nested-properties-and-jquery/
View Address.cfc
component extends="Model" {
function init() {
belongsTo("contact");
}
}
@chrisdpeters
chrisdpeters / show-output-filtered.html
Last active Aug 10, 2017
Never output anything to a browser without a formatting filter http://blog.chrisdpeters.com/formatting-filter/
View show-output-filtered.html
<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>
View InvoiceSearchForm-init.cfc
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");
//...
}
@chrisdpeters
chrisdpeters / contact.rb
Last active Mar 2, 2016
Users, Contacts, and Friendships
View contact.rb
class Contact < ActiveRecord::Base
has_many :users
has_many :friendships
end
@chrisdpeters
chrisdpeters / TablelessModel.cfc
Last active Dec 16, 2015
Hiding complex model relationships behind form objects in CFWheels
View TablelessModel.cfc
<cfcomponent extends="Model">
<cffunction name="init">
<cfset table(false)>
</cffunction>
</cfcomponent>
@chrisdpeters
chrisdpeters / Issue.cfc
Last active Aug 25, 2015
CFWheels nestedProperties sortProperty fix
View Issue.cfc
<cfcomponent extends="Model" output="false">
<cffunction name="init" output="false">
<cfscript>
hasMany(name="attemptedSolutions", shortcut="solution", dependent="delete");
nestedProperties(association="attemptedSolutions", allowDelete=true, sortProperty="sortOrder");
beforeValidation("$adjustAttemptedSolutionSortOrders");
</cfscript>
</cffunction>
<cffunction name="$adjustAttemptedSolutionSortOrders" access="private" hint="Adjusts array of attempted solutions before save happens so there aren't any null entries." output="false">
View _google_analytics.cfm
<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(){
View _bios.scss
$bio-breakpoint: 500px;
.bio {
@media screen and (min-width: $bio-breakpoint) {
float: left;
width: 50%;
}
}
.bio-photo {
You can’t perform that action at this time.