Skip to content

Instantly share code, notes, and snippets.

View mindscratch's full-sized avatar

Craig Wickesser mindscratch

View GitHub Profile
@mindscratch
mindscratch / $.Controller.md
Created May 31, 2011 09:47 — forked from jupiterjs/$.Controller.md
$.Controller for Alex MacCaw's Book

TODOS:

  • show .models() method and hookup

$.Controller - jQuery plugin factory

JavaScriptMVC's controllers are many things. They are a jQuery plugin factory. They can be used as a traditional view, making pagination widgets and grid controls. Or, they can be used as a traditional controller, initializing and controllers and hooking them up to models. Mostly, controller's are a really great way of organizing your application's code.

Controllers provide a number of handy features such as:

@mindscratch
mindscratch / app-config.yml
Created July 6, 2011 09:51
rake task to build a WAR using warbler. The idea being that a YAML file has multiple 'production' configurations but you need to select one when building a WAR for a certain production environment. You can do that by running: rake build_war[some_environme
%YAML 1.1
---
! "defaults":
! "cache": &7000
! "username": ""
! "password": ""
! "servers": ["localhost:11211"]
! "development":
! "cache": *7000
! "prod-server-a"
@mindscratch
mindscratch / gemfile-snippet
Created August 9, 2011 09:43
Reference other ruby or rails engine project from Gemfile
# include version of rails
gem "rails", "3.0.9"
require "rails"
if Rails.env == 'development'
gem "my-other-project", "../my-other-project"
else
gem "my-other-project", "~> 0.0.1"
end
@mindscratch
mindscratch / mongoid_id_monkey_patch.rb
Created August 15, 2011 09:24
Mongoid: return 'id' instead of '_id' when serializing documents as JSON
module Mongoid
module Document
def as_json(options={})
attrs = super options
attrs["id"] = attrs.delete "_id" if attrs.has_key? "_id"
attrs
end
end
end
@mindscratch
mindscratch / log4r_mixin.rb
Created August 15, 2011 09:28
log4r mixin
module Logging
# Get an instance to a logger configured for the class that includes it.
# This allows log messages to include the class name
def logger
return @logger if @logger
formatter = Log4r::PatternFormatter.new(:pattern => '[%d] %l %C: %M')
@logger = Log4r::Logger.new(self.class.name)
@mindscratch
mindscratch / rails_app_ssl_monkey_patch.rb
Created August 15, 2011 09:32
Rails (3.0.x): request.ssl? isn't working -- monkey patch
class Application < Rails::Application
# MONKEY PATCH
#
# Calls to request.ssl? aren't working. The ssl? method relies on some environment variable(s)
# to be set and doesn't take into account the 'rack.url_scheme'. See ticket #5750 on the Rails
# lighthouseapp.com ticketing site.
# url: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5750-requestssl-should-reflect-rackurl_scheme
def call(env)
@mindscratch
mindscratch / gist:1145962
Created August 15, 2011 09:37
Rails: simple resource routes generation (rails 3.0)
module ActionDispatch
module Routing
class Mapper
# resources can be one or more resource types (should be plural)
#
# ex: simple_resources :widgets
#
# This will generate the following routes:
#
# GET widgets => widgets#index
@mindscratch
mindscratch / routes.rb
Created August 15, 2011 09:44
Rails (3.0.x): easily namespace routes for entire app
MyApp::Application.routes.draw do
my_draw = Proc.new do
get "widgets" => "widgets#index"
# add other routes here
end
@mindscratch
mindscratch / warble.rb
Created August 15, 2011 09:47
Rails: warbler config for a JRuby on Rails app
# this file would live in myapp/confif directory
# this only shows the lines that I had uncommented/configured in the warble.rb file
# that was generated with warble v1.3.1
Warbler::Config.new do |config|
config.dirs = %w(app config lib log vendor tmp)
config.webxml.jruby.compat.version = "1.9"
@mindscratch
mindscratch / grid.ejs
Created August 17, 2011 09:39
jqGrid widget using JavaScriptMVC
<table id="<%= options.gridId %>" class="grid <%= options.gridClass %>">
<tr>
<td />
</tr>
</table>
<div id="<%= options.pagerId %>"></div>