Skip to content

Instantly share code, notes, and snippets.

View jparreira's full-sized avatar

João Parreira jparreira

View GitHub Profile
@jparreira
jparreira / iot_to_realtime.js
Last active December 14, 2015 12:35
AWS Lambda function that send a message through the Realtime Messaging Platform
var https = require('https');
exports.handler = function(event, context) {
var appkey = 'YOUR_REALTIME_APPKEY';
var privatekey = 'YOUR_REALTIME_PRIVATEKEY';
var channel = 'aws-iot';
var message = JSON.stringify(event);
var postBody = "AK=" + appkey + "&PK=" + privatekey + "&C=" + channel + "&M=" + message;
var headers = {
@jparreira
jparreira / migration.js
Created September 14, 2015 18:35
Creates and copies table items from one Realtime Cloud Storage app key to another
var Realtime = require("realtime-storage");
var fromSR;
var toSRCreate;
var toSRCopy;
// Creates destination table and copies items from origin table
function migrate(fromAppKey, fromPrivateKey, toAppKey, toPrivateKey, table)
{
@jparreira
jparreira / index.html
Created April 14, 2015 15:17
Copying items from a Realtime Cloud Storage table to another table (with the same key schema)
<!DOCTYPE html>
<html>
<head>
<script src="http://storage-cdn.realtime.co/storage/1.0.0/realtime-storage-min.js"></script>
<script src="migration.js"></script>
</head>
<body>
<h1>Realtime Cloud Storage: Copy items
@jparreira
jparreira / app.js
Created April 8, 2015 16:26
Retrieving todo items from Realtime Cloud Storage using the REST API from Appcelerator Titanium. This sample can be used with http://storage-public.realtime.co/samples/todo-lbl/index.html#/
//UI
Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({
backgroundColor:'#fff'
});
var label1 = Titanium.UI.createLabel({
color:'#777',
text:'Connecting to Realtime Storage...',
@jparreira
jparreira / HEADtrelloComment.js
Last active August 29, 2015 14:18
Realtime Code Hosting function to signal Trello that trelloComment is a valid webhook callback url
function trelloComment(res){
res.send(200);
}
@jparreira
jparreira / POSTtrelloComment.js
Last active August 29, 2015 14:18
Realtime Code Hosting function to send SMS using Twilio when a new comment is added to a Trello card
function trelloComment(res,req,modules){
// send a log to the remote console
modules.storageMule.log("trelloComment: ", JSON.stringify(req));
// find out the trello action triggered
var trelloAction = req.body.action.type;
// it's a comment
if(trelloAction == "commentCard") {
@jparreira
jparreira / incrementPlayerScore.m
Created May 19, 2014 19:28
Increment Player Score for Flying Brands
- (void) incrementPlayerScore:(NSDictionary *) playerScore WhitScore:(NSNumber *) score OnCompletion:(void (^)(BOOL finished)) completion {
NSNumber *totalScore = [NSNumber numberWithInt:([[playerScore objectForKey:SK_SCORES] intValue] + [score intValue])];
ItemRef *itemRef = [[_storageRef table:TAB_SCORES] item:[playerScore objectForKey:PK_SCORES] secondaryKey:[playerScore objectForKey:SK_SCORES]];
[itemRef del:^(ItemSnapshot *success) {
NSDictionary *newScore = [NSDictionary dictionaryWithObjectsAndKeys:
[playerScore objectForKey:PK_SCORES], PK_SCORES,
totalScore, SK_SCORES,
@jparreira
jparreira / index.htm
Last active August 29, 2015 13:56
Multi-user real-time chat using Realtime Cloud Storage, AngularJS and Pure CSS Speech Bubbles (get your free Storage developers license at http://framework.realtime.co/storage/)
<html ng-app>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.min.js"></script>
<script type="text/javascript" src="https://storage-cdn.realtime.co/storage/1.0.0/realtime-storage-min.js"></script>
<link rel="stylesheet" type="text/css" href="pure-speech.css">
<script type="text/javascript">
function ChatCtrl($scope) {
@jparreira
jparreira / client.htm
Created November 25, 2013 20:53
Realtime Cloud Messaging (ORTC) announcement channels test
<html>
<head>
<title>Announcement channels test</title>
<script type="text/javascript" src="http://dfdbz2tdq3k01.cloudfront.net/js/2.1.0/ortc.js"></script>
</head>
<body>
<script>
loadOrtcFactory(IbtRealTimeSJType, function (factory, error) {
if (error != null) {
@jparreira
jparreira / index.html
Created November 21, 2013 19:38
Listing last n chat messages and retrieve the previous messages on demand. Messages will be written at the browser console in groups of 3 (last ones first). Click on the "previous messages" link to retrieve the previous messages until there's no more messages in the table.
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="http://storage-cdn.realtime.co/storage/1.0.0/realtime-storage-min.js"></script>
</head>
<body>
<a href="javascript:void;" title="previous messages" id="aPreviousMessages">previous messages</a>
<script type="text/javascript" src="list.js"></script>