Skip to content

Instantly share code, notes, and snippets.

João Parreira jparreira

View GitHub Profile
@jparreira
jparreira / iot_to_realtime.js
Last active Dec 14, 2015
AWS Lambda function that send a message through the Realtime Messaging Platform
View iot_to_realtime.js
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 Sep 14, 2015
Creates and copies table items from one Realtime Cloud Storage app key to another
View migration.js
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 Apr 14, 2015
Copying items from a Realtime Cloud Storage table to another table (with the same key schema)
View index.html
<!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 Apr 8, 2015
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#/
View app.js
//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 Aug 29, 2015
Realtime Code Hosting function to signal Trello that trelloComment is a valid webhook callback url
View HEADtrelloComment.js
function trelloComment(res){
res.send(200);
}
@jparreira
jparreira / POSTtrelloComment.js
Last active Aug 29, 2015
Realtime Code Hosting function to send SMS using Twilio when a new comment is added to a Trello card
View POSTtrelloComment.js
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
Increment Player Score for Flying Brands
View incrementPlayerScore.m
- (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 Aug 29, 2015
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/)
View index.htm
<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 Nov 25, 2013
Realtime Cloud Messaging (ORTC) announcement channels test
View client.htm
<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 Nov 21, 2013
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.
View index.html
<!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>
You can’t perform that action at this time.