Skip to content

Instantly share code, notes, and snippets.

@uhlenbrock
uhlenbrock / init.coffee
Created March 13, 2014 17:27
Force Atom to load rails grammar over ruby grammar
path = require 'path'
atom.workspaceView.eachEditorView (editorView) ->
editor = editorView.getEditor()
grammar = switch path.extname(editor.getPath())
when '.rb' then atom.syntax.grammarsByScopeName['source.ruby.rails']
when '.erb' then atom.syntax.grammarsByScopeName['text.html.ruby']
@uhlenbrock
uhlenbrock / init.coffee
Created March 13, 2014 21:13
Open the last migration created in a rails project
atom.workspaceView.command 'last-migration', ->
migrate_directory = atom.project.getRootDirectory()
migrate_directory.path = "#{migrate_directory.path}/db/migrate"
last_migration = migrate_directory.getEntriesSync().pop()
atom.open
pathsToOpen: [last_migration.path]
@uhlenbrock
uhlenbrock / user.rb
Created September 23, 2008 20:05
Sample Unit Tests
class User < ActiveRecord::Base
# Validation
validates_presence_of :password_confirmation
# Association
has_many :comments
# Instance Method
def full_name
"#{first_name} #{last_name}"
end
end
class UserMailer < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += "One final step: please activate."
@body[:url] = "http://#{user.site.domain}/activate/#{user.activation_code}"
@body[:code] = user.activation_code
end
end
@uhlenbrock
uhlenbrock / users_controller.rb
Created September 23, 2008 20:54
Sample Functional Tests
class UsersController < ActionController::Base
before_filter :login_required
def show
@user = User.find(params[:id])
end
end
@uhlenbrock
uhlenbrock / blueprint_bookmarklet.js
Created December 17, 2008 16:30
Bookmarklet for BlueprintCSS
/**
* Make this a "bookmarklet"
* 1. Remove the function enclosure
* 2. Remove spaces (http://userjs.up.seesaa.net/js/bookmarklet.html)
* 3. Add to your browser's bookmarks bar
*/
function toggle_showgrid() {
var d = Array.prototype.slice.call(document.getElementsByClassName('container'));
var id = document.getElementById('container');
if (id) { d.push(id); }
@uhlenbrock
uhlenbrock / template.rb
Created December 18, 2008 19:50
My Rails Template
# TODO
# - authentication for admin
# - hoptoad/exception_notification
# - setup layouts
# - any gems?
# - any plugins?
# - blueprint?
# Delete unneeded files
run 'rm README'
@uhlenbrock
uhlenbrock / deploy.rb
Created January 25, 2010 21:47
Simple Capistrano recipe for Jekyll
set :application, 'foo'
set :repository, '_site'
set :scm, :none
set :deploy_via, :copy
set :copy_compression, :gzip
set :use_sudo, false
set :host, '127.0.0.1'
role :web, host
role :app, host
@uhlenbrock
uhlenbrock / gist:298662
Created February 8, 2010 22:30
Retrieve archival tweets in json
# TODO: parameterize query
# TODO: paginate google results
require 'rubygems'
require 'mechanize'
require 'json'
tweets = []
a = Mechanize.new do |agent|
@uhlenbrock
uhlenbrock / integration_test_helper.rb
Created September 7, 2011 17:16
Integration Testing with Capybara & Devise
require 'test_helper'
require 'capybara/rails'
require 'devise/test_helpers'
class ActionController::IntegrationTest
include Capybara::DSL
include Warden::Test::Helpers
self.use_transactional_fixtures = false