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 / render_and_redirect.markdown
Created September 11, 2011 22:46 — forked from jcasimir/render_and_redirect.markdown
Render and Redirect in Rails 3

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

@mindscratch
mindscratch / rails.rb
Created October 20, 2011 16:05 — forked from simi/rails.rb
Rails 3.1.1 Webrick with SSL support
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
require 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
@mindscratch
mindscratch / .gitignore
Created January 13, 2012 02:04 — forked from bkeepers/.gitignore
My Sublime settings
*
@mindscratch
mindscratch / 1_intro_to_subject.rb
Created February 29, 2012 18:11 — forked from knzconnor/1_intro_to_subject.rb
A pattern for testing class methods in ruby with rspec explicit subjects
# RSpec's subject method, both implicitly and explicitly set, is useful for
# declaratively setting up the context of the object under test. If you provide a
# class for your describe block, subject will implicitly be set to a new instance
# of this class (with no arguments passed to the constructor). If you want
# something more complex done, such as setting arguments, you can use the
# explicit subject setter, which takes a block.
describe Person do
context "born 19 years ago" do
subject { Person.new(:birthdate => 19.years.ago }
it { should be_eligible_to_vote }
@mindscratch
mindscratch / uri.js
Created April 21, 2012 13:33 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.host; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
@mindscratch
mindscratch / self_signed_cert.rb
Created June 7, 2012 14:30 — forked from nickyp/self_signed_cert.rb
create a self-signed certificate using ruby-openssl
We couldn’t find that file to show.
@mindscratch
mindscratch / rails31init.md
Created August 16, 2012 12:48 — forked from samnang/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Simple Form, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

@mindscratch
mindscratch / html-escape.js
Created December 7, 2012 17:56
un/escape HTML in Javascript
// Use the browser's built-in functionality to quickly and safely escape the
// string
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
};
// UNSAFE with unsafe strings; only use on previously-escaped ones!
function unescapeHtml(escapedStr) {
var AutocompleteView = Backbone.View.extend({
initialize: function() {
this.availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",