Skip to content

Instantly share code, notes, and snippets.

View rjcorwin's full-sized avatar

R.J. (Steinert) Corwin rjcorwin

View GitHub Profile
@rjcorwin
rjcorwin / new-content-type-checklist-for-backbone-apps-on-couchdb.md
Created February 19, 2014 00:06
New content type checklist when creating Backbone apps with CouchDB.
  • add the couch view to back the collection (or database)
  • add the model
  • add the model's form view
  • add the route for model's CRUD using form view
  • add the collection
  • add the table and row views
  • add the corresponding table and row templates
  • add the route for the model's collection
var Settings = require('../Settings.js')
var request = require('request')
var log = require('../util/log.js')
var curl = require('node-curl')
var nano = require('nano')(Settings.jerry.CouchDB.URL)
var urlsDb = nano.db.use('urls')
var S = require('string')
var alertAdmins = require('./AlertAdmins.js')
module.exports = function(urlDoc, callback) {
<html>\n\t
<head>\n\t\t
<title>MtGox.com</title>\n\t</head>\n\t
<body>\n\t\t
<p>
<img src=\ "/img/mtgox_loego_mail.png\"/>
</p>\n\t\t\n\t
<form id=\ "memberBlock\" class=\ "memberBlock\" action=\ "#\" method=\ "post\" autocomplete=\ "off\">\n\t\t<span class=\ "icons iconPeople\"></span>\n\t\t
@rjcorwin
rjcorwin / FormRoute.js
Last active August 29, 2015 13:57
Boiler Backbone.js helper code for a Form Route to do CRUD operations on a Model.
// Boiler Backbone.js helper code for a Form Route to do CRUD operations on a Model.
FormRoute = function(modelId, modelClass, formClass, redirect) {
var model = new App.Models[modelClass]()
var form = new App.Views[formClass]({model: model})
App.$el.children('.body').html(form.el)
form.once('Form:done', function() {
Backbone.history.navigate(redirect, {trigger: true})
})
if (modelId) {
model.id = modelId
#copy your ssh key to root@raspberrypi
ssh [email protected] 'aptitude install screen iotop'
ssh [email protected] 'screen -d -m -S clone'
ssh [email protected] 'echo u > /proc/sysrq-trigger'
ssh [email protected] 'screen -x clone'
dd if=/dev/mmcblk0 bs=1M of=/dev/sda
#detach with "CRTL-a d"
iotop
var dirty = require("dirty")('./var/dirty.db')
var ueber = require("./db/DB")
ueber.init(function() {
console.log('ueber initialized')
var db = ueber.db
dirty.on("load", function() {
console.log('dirty load complete')

Chain API is a server that your devices can interact with using HTTP POSTs and HTTP GETs for finding and managing a hierarchy of Sites>Devices>Sensors. After a device has been described to the Chain API server, that Device can then send its data via HTTP POST to the CHAIN API server. The Chain API server then publishes URIs so that other Devices can HTTP GET the historical data of a Device's Sensor(s) as well as a WebSockets URI for each Sensor for subscribing to a live feed of the data as it comes in.

Example

To explain how to accomplish the said purpose of Chain API, I'll interact with a Chain API server using curl from the command line to carry out the following tasks.

  1. Create a Site on a Chain API Server
  2. Create a Device at that Site
  3. Create a Sensor at that Device
  4. Post data to that Sensor
var db = new PouchDB('http://localhost:5984/dbname');
var Thing = Backbone.Model.extend({
idAttribute: "_id",
initialize: function() {
var model = this
var changes = db.changes({
live: true,
var fs = require('fs')
var New = fs.readFileSync('new.html', 'utf-8')
New = New.replace(/\s/g, '')
var Old = fs.readFileSync('old.html', 'utf-8')
Old = Old.replace(/\s/g, '')
if(New == Old) {
console.log('same')
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(random(300));
Serial.println("x");
delay(500);