Skip to content

Instantly share code, notes, and snippets.

View traviskroberts's full-sized avatar

Travis Roberts traviskroberts

View GitHub Profile
@traviskroberts
traviskroberts / gist:97
Created July 21, 2008 20:20
Generate Random Password
def generate_password(length=6)
chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ23456789'
password = ''
length.times { password << chars[rand(chars.length)] }
password
end
@traviskroberts
traviskroberts / 1_activeadmin_user.rb
Created February 5, 2014 16:47
Custom filter for ActiveAdmin.
ActiveAdmin.register User do
index do
column :id
column :full_name, sortable: :last_name
column :status
default_actions
end
filter :first_name
class ApplicationController < ActionController::Base
before_filter :set_rand_cookie
private
def set_rand_cookie
return if cookies[:rand_seed].present?
cookies[:rand_seed] = {value: rand(100), expires: Time.now + 900}
end
end
<%= form_tag form_submit_path do %>
<fieldset>
<legend>Contact Info</legend>
<div class="form-group">
<%= label_tag :name %>
<%= text_field_tag :name %>
</div>
<div class="form-group">
@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
@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 / 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
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
{
"auto_complete": false,
"binary_file_patterns":
[
"*.dds",
"*.eot",
"*.gif",
"*.ico",
"*.jar",
"*.jpeg",
class User < ActiveRecord::Base
belongs_to :organization
has_many :projects
validates :name, :presence => true
validates :email, :uniqueness => true
end