Skip to content

Instantly share code, notes, and snippets.

View superacidjax's full-sized avatar

Brian Dear superacidjax

View GitHub Profile
@superacidjax
superacidjax / gist:6390687
Created August 30, 2013 14:51
Sublime Test Setting
{
"color_scheme": "Packages/User/Monokai Soda.tmTheme",
"draw_white_space": "selection",
"font_face": "Source Code Pro",
"font_size": 14.0,
"rulers":
[
80
],
"tab_size": 2,

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@superacidjax
superacidjax / examples.rb
Created June 25, 2013 14:50
Some examples of proper Ruby Style
class SomeClass
SOME_CONSTANT = 'upper case name'
def initialize(attributes)
@some_attribute = attributes[:some_attribute]
@another_attribute = attributes[:another_attribute]
@user_factory = attributes[:user_factory]
end
def method_with_arguments(argument_one, argument_two)
@superacidjax
superacidjax / case.rb
Created June 11, 2013 14:06
Brian's Ruby Tuesday: Examples of Case
# case is a multi-way decision statement similar to if/elsif/else
# here's a bit longer and more thorough discussion: http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/
# a simple example of case
case title
when 'War and Peace'
puts 'Tolstoy'
when 'Romeo and Juliet'
puts 'Shakespeare'
# app/models/ability.rb
# All front end users are authorized using this class
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
can :read, :all
@superacidjax
superacidjax / reset_password.feature
Created December 6, 2012 15:27
Gherkin Example
Feature: User Resets Password
In order to get back in the system when I have forgotten my password
As a User on the sign in page
I want to reset my password
- click forgot password
- I am taken to the reset password page
- provide email
- click reset password
- I receive an email with a reset password link
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
def signed_in?
!current_user.nil?
end
validates :first_name, presence: true, length: { maximum: 50 }
validates :last_name, presence: true, length: { maximum: 50 }
validates :name, presence: true, length: { maximum: 50 },
uniqueness: { case_sensitive: false }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }
validates :password_confirmation, presence: true
txtblk='\[\e[0;30m\]' # Black
txtred='\[\e[0;31m\]' # Red
txtgrn='\[\e[0;32m\]' # Green
txtylw='\[\e[0;33m\]' # Yellow
txtblu='\[\e[0;34m\]' # Blue
txtpur='\[\e[0;35m\]' # Purple
txtcyn='\[\e[0;36m\]' # Cyan
txtwht='\[\e[0;37m\]' # White
txtrst='\[\e[0m\]' # Text Reset
@superacidjax
superacidjax / bad_ruby_indention.rb
Created November 30, 2012 15:19
Bad Ruby Indention
def ugly_method #four space tab-based indention
if current_coder is_not_amateur?
nice_method #see nice_method below
else
20.times.do
puts 'Can you please indent your code properly?'
end
end
end