Skip to content

Instantly share code, notes, and snippets.

View openfirmware's full-sized avatar

James Badger openfirmware

View GitHub Profile
@openfirmware
openfirmware / gist:3427808
Created August 22, 2012 17:36
capybara-webkit 0.12.1 install issue
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
$ uname -a
Darwin James-MacBook-Pro.local 12.0.0 Darwin Kernel Version 12.0.0: Sun Jun 24 23:00:16 PDT 2012; root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64
$ rvm version
rvm 1.15.5 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$ brew doctor
Your system is raring to brew.
@openfirmware
openfirmware / engine_override.rb
Created January 17, 2013 23:28
This piece of code (from http://stackoverflow.com/a/5051185/237958) can be used to automatically extend controllers/helpers/models and replace views defined in a Rails engine with the same files defined in the host Rails application. Works on Rails 3.2.11.
# config/initializers/engine_override.rb
require 'active_support/dependencies'
module ActiveSupport::Dependencies
alias_method :require_or_load_without_multiple, :require_or_load
def require_or_load(file_name, const_path = nil)
if file_name.starts_with?(Rails.root.to_s + '/app')
relative_name = file_name.gsub(Rails.root.to_s, '')
@engine_paths ||= Rails.application.railties.engines.collect{|engine| engine.config.root.to_s }
@engine_paths.each do |path|
#!/usr/bin/env ruby
# -*- ruby -*-
require 'rubygems'
require 'daemon_spawn'
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
class DelayedJobWorker < DaemonSpawn::Base
def start(args)
ENV['RAILS_ENV'] ||= args.first || 'development'
@openfirmware
openfirmware / april-ntc1.nut
Last active December 21, 2015 21:19
Electric Imp program for April breakout board and NTC Thermistor to measure temperature wirelessly. Modified from original version to return Celsius instead of Fahrenheit.
/*
Copyright (C) 2013 electric imp, inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
@openfirmware
openfirmware / completed tasks.applescript
Created September 26, 2013 20:37
With OmniFocus running, will log how many tasks in each context were marked completed in the last 7 days.
(*
This script logs the number of tasks completed for each context in the last 7 days.
Copyright © 2013, James Badger.
*)
property daysLimit : 7
on run
tell application "OmniFocus"
@openfirmware
openfirmware / slow-ajax.js.coffee
Created October 24, 2013 21:00
Use JQuery promises to add a random delay before actually executing any JQuery ajax calls. Intended to simulate a slow-loading or high latency connection, so you can focus on your waiting/loading interface.
# When enabled, will add a delay to all AJAX calls of `base` +/- `range`.
# Will not delay less than 0 seconds.
nativeAjax = $.ajax
window.SlowAjax =
activate: (base = 5000, range = 0) ->
@min = base - range
@max = base + range
@openfirmware
openfirmware / dummy_server.sh
Created November 12, 2013 20:32
For Rails Engines, to start the dummy server with a single command. Save in `bin` directory, and make executable with chmod. Will pass arguments along to `rails server` (e.g. `-p 8080`).
#!/bin/bash
cd "test/dummy" && rails server $@
@openfirmware
openfirmware / ntc-agent.nut
Created February 4, 2014 20:54
Updated version of my NTC device and agent code, for use with the newer Electric Imp IDE and Xively.
const FEED_ID = "HERE";
const API_KEY = "YOUR KEY";
function send_xively(body) { //take in csv value
local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".csv"; //setup url for csv
server.log(xively_url);
server.log(body); //pring body for testing
local req = http.put(xively_url, {"X-ApiKey":API_KEY, "Content-Type":"text/csv", "User-Agent":"Xively-Imp-Lib/1.0"}, body); //add headers
local res = req.sendsync(); //send request
if(res.statuscode != 200) {
server.log("error sending message: "+res.body);
@openfirmware
openfirmware / README.markdown
Created April 1, 2014 18:40
roar-rails nested association pagination example

Roar-rails and representing AssocationRelations with Pagination

The roar-rails gem can be used to generate custom REST representations of resources for your Rails application. If you have an app with any sort of nested resources, then you may not have many found examples of representing the layers of resources. Here is one that I've found works and is mostly straight forward.

As the routes file and models show, it is just a simple has_many/belongs_to relationship. You likely want to show representations of the resources: People, Person, Pets for Person, and Pet. Writing representers for People, Person, and Pet are simple enough, and the roar-rails documentation explains it. There are multiple ways to represent the Pets for a Person; which is a resource in its own right. Because it is a resource, it should have its own representation: PersonPetsRepresenter.

A simple way is to respond_with @person and then read the #pets relation in the