Skip to content

Instantly share code, notes, and snippets.

View elricstorm's full-sized avatar

Joel Dezenzio elricstorm

View GitHub Profile
# SANDBOX EXAMPLE
#===========================================================================================================
# RAKE FILE START
#===========================================================================================================
desc "Perform Calculations"
task :calc => :environment do
# Category
@elricstorm
elricstorm / example xml
Created August 24, 2009 22:27
comparison
<?xml version="1.0" encoding="UTF-8"?>
<comparison>
<team>
<name>Florida</name>
<tsrs type="float">111.423</tsrs>
<offensive_statistics>
<raw_stats>
<total_offense type="float">445.07</total_offense>
<rushing_offense type="float">231.14</rushing_offense>
<passing_offense type="float">213.93</passing_offense>
named_scope :compiled_this_week, lambda { { :conditions => ['created_at > ? and created_at < ?', Time.now.beginning_of_week, Time.now.end_of_week] } }
# I have a series of constants that use the following format:
OFFENSE_RUSHING = [:rank, :team_id, :games, :carries, :net, :avg, :tds, :ydspg, :wins, :losses, :ties]
# These constants are called in the method below
# url, name, deep only apply to my scraper class and is used for parsing so it's not an issue here
# If no data is found for the current week, new data is created - this works fine
# Set up email server using Gmail
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => :true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "yourdomain.com" ,
:authentication => :plain,
:user_name => "your_username" ,
<html>
<head>
<title>Contact Message</title>
</head>
<body>
<h2>Contact Email Received</h2>
<ul>
<li>From: <%= @message.name %></li>
<li>Company: <%= @message.company %></li>
<li>Phone: <%= @message.phone %></li>
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
class CreateUsers < ActiveRecord::Migration
def self.up
create_table "users", :force => true do |t|
t.string :login, :email, :remember_token, :first_name, :last_name, :limit => 100
t.boolean :admin, :super
t.string :crypted_password, :limit => 40
t.string :password_reset_code, :limit => 40
t.string :salt, :limit => 40
t.string :activation_code, :limit => 40
t.datetime :remember_token_expires_at, :activated_at, :deleted_at, :created_at, :updated_at
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery
include AuthenticatedSystem
private
# Defining a function called authorize which will make sure that any pages we don't want accessible
class UsersController < ApplicationController
before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, :purge]
before_filter :login_required, :except => [:new, :create, :activate, :change_password, :forgot_password, :reset_password]
before_filter :authorize, :except => [:new, :create, :activate, :change_password, :forgot_password, :reset_password]
def index
@users = User.find(:all)
respond_to do |format|
require 'digest/sha1'
class User < ActiveRecord::Base
# Virtual attribute for the unencrypted password
attr_accessor :password
validates_presence_of :login, :email, :first_name, :last_name
validates_presence_of :password, :if => :password_required?
validates_presence_of :password_confirmation, :if => :password_required?
validates_length_of :password, :within => 4..40, :if => :password_required?