Skip to content

Instantly share code, notes, and snippets.

View brand-it's full-sized avatar

Brandt Lareau brand-it

View GitHub Profile
class ApplicationController < ActionController::Base
before_filter :set_current_user
protected
def set_current_user
# Call in model with User.current_user
User.current_user = self.current_user
end
end
@brand-it
brand-it / import.rake
Created April 1, 2010 02:55
This is a cool little image importer for web sites kinda out dated but still useful. Used as a rake.
namespace :images do
require 'action_controller'
require 'action_controller/test_process.rb'
require 'find'
desc "Imports all the images into the database as well as formats the for your use."
task :import => :environment do
cards = Array.new
Card.find(:all).map do |t|
cards << ["#{t.name}"]
@brand-it
brand-it / error_form_builder.rb
Created April 1, 2010 02:58
It takes the error messages and moves them next to the label. Only show one error at a time pure field.
class ErrorFormBuilder < ActionView::Helpers::FormBuilder
#Adds error message directly inline to a form label
#Accepts all the options normall passed to form.label as well as:
# :hide_errors - true if you don't want errors displayed on this label
# :additional_text - Will add additional text after the error message or after the label if no errors
def label(method, text = nil, options = {})
#Check to see if text for this label has been supplied and humanize the field name if not.
text = text || method.to_s.humanize
#Get a reference to the model object
object = @template.instance_variable_get("@#{@object_name}")
@brand-it
brand-it / application_controller.rb
Created April 1, 2010 03:00
It is a creative way to create access levels for the admin and any other type of users. Very scalable.
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
# Make sure that all the methods that redirect are handled in the controllers.
class ApplicationController < ActionController::Base
include AuthenticatedSystem
include Userstamp
include ExceptionLoggable
local_addresses.clear
@brand-it
brand-it / application_helper.rb
Created June 24, 2011 06:04
This is kinda of a basic little helper to tell you if the page that you are on is the one you were looking for
module ApplicationHelper
# A nice way to help the views tell if you are on the current page you want to be on.
def current_view(params, options = {})
results = options[:result] || "true"
valid = true
options.each do |option|
for param in params
@brand-it
brand-it / photo_uploader.rb
Created July 8, 2011 07:38
I am Loving CarrierWave and thought I would share the code I am using on r3dux.net. I have loved its connection information for S3.
# encoding: utf-8
class PhotoUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support:
include CarrierWave::RMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
if RAILS_ENV == "development"
storage :file
@brand-it
brand-it / mouse_robot.java
Created July 17, 2011 05:54
I cool mouse robot system that works great. May work for you as well.
public class MouseRobot {
private void mouseRebotReplace(MouseEvent e) {
int x = e.getX() - pCenterX;
int y = e.getY() - pCenterY;
if (!isPaused) {
if (mouseX < 0) {
mouseX = 0;
} else if (mouseX > pWidth) {
@brand-it
brand-it / Start.java
Created August 27, 2011 06:29
This is a basic distance calculation for game. Was testing out how accurate the data that is returned from numbers. Seams to be very good.
public class Start {
public static void main(String args[]) {
System.out.println("x, y: " + (7 - 6) + ", " + (3 - 4));
System.out.println((Math.pow((7 - 6), 2) + Math.pow((3 - 4), 2)));
System.out.println("x, y: " + (7 - 6) + ", " + (3 - 2));
@brand-it
brand-it / Gemfile
Created October 27, 2011 04:27
This is what a rails 3.1.0 app looks like when you create it.
source 'http://rubygems.org'
gem 'rails', '3.1.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
@brand-it
brand-it / Gemfile
Created October 27, 2011 04:31
This is what My rails 3.0.9 R3dux.net site Gemfile looks like
source 'http://rubygems.org'
gem 'rails', '3.0.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem "authlogic", :git => 'git://github.com/odorcicd/authlogic.git', :branch => "rails3"
gem "carrierwave", :git => "git://github.com/jnicklas/carrierwave.git", :branch => "0.5-stable"