Skip to content

Instantly share code, notes, and snippets.

@andreareginato
andreareginato / Guardfile
Created October 2, 2012 16:49
Rails Guardfile (handle Spork and RSpec automatic tests)
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch(%r{^config/locales/.+\.yml$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
end
@andreareginato
andreareginato / spec_helper.rb
Created October 2, 2012 16:48
Rails Spec Helper (using Spork, Mongoid, Factory Girls, Draper, Webmock and Capybara)
require 'rubygems'
require 'spork'
# This code runs once when you run your test suite
Spork.prefork do
ENV['RAILS_ENV'] ||= 'test'
# Mongoid models reload
require 'rails/mongoid'
Spork.trap_class_method(Rails::Mongoid, :load_models)
@andreareginato
andreareginato / arduino-ethernet-light.ino
Last active July 14, 2018 09:08
Create your first connected light using Arduino Ethernet
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
/* ------------------ */
/* SKETCH CREDENTIALS */
/* ------------------ */
char* deviceId = "<DEVICE-ID>"; // * set your device id (will be the MQTT client username)
@andreareginato
andreareginato / lelylan-lamp-ardiuno-yun.ino
Last active January 4, 2018 19:45
Code for the MakerFaire Lamp
#include <SPI.h>
#include <YunClient.h>
#include <PubSubClient.h>
char* deviceId = "<DEVICE-ID>";
char* deviceSecret = "<DEVICE-SECRET>";
char* outTopic = "devices/<DEVICE-ID>/set";
char* inTopic = "devices/<DEVICE-ID>/get";
var mongoose = require('mongoose')
, debug = require('debug')('lelylan')
, Device = require('../app/models/devices/device');
module.exports.authenticate = function(client, username, password, callback) {
Device.findOne({ _id: username, secret: password }, function (err, doc) {
if (doc) client.device_id = doc.id
callback(null, doc);
});
}
@andreareginato
andreareginato / sftp-node-server.js
Created October 6, 2017 15:48
sftp node server
"use strict";
var fs = require('fs');
var SFTPServer = require("node-sftp-server");
var ReadableStreamClone = require("readable-stream-clone");
// create the server
var srv = new SFTPServer({
privateKeyFile: "./id_rsa",
temporaryFileDirectory: "./tmp"
});
@andreareginato
andreareginato / oauth2.js
Created January 26, 2013 16:29
OAuth2 app with a Node.js library
/**
*
* OAuth usage example.
*
**/
var http = require("http");
var Url = require("url");
var querystring = require("querystring");
{
"id": "5735a694dcba0f0892824613",
"batch_id": "MARCASAR002",
"customer_id": "5731fdd2b3f30a687138ceea",
"uri": "http://admin.idcork.com/batches/5735a694dcba0f0892824613",
"code": null,
"description": null,
"article": null,
"quality": null,
"diameter": null,
{
"id": "5735a694dcba0f0892824613",
"batch_id": "MARCASAR002",
"customer_id": "5731fdd2b3f30a687138ceea",
"uri": "http://admin.idcork.com/batches/5735a694dcba0f0892824613",
"code": null,
"description": null,
"article": null,
"quality": null,
"diameter": null,
in_topic = 'devices/' + device_id + '/get' # receiving messages
out_topic = 'devices/' + device_id + '/set' # publishing messages