Skip to content

Instantly share code, notes, and snippets.

@jo
jo / domain.rb
Created March 30, 2010 05:42
Route domains root to resources show
class Domain < ActiveRecord::Base
validates :name, :presence => true, :uniqueness => true
validates :routable, :presence => true
belongs_to :routable, :polymorphic => true
end
@jo
jo / index.html
Created January 6, 2011 11:11
Backbone Event Delegation Tests
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Backbone Event Delegation Tests</title>
<script src="http://documentcloud.github.com/backbone/test/vendor/jquery-1.4.2.js"></script>
<script src="http://documentcloud.github.com/backbone/test/vendor/underscore-1.1.3.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone.js"></script>
<script>
$(function() {
@jo
jo / jevents.html
Created January 6, 2011 11:37
Testing bind event persistence over DOM removal
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Backbone Event Delegation Tests</title>
<script src="http://documentcloud.github.com/backbone/test/vendor/jquery-1.4.2.js"></script>
<script>
$(function() {
var main = $('#main'),
el = $('<p>Welcome <a href="#">Please click me</a></p>');
@jo
jo / couchmodel.js
Created January 11, 2011 14:00
use CouchDB _id
var oldSet = Backbone.Model.prototype.set;
_.extend(Backbone.Model.prototype, {
set: function(attrs, options) {
if ('_id' in attrs) this.id = attrs._id;
oldSet.apply(this, [attrs, options]);
return this;
}
});
@jo
jo / app.json.erb
Created March 31, 2011 20:14
couch app purism
{
"_id": "_design/myapp",
"rewrites": <%= read 'rewrites.json' %>,
"updates": {
"nash": <%=h read 'updates/entry.js' %>
},
"validate_doc_update": <%=h read 'validate.js' %>,
"views": {
"nashs": {
"map": <%=h read 'couchdb-views/entries/map.js' %>
@jo
jo / pointsToLine.js
Created March 29, 2012 12:17
Order points geometrically to build a line
// Build a line from unsorted points,
// in a way that the length of the line is minimal.
var pointsToLine = (function() {
// distance between two points
function dist(p1, p2) {
return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2));
}
// find insertion index
function findIdx(line, point) {
@jo
jo / tf.gif
Created April 14, 2012 20:03
Welcome to TF

this is a test

@jo
jo / README
Created April 17, 2012 21:23
Backbone Current Model Experiments
Backbone Current Model Experiments
You have already fetched a collection of pages.
There is a list view and a show view.
The user selects a page in the list view,
and the corresponding page view is shown.
@jo
jo / worker-fetch-json.js
Created August 3, 2012 13:05
A CouchDB Worker that fetches a remote JSON and inserts it into a document.
/*
* CouchDB Worker Fetch JSON
*
* A CouchDB Worker that fetches a remote JSON and inserts it into a document.
*
* Author: Johannes J. Schmidt
* (c) null2 GmbH, 2012
* MIT Licensed
*/
@jo
jo / README.md
Created November 13, 2012 21:46
Selectable elements

Provide selection capabilities for DOM elements, geared to <select multiple>.

  • click: select element
  • ctrl + click: add element to current selection
  • click + move: select elements while dragging
  • ctrl + a: select all elements within focused list
  • ctrl + shift + a: deselect all elements within focused list
  • ctrl + click + move: toggle selection while dragging
  • shift + click: select range from nearest last selected element to clicked element
  • shift + ctrl + click: add range to current selection