Skip to content

Instantly share code, notes, and snippets.

View dmccreary's full-sized avatar

Dan McCreary dmccreary

View GitHub Profile
@dmccreary
dmccreary / xforms-income-expense-totals
Last active August 23, 2017 19:23
Example of using Orbeon forms to create a spreadsheet like behavior to correctly calculate sums and differences even when nulls are present.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">
<head>
<title>Sample Annual Income and Expenses Report in Table</title>
<xf:model>
<xs:schema>
<xs:simpleType name="decimalOrNull">
<xs:restriction base="listOfDecimals">
<xs:maxLength value="1"/>
</xs:restriction>
</xs:simpleType>
@dmccreary
dmccreary / Orbeon XForms JavaScript using xf:load and AVTs
Created October 9, 2013 15:12
With Orbeon, you can pass parameters between an XForms application and a JavaScript function using the <xf:load> statement and Attribute Value Templates (AVTs). This example shows you how it is done. Note that there are a few samples (in comments) that do not work due to limitations in the ways parameters are passed. Thanks to Alessandro Vernet …
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xf="http://www.w3.org/2002/xforms">
<head>
<title>Example of Using JavaScript Variable Passing Using xf:load and Attribute Value Templates</title>
<!--
http://wiki.orbeon.com/forms/doc/developer-guide/xforms-actions/actions-script-action
http://wiki.orbeon.com/forms/doc/developer-guide/xforms-javascript-integration
Note that http://wiki.orbeon.com/forms/projects/client-side-api-for-custom-javascript-widgets is not yet implementd
-->
<xf:model>
<xf:instance xmlns="" id="save-data">
@dmccreary
dmccreary / Arduino LED fader
Created November 12, 2013 04:28
Sample Arduino C program to fade and LED slowly on and off and control the delay time of ramp up, on, ramp down and off.
/* Based on the Arduino fader example
Dan McCreary
Nov. 2013 */
int ledPin = 11; // LED connected from digital pin 11 to ground
int maxb = 155; // max brightness 0 to 255
int inc = 1; // step increment value: typical values are from 1 to 10
int slope = 20; // delay at each step in milliseconds - combine with inc to change speed transition
int delayOn = 1000; // how long to stay at max brightness in milliseconds
int delayOff = 2000; // how long to stay off in milliseconds
@dmccreary
dmccreary / tinymce-character-count.js
Last active December 28, 2015 08:59
Update to Chad Killingsworth's TinyMCE plugin that strips markup before character count.
(function () {
tinymce.create("tinymce.plugins.HTMLCharCount", {
_MaxLength: 0, _CharsString: "", _RemainString: "", init: function (a, b) {
var c = this; c._MaxLength = a.getParam("htmlcharcount_maxchars", 0);
if (a.getParam("theme", "") != "advanced") {
return
}
c._CharsString = " " + a.getLang("htmlcharcount.chars", "Characters");
c._RemainString = " " + a.getLang("htmlcharcount.remaining", "Characters remaining");
a.onPostRender.add(function (e, d) {
@dmccreary
dmccreary / read-DHT22.c
Last active December 28, 2015 12:49
Demonstration of reading digital temperature and relative humidity from DHT22 sensor with Arduino UNO. You can purchase the device here * https://www.sparkfun.com/products/10167 Based on Ben Adams driver at http://www.sparkfun.com/products/10167 Using Arduino 1.5.4 IDE I got the following compile data: Sketch uses 5,406 bytes (16%) of program st…
// you can get the header file at http://www.sparkfun.com/products/10167
#include <DHT22.h>
// Only used for sprintf
#include <stdio.h>
// Data wire is plugged into port 2 on the Arduino
#define DHT22_PIN 2
// Ben's original code suggested a 4.7K resistor between VCC and the data pin (strong pullup)
// But I found this was not needed since the pullup can be in software
@dmccreary
dmccreary / gist:8201987
Created December 31, 2013 20:36
Hot to detect what version of XQuery you are running using the newer XQuery 3.0 function-lookup() function. Note: this approach will not work on XQuery 1.0.
xquery version "3.0";
(: Sample XQuery program to detect what version of XQuery you are running.
Note this ONLY works in XQuery 3.0. It will fail in any XQuery "1.0" implementation such as Saxon HE.
Unlike many things in XQuery, this function is not elegant. Perhaps XQuery "4.0" will include a function such system-property('version')
Note that fn:function-lookup() returns a function if it exists and null if it does not.
See http://www.w3.org/TR/xpath-functions-30/#func-function-lookup
Thanks to http://stackoverflow.com/users/1451599/dirkk for the solution
http://stackoverflow.com/questions/20849295/how-can-i-write-an-xquery-that-can-test-what-version-of-xquery-is-being-used
:)
declare function local:exist() as xs:boolean {
@dmccreary
dmccreary / helipad-distance.cpp
Last active January 4, 2016 05:09
Position sensor code for RC Helicopter target landing game. Try to land your RC Helicopter (Syma S107 preferred) in a 10cm target. Sensor detect how far you are away from center. Three LEDs (green, orange and red) will tell your score.
/*
Arduino 1 Dimensional RC Helicopter Target Center Detection
Mount sensor near a circle 10 cm across
Try to land your RC Helicopter (Syma S107 preferred)
If the Green LED lights up you are in the target zone and you get 3 points
If the Orange LED lights up you near but not in the target zone and you get 1 points
If the Red LED lights up you only get a single point
Circuit:
I used HC-SR04 Ping distance sensor
@dmccreary
dmccreary / xforms-css-layout-vertical-horizontal-grid.xml
Created February 11, 2014 01:22
XForms CSS Layout Examples: Vertical, Horizontal and Grid
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xxf="http://orbeon.org/oxf/xml/xforms">
<head>
<title>XForms CSS Layout Examples - Vertical, Horizontal and Grid Layouts</title>
<xf:model>
<xf:instance xmlns="">
<data>
<first-name>Sue</first-name>
<last-name>Johnson</last-name>
<city>Minneapols</city>
<state>MN</state>
@dmccreary
dmccreary / xforms-css-label-layout.xml
Last active August 29, 2015 13:56
XForms CSS to control label layout style: top, left align and right align
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xxf="http://orbeon.org/oxf/xml/xforms">
<head>
<title>XForms Label Layout Styles</title>
<xf:model>
<xf:instance xmlns="">
<data>
<first-name>Sue</first-name>
<last-name>Johnson</last-name>
<city>Minneapols</city>
<state>MN</state>
@dmccreary
dmccreary / xforms-label-hint-help-alert.xml
Created February 11, 2014 02:03
XForms labels, hints, help and alert elements within a form
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xxf="http://orbeon.org/oxf/xml/xforms">
<head>
<title>XForms Label, Hint, Help and Alerts</title>
<xf:model>
<xf:instance xmlns="">
<data>
<myNumber1>-1.234</myNumber1>
<myNumber2>101</myNumber2>
</data>
</xf:instance>