Skip to content

Instantly share code, notes, and snippets.

@snay2
snay2 / open_tunnel.rb
Created July 20, 2011 17:23
Using localtunnel with Kynetx
# The webhook that should be notified when the tunnel is created. In this case, a
# webhook handled by a Kynetx ruleset.
app_url = "http://webhooks.kynetxapps.net/h/a000x000.dev/set_tunnel"
# Create and open the tunnel
tunnel = LocalTunnel::Tunnel.new(4567, key, app_url)
tunnel.register_tunnel()
tunnel.start_tunnel()
@snay2
snay2 / rules.rb
Created July 20, 2011 16:24
KRL for the home automation prototype (incoming call example)
rule incoming_call {
select when phone incoming_call
pre {
media_state = get_media_state();
new_media_state = (media_state eq "play") => "pause" | media_state;
light_level = get_light_level();
new_light_level = (light_level <= 8) => 8 | light_level;
}
{
set_media_state(new_media_state);
@snay2
snay2 / a163x125.js
Created July 7, 2011 14:57
Demonstrates a bug in the JSON parser
ruleset a163x125 {
meta {
name "JSON parser bug"
description <<
Demonstrates a bug in the JSON parser
>>
author "Steve Nay"
logging off
}
@snay2
snay2 / draw.js
Created July 1, 2011 17:44
Dialoguing using a module
rule draw {
select when explicit draw
pre {
placeholder = event:param("placeholder");
html = <<
<div><form>
Last name: <input type="text" name="byufb_dir_last" class="inputtext" />
First name: <input type="text" name="byufb_dir_first" class="inputtext" />
<input type="button" value="Search" class="uiButton" onclick="byufb_dir_search_prep();"/>
</form></div>
@snay2
snay2 / get-stats.js
Created June 21, 2011 23:09
Kynetx rule for exposing stats and the Google Apps Script function that calls it
/**
* Function to pull in TomatoFlix stats through the RESTful web service
* on the webhook. Appends a new row with the date and time and each of the stats.
*
* Set up with a trigger to run once per day in the middle of the night. This can then
* be used for aggregating the stats over time.
*/
function getTomatoFlixStats() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[3];
@snay2
snay2 / incrementA1.js
Created June 21, 2011 22:52
Simple Apps Script example to increment a cell
function incrementA1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[2];
var oldValue = sheet.getRange("A1").getValue();
sheet.getRange("A1").setValue(oldValue + 1);
}
@snay2
snay2 / draw.js
Created June 21, 2011 20:16
Dialoguing with web events
rule draw {
select when explicit directory
pre {
html = <<
<div><form name="byufb_directory_search" id="byufb_directory_search">
Last name: <input type="text" name="byufb_last" class="inputtext" />
First name: <input type="text" name="byufb_first" class="inputtext" />
<input type="button" value="Search" class="uiButton" onclick="byu_fb_submit();"/>
</form></div>
<div id="byufb_dir_res">&nbsp;</div>
@snay2
snay2 / a163x111.krl
Created June 20, 2011 16:11
Bug with raising events in called rulesets
ruleset a163x111 {
meta {
name "Raise event test"
description <<
Original rule. Events can be raised to this rule from itself or from 112.
Run at http://ktest.heroku.com/a163x111
>>
author "Steve Nay"
logging off
}
rule booklist {
select when web pageview "booklist.byu.edu/cas/mybooks.cfm"
pre {
my_form = <<
<div style="display: none;">
<form id="isbnForm" onsubmit="return false">
<input name="isbn" value="nonsense" />
<input type="submit" />
</form>
</div>
@snay2
snay2 / postlude.rb
Created June 2, 2011 23:06
TomatoFlix stats code pieces
fired {
app:netflix += 1 from 1;
}