Skip to content

Instantly share code, notes, and snippets.

View traviskroberts's full-sized avatar

Travis Roberts traviskroberts

View GitHub Profile
@traviskroberts
traviskroberts / snippets.cson
Created June 30, 2015 17:23
RSpec 3 Atom snippets
'.source.ruby':
'allow(object).to receive(:method) { return_value }':
'prefix': 'arr'
'body': 'allow(${1:object}).to receive(:${2:method}) { ${3:value} }'
'allow(object).to receive(:method)':
'prefix': 'ar'
'body': 'allow(${1:object}).to receive(:${2:method})'
'allow(object).to receive_messages(method: value)':
require 'rubygems'
require 'vendor/sinatra/lib/sinatra.rb'
set :public, File.expand_path(File.dirname(__FILE__) + '/public') # Include your public folder
set :views, File.expand_path(File.dirname(__FILE__) + '/views') # Include the views
set :environment, :production
disable :run, :reload
class Domain
def self.matches?(request)
request.domain.present? && request.domain != 'example.com'
end
end
# run in non-daemonized mode (so you can monitor it) with `god -c /path/to/mysql.god -D`
# run normally with `god -c /path/to/mysql.god`
# Settings for email notifications (optional)
God::Contacts::Email.defaults do |d|
d.from_email = 'god@my-app.com'
d.from_name = 'God'
d.delivery_method = :smtp # this can also be :sendmail
d.server_host = 'smtp.myapp.com'
d.server_port = 25
class User < ActiveRecord::Base
belongs_to :organization
has_many :projects
validates :name, :presence => true
validates :email, :uniqueness => true
end
{
"auto_complete": false,
"binary_file_patterns":
[
"*.dds",
"*.eot",
"*.gif",
"*.ico",
"*.jar",
"*.jpeg",
guard "spork", rspec_env: { "RAILS_ENV" => "test" }, rspec_port: 8999 do
watch("config/application.rb")
watch("config/environment.rb")
watch("config/environments/test.rb")
watch(%r{^config/initializers/.+\.rb$})
watch("Gemfile")
watch("Gemfile.lock")
watch("spec/spec_helper.rb") { :rspec }
watch(%r{^spec/factories/.+\.rb$})
end
@traviskroberts
traviskroberts / rdio.scpt
Last active August 29, 2015 14:02
Rdio Apple Scripts for media keys
if application "Rdio" is running then
tell application "Rdio" to playpause
else if application "iTunes" is running then
tell application "iTunes" to playpause
end if
if application "Rdio" is running then
tell application "Rdio" to next track
else if application "iTunes" is running then
tell application "iTunes" to next track
@traviskroberts
traviskroberts / app.js.coffee
Created May 1, 2014 17:49
Code to handle global ajax error codes.
# handle api errors
$.ajaxSetup
statusCode:
401: ->
# authentication error
404: ->
# not found
500: ->
# application error
@traviskroberts
traviskroberts / resource.rb
Created March 11, 2014 02:56
Code for blog post "ActiveAdmin: Redirect to Index on Create/Update" - http://nomethoderror.com/blog/2014/03/10/activeadmin-redirect-to-index-on-create-update/
ActiveAdmin.register User do
# ...truncated code...
controller do
def create
super do |format|
redirect_to collection_url and return if resource.valid?
end
end