Skip to content

Instantly share code, notes, and snippets.

@bcswartz
bcswartz / gruntfile.js
Created November 25, 2017 14:14
Parses the index.html file to determine which JS and CSS files to concatenate
module.exports = function( grunt )
{
grunt.initConfig({
//Create jsResources and cssResources configuration properties
jsResources: [],
cssResources: [],
clean: {
build: {
dot: true,
@bcswartz
bcswartz / gruntfile.js
Created November 25, 2017 14:04
Grunt file with the grunt-open plugin for opening certain websites
module.exports = function( grunt )
{
grunt.initConfig({
open: {
joyoftech: {
path: 'http://www.geekculture.com/joyoftech/',
app: 'Chrome'
},
dilbert: {
path: 'http://www.dilbert.com/',
@bcswartz
bcswartz / converterUtil.cfc
Created November 24, 2017 16:27
Simple ColdFusion method for converting letters to number in American phone numbers
public string function convertPhoneLetters(required string oldNumber) {
var newNumber= arguments.oldNumber;
var regArray= [
"[A-Ca-c]",
"[D-Fd-f]",
"[G-Ig-i]",
"[J-Lj-l]",
"[M-Om-o]",
"[P-Sp-s]",
"[T-Vt-v]",
@bcswartz
bcswartz / muraSiteLoginWithCAS.cfm
Created November 24, 2017 14:41
Second of 2 code blocks describing how to link JASIG CAS authentication with the Mura CMS
<cfif StructKeyExists(session,"userId") EQ false>
<cfif StructKeyExists(session,"NetId")>
<!---Look for a user account with the user identifier returned by CAS--->
<cfquery name="qry" datasource="{My Mura Datasource}">
select userId, type
from tUsers
where username= <cfqueryparam value="#session.NetId#" cfsqltype="cf_sql_varchar" />
</cfquery>
<cfif qry.recordcount EQ 1>
@bcswartz
bcswartz / muraAdminLoginWithCAS.cfm
Created November 24, 2017 14:41
First of 2 code blocks describing how to link JASIG CAS authentication with the Mura CMS
<cfif cgi.script_name EQ "/admin/index.cfm" and cgi.query_string EQ "">
<cfif IsDefined('session.mura') and session.mura.userId EQ "">
<cfif StructKeyExists(session,"NetId")>
<!---Look for an admin (type 2) account with the user identifier returned by CAS--->
<cfquery name="qry" datasource="{My Mura Datasource}">
select userId
from tUsers
where username= <cfqueryparam value="#session.NetId#" cfsqltype="cf_sql_varchar" />
and type= <cfqueryparam value="2" cfsqltype="cf_sql_numeric" />
</cfquery>
@bcswartz
bcswartz / modelGlueFormDataParser.cfc
Created November 24, 2017 13:54
A method for performing processing on form field values defined in a list
<cffunction name="collectFormDataAndTrim" access="public" returntype="void" output="false" hint="I collect the form values">
<cfargument name="event" type="any">
<cfset var loc= StructNew()>
<cfset loc.propertyList= arguments.event.getArgument("propertyList","")>
<cfif loc.propertyList EQ "">
<cfset loc.propertyList= arguments.event.getValue("fieldnames")>
</cfif>
<cfset loc.form= StructNew()>
@bcswartz
bcswartz / customValidatorExample.js
Created November 23, 2017 20:23
Example of a custom validation method for the jQuery Validation plugin to ensure one date is greater than the other
jQuery.validator.addMethod("dateComparison",function(value,element) {
var result= true;
if($("#startDateOptionLater:checked").length== 1)
{
var dateArray= $("#startDate").val().split("/");
var startDateObj= new Date(dateArray[2],(dateArray[0]-1),dateArray[1],0,0,0,0);
}
else
{
var exactDate= new Date();
@bcswartz
bcswartz / modelGlue.xml
Created November 23, 2017 20:11
CSRF protection example in a ModelGlue-based ColdFusion app, part 2
<event-types>
<event-type name="permitted">
<before>
<broadcasts>
<message name="checkAuthorization" />
<message name="secureTransmissionURL" />
</broadcasts>
<results>
...<!--Whatever you do if user is not authenticated yet-->
@bcswartz
bcswartz / mgAuth.cfc
Created November 23, 2017 20:10
CSRF protection example in a ModelGlue-based ColdFusion app, part 1
<cffunction name="secureTransmissionURL" access="public" returntype="void" output="false">
<cfargument name="event" type="any">
<cfif arguments.event.valueExists("token") EQ false>
<cfset session.token= CreateUUID()>
</cfif>
<cfset arguments.event.setValue("secureMyself","index.cfm?token=" & Hash(session.token,"SHA-256") & "&" & arguments.event.getValue("eventValue") & "=")>
</cffunction>
<cffunction name="validateTransmissionURL" access="public" returntype="void" output="false">
<cfargument name="event" type="any">
@bcswartz
bcswartz / layoutWithImport.xml
Created November 23, 2017 20:03
Simple example of importing a layout XML definition in Android in early days
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/pageColor">
<include android:id="@+id/header" layout="@layout/main_header" />
<ListView android:id="@+id/android:list"