Skip to content

Instantly share code, notes, and snippets.

@superlou
superlou / gist:935790
Created April 22, 2011 00:44
Modeling polymorphic has_many :through
A user creates Spaces (rooms), Items (things), and Profiles (people).
Reservations are used to schedule times when these three models are in use and cannot be used elsewhere.
Since the modeling of a thing that can only be in use in one place/activity is common to Spaces, Items, and Profiles, this common functionality makes up the polymorphic model Resource.
Reservation
belongs_to :manager, :class_name => "Profile"
has_many :reservation_lines, :before_add => :set_nest, :dependent => :destroy
has_many :profiles, :through => :reservation_lines, :source => :reservable, :source_type => 'Profile'
has_many :spaces, :through => :reservation_lines, :source => :reservable, :source_type => 'Space'
@superlou
superlou / gist:1086741
Created July 16, 2011 20:29
Automatic join model not created
== Activity Model ==
has_many :rule_assignments, :dependent => :destroy # RuleAssignment has activity_id, and rule_type, rule_id
has_many :be_located_in_rules, :through => :rule_assignments, :source => :rule, :source_type => 'BeLocatedInRule'
== BeLocatedInRules Controller ==
def create
@rule = @activity.be_located_in_rules.build(params[:be_located_in_rule])
...
@rule.save # successfully create the BeLocatedInRule, but no join model (RuleAssignment)
@superlou
superlou / gist:1087737
Created July 17, 2011 16:15
Centering
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<style type="text/css">
#flag { url(images/heartseedLightImage2.jpg) no-repeat }
#green { background:green; display:block; float: left; width: 100px }
#white { background:yellow; display:block; float: left; width: 100px }
#red { background:red; display:block; float: left; width: 100px }
@superlou
superlou / gist:1362773
Created November 13, 2011 21:46
Source switching debug info
Attempting fallback
0:00:05.293557425 8185 0xe5f730 DEBUG basesrc gstbasesrc.c:3104:gst_base_src_change_state:<v4l2src0> PLAYING->PAUSED
0:00:05.293593887 8185 0xe5f730 DEBUG basesrc gstbasesrc.c:2895:gst_base_src_set_playing:<v4l2src0> unlock
0:00:05.293610433 8185 0xe5f730 LOG v4l2src gstv4l2src.c:749:gst_v4l2src_unlock:<v4l2src0> Flushing
0:00:05.293711344 8185 0x1545090 DEBUG v4l2src v4l2src_calls.c:191:gst_v4l2src_grab_frame: stop called
0:00:05.293737276 8185 0x1545090 DEBUG basesrc gstbasesrc.c:2232:gst_base_src_get_range:<v4l2src0> create returned -2 (wrong-state)
0:00:05.293754932 8185 0x1545090 INFO basesrc gstbasesrc.c:2405:gst_base_src_loop:<v4l2src0> pausing after gst_base_src_get_range() = wrong-state
0:00:05.293777495 8185 0x1545090 DEBUG basesrc gstbasesrc.c:2545:gst_base_src_loop:<v4l2src0> pausing task, reason wrong-state
0:00:05.293807345
@superlou
superlou / home.js
Created January 21, 2012 22:00
Modules undefined
// Module Room
define([
"namespace",
"use!backbone"
],
function(namespace, Backbone) {
var Room = namespace.module();
define([
"namespace",
"use!backbone",
"modules/message",
"text!templates/room_tpl.html",
"text!templates/room_row_tpl.html"
],
function(namespace, Backbone, Message, room_tpl, room_row_tpl) {
var Room = namespace.module();
@superlou
superlou / gist:1812642
Created February 13, 2012 01:52
Loop until unique?
var name_is_unique = false;
var name;
while (!name_is_unique) {
name = namer.generate();
var waiting_on_db = true;
User.find({name: name}, function(err,docs) {
if (docs.count > 0) {
name_is_unique = true;
// Set up Mongoose
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var UserSchema = new Schema({
id: ObjectId,
name: String,
registered: {type: Boolean, default: false},
password_hash: {type: String, default: ""},
var Router = Backbone.Router.extend({
routes: {
"": "index",
"profiles": "profiles",
"profiles/:id": "index"
},
index: function() {
var home = new Home.Model({con_name: "Bureaucracon"});
var home_view = new Home.Views.Main({model: home});
// ============================================================================
// TASKS
// ============================================================================
task.registerTask("server", "Run development server.", function(prop) {
var props = ["server"];
// If a prop was passed as the argument, use that sub-property of server.
if (prop) { props.push(prop); }
var options = config(props) || {};