Skip to content

Instantly share code, notes, and snippets.

@bcswartz
bcswartz / simpleLayout.xml
Created November 23, 2017 19:38
Example of a simple Android view layout from the very early days of Android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/exampleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Push the button"
android:background="#ffff00"
@bcswartz
bcswartz / ColdSpring.xml
Created November 23, 2017 16:30
Configure environment-specific settings with ModelGlue and ColdSpring, part 2
<bean id="appConfig" class="myApp.model.csBeans.appConfig">
<constructor-arg name="universalSettings">
<map>
<entry key="ds"><value>myDatasource</value></entry>
<entry key="appName"><value>myApp</value></entry>
<entry key="approot"><value>/myApp</value></entry>
</map>
</constructor-arg>
<constructor-arg name="localSettings">
<map>
@bcswartz
bcswartz / appConfig.cfc
Created November 23, 2017 16:29
Configure environment-specific settings with ModelGlue and ColdSpring, part 1
<cfcomponent displayname="appConfig" hint="I provide the configuration settings for the application dependent on where the application is running.">
<cffunction name="init" access="public" returntype="any" hint="I accept all of the possible setting configurations">
<cfargument name="universalSettings" type="struct" required="true" hint="A struct of all of the configuration settings that are true regardless of environment" />
<cfargument name="localSettings" type="struct" required="true" hint="A struct of all of the configuration settings for the local environment" />
<cfargument name="remoteSettings" type="struct" required="true" hint="A struct of all of the configuration settings for the remote environment" />
<cfset var loc= StructNew()>
<cfset variables.config= StructNew()>
<cfloop collection="#arguments.universalSettings#" item="loc.ukey">
<cfset variables.config[loc.ukey]= arguments.universalSettings[loc.ukey]>
@bcswartz
bcswartz / validUserSubmittedDate.js
Created November 23, 2017 14:22
A means to check if the date a user provided is invalid (like "April 31")
//Since JavaScripts counts months starting from 0 (January is 0),
//subtract 1 from the month integer submitted by the user
var formattedMonth = userSubmittedMonth - 1;
var testDate = new Date( userSubmittedYear,formattedMonth,userSubmittedDay,0,0,0,0) ;
if (
testDate.getFullYear() != userSubmittedYear
|| testDate.getMonth() != formattedMonth
|| testDate.getDate() != userSubmittedDay
@bcswartz
bcswartz / itemsDecorator.cfm
Created November 22, 2017 15:54
Transfer decorator example, part 2. The domain class
<cfcomponent displayname="itemsDecorator" extends="transfer.com.TransferDecorator" output="false">
<cffunction name="getMyParentItem" access="public" output="false" returntype="any">
<cfreturn getTransfer().get("example.Item",getTransferObject().getParentId()) />
</cffunction>
<cffunction name="getMyChildItems" access="public" output="false" returntype="array">
<cfset var local= StructNew() />
<cfset local.childrenArray= ArrayNew(1) />
<cfset local.childrenQry= getTransfer().listByProperty("example.Item","parentId",getTransferObject().getItemId(),"itemOrder")>
@bcswartz
bcswartz / transfer.xml
Created November 22, 2017 15:52
Transfer decorator example, part 1. The configuration
<package name="example">
<object name="Item" table="itemsTable" sequence="itemId_seq" decorator="com.itemDecorator">
<id name="itemId" type="numeric" />
<property name="setId" type="numeric" column="setId" />
<property name="itemTitle" type="string" column="itemTitle" />
<property name="itemText" type="string" column="itemText" />
<property name="itemOrder" type="numeric" column="itemOrder" />
<property name="parentId" type="numeric" column="parentId" />
</object>
</package>
@bcswartz
bcswartz / pseudoAjaxHyperlink.cfm
Created November 22, 2017 15:33
Example of a technique to support AJAX-like behavior when JavaScript is turned off
@bcswartz
bcswartz / serverSubmit.cfm
Created November 19, 2017 16:08
submitDemo, part 4
<cfset errorList= "">
<cfif form.firstName EQ "">
<cfset errorList= ListAppend(errorList,"You must enter your first name.","|")>
</cfif>
<cfif form.lastName EQ "">
<cfset errorList= ListAppend(errorList,"You must enter your last name.","|")>
</cfif>
<cfif errorList EQ "">
@bcswartz
bcswartz / submitDemo.js
Created November 19, 2017 16:07
submitDemo, part 3
$(document).ready(function() {
$("#submitButton").click(function () {
$("#submitType").val("ajax");
});
$('#submitDemoForm').submit(function() {
$(this).ajaxSubmit(submitOptions);
return false;
});
@bcswartz
bcswartz / submitDemo.css
Created November 19, 2017 16:06
submitDemo, part 2
hideElement {display:none;}
.errorMsg {background-color:red;color:white;padding:.5ex;}
.successMsg {background-color:green;color:white;padding:.5ex;}
.successText {color:green;font-weight:bold;}
.errorText {color:red;font-weight:bold;}
form label {
width:7em;
float: left;