Skip to content

Instantly share code, notes, and snippets.

View reggieb's full-sized avatar

Rob Nichols reggieb

View GitHub Profile
@reggieb
reggieb / self_assessment.conf
Created June 7, 2013 08:59
A passenger apache directive, used on my development PC so that I can mimic the production environment and debug errors caused by the app being hosed in a sub-uri. For example, issues with redirects going to http root rather than app root.
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/rob/public_html
<Directory /home/rob/public_html>
Allow from all
</Directory>
RackBaseURI /self_assessment
<Directory /home/rob/web/select_assessment>
@reggieb
reggieb / overwrite_class.rb
Last active December 15, 2015 17:49
An example of how a class can be replaced with a modified version within a name space.
class Thing
def colour
'blue'
end
def who
self.class.to_s
end
def output(line)
@reggieb
reggieb / display_readme.rb
Created February 8, 2013 16:06
I'm getting tired of not being quite sure how my README.rdoc will appear when loaded onto github. By adding this to the root of my app, I can 'ruby display_readme.rb' to see the rendered README.rdoc at localhost:4567
require 'sinatra'
require 'rdoc/markup/to_html'
get '/' do
input_string = ""
parser = RDoc::Markup::ToHtml.new
File.open("README.rdoc", "r") do |file|
file.each_line{|l| input_string << l}
end
@reggieb
reggieb / split_collection_into_columns.html.erb
Last active December 9, 2015 21:08
Split a collection of items so that they can be displayed within two column divs
<% number_of_columns = 2 %>
<div class="columns">
<% @things.each_slice((@things.length / number_of_columns.to_f).ceil) do |column_of_things| %>
<div class ="column">
<% column_of_things.each do |thing| %>
<%= thing.title %>
<% end %>
</div>
<% end %>
</div>
@reggieb
reggieb / time_formats.rb
Last active March 21, 2023 10:57
Sample time format initializer for rails apps
# Used to create time and datetime formatting short cuts. Search for to_formatted_s in the api
# Also see http://snippets.dzone.com/posts/show/2406
# If time = Time.local(2009,12,24,15,30,27)
Time::DATE_FORMATS[:datetime] = "%H:%M %d-%b-%Y" # time.to_s(:datetime) ----> 15:30 24-Dec-2009
Time::DATE_FORMATS[:date] = "%d-%b-%Y" # time.to_s(:date) ----> 24-Dec-2009
Time::DATE_FORMATS[:time] = "%H:%M" # time.to_s(:time) ----> 15:30
Time::DATE_FORMATS[:google] = "%Y-%m-%d %H:%M:%S" # time.to_s(:google) ----> 2009-12-24 15:30:27