Skip to content

Instantly share code, notes, and snippets.

View TomV's full-sized avatar

Tom V TomV

  • UsefulBots
  • San Francisco, CA, USA
  • 07:21 (UTC -12:00)
View GitHub Profile
@TomV
TomV / lcm-term.js
Last active December 17, 2015 22:19
Simple Terminal for Locomotive!
/**
* Simple script to invoke locomotive
* uses the jake-lcm module: https://npmjs.org/package/jake-lcm
*
* Just put this at the root of your locomotive app
*
* Date: 5/30/13
*
*/
@TomV
TomV / models.user.js
Created May 19, 2013 03:54
Example of using jake-lcm to define locomotive environment for testing a model
/* in the test/ folder of a locomotive app that is using jake-lcm */
var mocha = require('mocha')
, should = require('should')
, lcm = require('jake-lcm')
, User;
/* Assume there is a model in app/models/user.js with
var userSchema = new Schema({
display_name: { type: String, required: true, index: true , trim: true}
, email: { type: String, required: true, trim: true}
@TomV
TomV / mouse.js
Created November 12, 2012 05:21 — forked from bfncs/mouse.js
Read Linux mouse(s) in node.js
/**
* Read Linux mouse(s) in node.js
* Author: Marc Loehe (marcloehe@gmail.com)
*
* Adapted from Tim Caswell's nice solution to read a linux joystick
* http://nodebits.org/linux-joystick
* https://github.com/nodebits/linux-joystick
*/
var fs = require('fs'),
# @alert object set up in before proc
it "should have date after sending message" do
email = mock('email')
Mailer.should_receive(:new).and_return(email)
email.should_receive(:send)
email.should_receive(:send)
@alert.send_alert()
@alert.sent_at.class.should == DateTime
end
@TomV
TomV / exception_mailer.rb
Created March 20, 2010 00:46
Simple Sinatra extension to catch exceptions and do some notifiyin (not working yet.)
require 'sinatra/base'
module Sinatra
# module to catch Sinatra errors and send a email
module ExceptionMailer
def initialize(app)
@app = app
# set parameters here..
yield self if block_given?
end
# The following sample code doesn't work for me - any ideas on what I need to change?
# (you need a hoptoad API key to run this..
require 'rubygems'
require 'sinatra/base'
require 'rack/hoptoad'
API_KEY = 'YOUR HOPTOAD API HERE'
class MyApp < Sinatra::Base # (was Sinatra::Default)
use Rack::Hoptoad, API_KEY
enable :raise_errors
require 'rubygems'
require 'sinatra/base'
require 'hoptoad_notifier'
API_KEY = 'YOUR Hoptoad KEY here'
HoptoadNotifier.configure do |config|
config.api_key = API_KEY
end
# Basic Rspec question:
# How do I 'catch' that an Alert was sent to verify my test?
require 'spec'
class MyTask
def problem
a = Alert.new
a.send_alert
end
<!-- This gets the error:
"undefined method `merge' for :code:Symbol"
-->
<%= f.collection_select(:section, :assessment_id, Assessment.all, :id, :code) %>
<!-- but building it manually works fine: -->
<select name="section[assessment_id]">
<!-- This gets the error:
"undefined method `merge' for :code:Symbol"
-->
<%= f.collection_select(:section, :assessment_id, Assessment.all, :id, :code) %>
<!-- but building it manually works fine: -->
<select name="section[assessment_id]">