Skip to content

Instantly share code, notes, and snippets.

View scott-stewart's full-sized avatar

Scott Stewart scott-stewart

View GitHub Profile
// Example code of using MQTT.js to interact with AWS IoT via a presigned url.
// See https://gist.github.com/scott-stewart/2d7dc6a01d5da4326a7ad8b49d467354 for
// an exmaple of creating a presigned AWS IoT URL from a Rails controller.
// This script makes assumptions about page elements and variables not in the
// gist, but hopefully demonstrates the gist of using a presigned url approach,
// which can work to interact with AWS IoT WebSocket MQTT connections.
var iotClient = null;
function runIotClient() {
# Generate Presigned URLS for AWS IoT MQTT WebSockets. There are 2 ways to
# connect to AWS IoT; certificates and Sigv4. Certificates are great for real
# things, but not so great for JavaScript. This presign Rails controller
# example, will allow you to make an authorized ajax call from your apps
# JavaScript to this controller's endpoint, and get back a short lived presign
# url to use to open the connection to your AWS IoT endpoint.
# Note: It is assumed your app already has some sort of session based security
# taking place in ApplicationController, which is omitted here for brevity. You
# would not want an unauthenticated request to be able to get presigned url's
# to your AWS IoT endpoint.
@scott-stewart
scott-stewart / shoulda_matchers_in_test_unit
Created March 7, 2012 18:27
shoulda matchers in plain test::unit, somebody told me you can't use them in test::unit. I said you could, it was just ugly
require 'test_helper'
require 'shoulda/matchers'
class BlogTest < ActiveSupport::TestCase
fixtures :blogs
test "validations" do
assert validate_presence_of(:title).matches?(Blog.new)
end
@scott-stewart
scott-stewart / gist:1269328
Created October 7, 2011 02:55
SimpleForm Nested Label Component for Twitter Bootstrap CSS
# <rails_root>/lib/simple_form/label_nested_input.rb
module SimpleForm
module Components
module LabelInput
extend ActiveSupport::Concern
included do
include SimpleForm::Components::Labels
end
@scott-stewart
scott-stewart / ruby-debug19_in_rbenv
Created September 23, 2011 15:29
installing ruby-debug19 with rbenv
gem install ruby-debug19 -- --with-ruby-include="/Users/scott/.rbenv/versions/1.9.2-p290"
@scott-stewart
scott-stewart / gist:1030835
Created June 17, 2011 03:46
rename files in directory sample
for i in *.html.erb; do mv "$i" "${i/.erb/}".haml; done