Skip to content

Instantly share code, notes, and snippets.

View jejacks0n's full-sized avatar
🕴️
doing things and stuff.

Jeremy Jackson jejacks0n

🕴️
doing things and stuff.
  • Denver, CO
View GitHub Profile
module FilterableResource
def acts_as_filterable(options = {})
cattr_accessor :testing
self.testing = 'testing'
self.named_scope :filtered_from, lambda { |params|
puts('!!![' + self.testing.to_s + ']!!!')
nil
}
end
module FilterableResource
# to test {:filter => {:users => .. }
# {:method => 'any', :terms => ['first', 'second'], :fields => 'all'}
# {:method => 'any', :terms => 'first second', :fields => 'all'}
# {:method => 'any', :terms => 'first', :fields => ['first_name', 'last_name']}
# {:method => 'any', :terms => 'first', :fields => 'first_name last_name'}
# {:method => 'all', :terms => ['first', 'second'], :fields => 'all'}
# {:method => 'all', :terms => 'first second', :fields => 'all'}
# {:method => 'all', :terms => 'first', :fields => 'first_name'}
# {:method => 'all', :terms => 'first', :fields => ['first_name', 'last_name']}
module Kernel
def the(a, b)
Exception.new
end
def roof
end
def yo!
end
// Custom Rails routing/resource handling for ajax requests..
(function() {
var methods = ['get', 'put', 'post', 'delete'],
actions = ['index', 'show', 'new', 'create', 'edit', 'update', 'destroy'];
function parseUrl(url) {
var urlParts = url.match(/^((http[s]?|ftp):\/\/)?(((.+)@)?([^:\/\?#\s]+)(:(\d+))?)?(\/?[^\?#\.]+)?(\.([^\?#]+))?(\?([^#]?))?(#(.*))?$/i) || [];
var pathParts = (urlParts[9]) ? urlParts[9].match(/(\/.*)\/+(\w+)$/i) || [] : [];
@jejacks0n
jejacks0n / collection_base.js
Created October 21, 2010 18:29
WebSocketCollection inherits from Collection.Base
CollectionBase = Class.create({
resource: null,
resourceName: '',
resourceHandler: null,
collection: null,
initialize: function(resource) {
this.collection = {};
this.resource = resource;
this.resourceName = resource.prototype.resourceName;
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Footnotes::Application.initialize!
# Start the websocket server
Footnotes::WebSocketServer.new(10081)
require 'rack'
module Middleware
class Jammit
ROOT = '/app/javascripts'
def initialize(app, options = {})
@app = app
@file_server = ::Rack::File.new(Protosite::Engine.root)
end
<script type="text/javascript">
window['midas_setup_container'] = function() {
$('midas_container_selector').childElements().each(function(element) {
Event.observe(element, 'click', function(event) {
event.stop();
this.execute('insertHTML', {action:'insertHTML', value: '<div class="' + element.getAttribute('data-class') + '"><br/></div>'});
}.bind(this));
}.bind(this));
}
</script>
// version 1: working, but not providing what's being sent
// we need to have full posts come through so rails can get the info
xhr.open(this.method, this.action, true);
xhr.setRequestHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.setRequestHeader('X-Version', '1');
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('X-CSRF-Token', this.token);
xhr.setRequestHeader("X-File-Name", this.file.name);
xhr.setRequestHeader("X-File-Size", this.file.size);
# The following allows us to have a nested directory structure of specs. With
# a lot of specs this is needed.
module Evergreen
class Suite
def specs
Dir.glob(File.join(root, Evergreen.spec_dir, '**', '*_spec.{js,coffee}')).map do |path|
Spec.new(self, path.gsub(File.join(root), ''))
end
end