Skip to content

Instantly share code, notes, and snippets.

View Sutto's full-sized avatar

Darcy Laycock Sutto

View GitHub Profile
class DownloadsController < ApplicationController
before_filter :can_create?, :only => [:new, :create]
before_filter :can_edit?, :only => [:edit, :update, :destroy]
resources_controller_for :downloads
helper_method :can_create?, :can_edit?
def can_create?
return !!(current_user && current_user.superuser?)
end
Goal is => Client.first.items... Can do with finder_sql, but want an activerecord way!
class Client < ActiveRecord::Base
has_many :contacts
has_many :tasks, :through => :contacts
has_many :items, :through => :contacts # THIS DOESNT WORK
end
class Contact < ActiveRecord::Base
belongs_to :client
# Recursion
# I usually put them around method arguments
def recursive(x)
return if x >= 10
puts x
recursive x + 1
end
# No Brackets here
recursive 0
#!/usr/bin/ruby
require 'rubygems'
require 'mysql'
require 'sqlite3'
def with_mysql
db_object = Mysql.init()
db_object.real_connect('localhost','things','1234','things')
@Sutto
Sutto / checker.erb
Created October 15, 2009 11:30 — forked from ocean/checker.erb
<h1>Feeds Checker</h1>
<%
require 'hpricot'
require 'open-uri'
f1 = open("http://www.commerce.wa.gov.au/feeds/feed1.xml")
feed = Hpricot.XML(f1)
@Sutto
Sutto / app.rb
Created October 25, 2009 02:30 — forked from zacheryph/app.rb
require 'sinatra/base'
class Bacon < Sinatra::Base
enable :logging, :clean_trace
get '/' do
'Hello from Sinatra!'
end
end
#!/usr/bin/env zsh
if [[ -s "${TM_PROJECT_DIRECTORY}/.rvmrc" ]]
then
source "${TM_PROJECT_DIRECTORY}/.rvmrc"
fi
exec ruby "$@"
set :default_environment, {
'PATH' => '/home/joey/.rvm/gems/ree-1.8.7-2010.02@vk/bin:/home/joey/.rvm/gems/ree-1.8.7-2010.02@global/bin:/home/joey/.rvm/rubies/ree-1.8.7-2010.02/bin:/home/joey/.rvm/bin:$PATH',
'RUBY_VERSION' => 'ree-1.8.7-2010.02',
'GEM_HOME' => '/home/joey/.rvm/gems/ree-1.8.7-2010.02@vk',
'GEM_PATH' => '/home/joey/.rvm/gems/ree-1.8.7-2010.02@vk:/home/joey/.rvm/gems/ree-1.8.7-2010.0@global',
'BUNDLE_PATH' => '/home/joey/.rvm/gems/ree-1.8.7-2010.02@vk' # If you are using bundler.
}
#!/usr/bin/env bash
source "$HOME/.rvm/scripts/rvm"
if command -v __rvm_load_rvmrc >/dev/null; then
__rvm_load_rvmrc
fi
exec ruby "$@"
#!/usr/bin/env sh
source ~/.rvm/scripts/rvm
! command -v ruby >/dev/null 2>&1 || command -v ruby | grep -v rvm >/dev/null
echo "Result = $?"
echo "<pre>"
echo "rvm_path = '$rvm_path'"
echo "$rvm_environments_path"
echo "---"
rvm alias list
echo "--"