Skip to content

Instantly share code, notes, and snippets.

@snay2
snay2 / a163x40.krl
Created February 3, 2011 01:27
TA office hours - web augmentation version
ruleset a163x40 {
meta {
name "TA Hours"
description <<
Shows on the class website whether the TA is currently in his office hours
>>
author "Steve Nay"
logging off
use module a8x114 alias officehours with url = "http://www.google.com/calendar/feeds/logih83e7lfku7ighp75l3qsp8%40group.calendar.google.com/public/basic"
@snay2
snay2 / a163x40.krl
Created February 3, 2011 18:30
Twilio integration for the Office Hours app
rule call is active {
select when twilio onanswer
if officehours:onnow("Office hours") then {
noop();
}
fired {
raise explicit event call_present;
} else {
raise explicit event call_not_present;
}
@snay2
snay2 / a163x40.krl
Created February 3, 2011 22:06
Modified SMS rules
rule sms is active {
select when twilio sms
pre {
messagetext = event:param("Body");
sender = event:param("From");
nextevent = officehours:next("Office hours");
eventtime = nextevent => smsdate(nextevent.pick("$.when[0].start")) | "not scheduled. See the class wiki for info";
}
if officehours:onnow("Office hours") then {
noop();
@snay2
snay2 / a163x40.krl
Created February 3, 2011 22:07
smsdate function for displaying the date
smsdate = function(d){
datestringA = time:strftime(d, "on %A (%B %d) at %I %M %p");
datestringB = datestringA.replace(re/ 0/g, " ").replace(re/ 0/g, " ");
datestringB;
};
@snay2
snay2 / comment.html
Created February 13, 2011 04:09
Example using SimpleDB and the logging server
<p>Submitted an automated comment to that image.
Go <a href="http://imaj.lddi.org/view?imagekey=$key">view it</a>.</p>
<p><a href="/simpldb">Return</a></p>
@snay2
snay2 / notifications.html
Created February 24, 2011 23:16
Simple Chrome desktop notifications
<html>
<head>
<title>Testing Chrome desktop notifications</title>
<script type="text/javascript" language="javascript">
var icon = 'http://farm1.static.flickr.com/79/245536726_94521c750d_s.jpg';
function showPopup() {
window.webkitNotifications.requestPermission(function() {
var popup = window.webkitNotifications.createNotification(
icon, 'Message Title', 'Message body');
@snay2
snay2 / funcs.py
Created March 3, 2011 22:21
Examples using SQS
import uuid
import time
import boto
import json
from boto.sqs.message import RawMessage
AWSKey = "{redacted}"
AWSSecret = "{redacted}"
testQueue = "testqueue"
@snay2
snay2 / watermark.py
Created March 18, 2011 17:00
How to apply a semi-transparent watermark to an image using Python
from PIL import Image, ImageDraw
def main():
# Open the original image
main = Image.open("12voltm.jpg")
# Create a new image for the watermark with an alpha layer (RGBA)
# the same size as the original image
watermark = Image.new("RGBA", main.size)
# Get an ImageDraw object so we can draw on the image
@snay2
snay2 / a163x63.krl
Created March 28, 2011 17:33
The StringBin module
ruleset a163x63 {
meta {
name "StringBin module"
description <<
Module for the StringBin API (http://stringbin.com/).
Version 1 of the API provides two functions: read and write. While
the API provides the ability to use callbacks, this is not reflected
here, as they are not necessary in the context of KRL.
>>
author "Steve Nay"
@snay2
snay2 / a163x75.krl
Created April 4, 2011 18:47
Example for using the Postmark API
ruleset a163x75 {
meta {
name "Postmark example"
description <<
Uses the Postmark module to send an email when called through a bookmarklet
>>
author "Steve Nay"
logging off
key postmark {