Skip to content

Instantly share code, notes, and snippets.

View wrburgess's full-sized avatar
:shipit:
Shippin'

Randy Burgess wrburgess

:shipit:
Shippin'
View GitHub Profile
@wrburgess
wrburgess / drupal_detect_front_page.php
Created October 8, 2011 19:12
Drupal detect front page
If($is_front){
// do something;
} else {
// do something;
}
@wrburgess
wrburgess / drupal_print_node_array_contents.php
Created October 8, 2011 19:14
Drupal print node contents
print_r($node);
@wrburgess
wrburgess / gist:1337891
Created November 3, 2011 21:49
Rails Contact Form w/ Gmail SMTP
# Majority of this solution was written and posted here:
# http://matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3
# http://railscasts.com/episodes/206-action-mailer-in-rails-3
# config/initializers/smtp_settings.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
@wrburgess
wrburgess / gist:1342076
Created November 5, 2011 21:56
rails controller response formats
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @model }
end
@wrburgess
wrburgess / gist:1344035
Created November 7, 2011 02:08
return copyright declaration with current year
# return copyright declaration with current year
def copyright
copyright = '© '.html_safe + Time.new.strftime('%Y') + ' [Company]. All Rights Reserved'
end
@wrburgess
wrburgess / gist:1344044
Created November 7, 2011 02:11
return a title on a per-page basis
# return a title on a per-page basis
def title
base_title = "[Site Name]"
if @title.nil?
base_title
else
"#{base_title} | #{@title}"
end
end
@wrburgess
wrburgess / gist:1344048
Created November 7, 2011 02:12
return body class for markup
# return body class for markup
def body_class
base_body_class = "[site-name]"
if @body_class.nil?
base_body_class
else
base_body_class + " #{@body_class}"
end
end
@wrburgess
wrburgess / gist:1344105
Created November 7, 2011 03:17
concatenate a user model first and last name
# concatenate a user model's first and last name, include middle name or suffix if required
# may consider abbreviating the middle name
def fullname
if middlename.nil? then
fullname = firstname + ' ' + lastname
else
fullname = firstname + ' ' + middlename + ' ' + lastname
end
@wrburgess
wrburgess / gist:1344108
Created November 7, 2011 03:19
cli for ubuntu package manager update and upgrade
#simple cli for updating ubuntu
$ apt-get update && apt-get upgrade
@wrburgess
wrburgess / nokogiri_xml_import_example.rb
Created December 15, 2011 15:27
Use Nokogiri to import an xml file
require 'rubygems'
require 'nokogiri'
require 'open-uri'
Model.delete_all #if refreshing
doc = Nokogiri::XML(File.read("app/assets/files/example.xml"))
@doc = doc.xpath('//node_name').each do |record|
Model.create(
:column1 => record.at('@element_id').text,
:column2 => record.at('node_name').text,