Skip to content

Instantly share code, notes, and snippets.

@alexkolson
Created December 17, 2010 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkolson/744318 to your computer and use it in GitHub Desktop.
Save alexkolson/744318 to your computer and use it in GitHub Desktop.
ruleset a369x116 {
meta {
name "SringBin Module Test Harness"
description <<
SringBin Module Test Harness
>>
author "AKO"
logging on
use module a369x115 alias StringBin with pin = "X9ooUUsrR180MkpxZ2N1M"
}
rule write_to_stringbin {
select when pageview ".*"
pre {
stuff = StringBin:write("yellow", "mellow");
}
emit <|
window.countOfThings = 0;
|>;
always {
raise explicit event "read_from_stringbin" with k = "yellow";
}
}
rule read_from_stringbin {
select when explicit read_from_stringbin
pre {
goodness = StringBin:read(event:param("k"));
}
{
emit <|
console.log(window.countOfThings + "\n" + JSON.stringify(goodness, null, 2));
window.countOfThings++;
|>;
}
always {
app:counter += 1 from 1;
raise explicit event "destroy_key_in_stringbin" with k = "yellow";
}
}
rule destroy_key_in_stringbin {
select when explicit destroy_key_in_stringbin
pre {
mcHorsty = StringBin:destroy(event:param("k"));
}
always {
raise explicit event "read_from_stringbin" with k = "yellow" if app:counter < 2;
}
}
}
ruleset a369x115 {
meta {
name "StringBin Module"
description <<
StringBin Module
>>
author "AKO"
logging off
provide read, write, destroy
configure using pin = "nopin"
}
global {
datasource write <- "http://api.stringbin.com/1/write?" cachable for 1 second
datasource read <- "http://api.stringbin.com/1/read?" cachable for 1 second
write = function(k,v) {
datasource:write({"pin":pin,"key":k,"value":v})
}
read = function(k) {
datasource:read({"pin":pin,"key":k})
}
destroy = function(k) {
datasource:write({"pin":pin,"key":k,"value":""})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment