Skip to content

Instantly share code, notes, and snippets.

View reggieb's full-sized avatar

Rob Nichols reggieb

View GitHub Profile
@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
@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 / 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 / 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 / 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 / curl_typhoeus_config_issue
Created July 1, 2013 08:15
I think I have something miss-configured in my curl setup and it is causing errors when loading typhoeus
require 'typhoeus'
LoadError: Could not open library 'libcurl': libcurl: cannot open shared object file: No such file or directory.
Could not open library 'libcurl.so': /lib/i386-linux-gnu/libssl.so.1.0.0: symbol CRYPTO_memcmp, version OPENSSL_1.0.0 not defined in file libcrypto.so.1.0.0 with link time reference
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/ffi-1.1.5/lib/ffi/library.rb:121:in `block in ffi_lib'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/ffi-1.1.5/lib/ffi/library.rb:88:in `map'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/ffi-1.1.5/lib/ffi/library.rb:88:in `ffi_lib'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/typhoeus-0.4.2/lib/typhoeus/curl.rb:405:in `<module:Curl>'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/typhoeus-0.4.2/lib/typhoeus/curl.rb:6:in `<module:Typhoeus>'
from /home/rob/.rvm/gems/ruby-1.9.3-p286@DbpediaConceptSearch/gems/typhoeus-0.4.2/lib/typhoeus/curl.rb:5:in
@reggieb
reggieb / JQuery version
Created July 15, 2013 08:20
Display the current JQuery version within a rails view
jQuery <span id='jquery_version'></span>
<%= javascript_tag do %>
var jQueryVersion = jQuery.fn.jquery;
$('#jquery_version').html(jQueryVersion);
<% end %>
@reggieb
reggieb / google_contact_list
Last active December 25, 2015 16:48
Get a user's google contacts using their valid access token (so they only need to authenticate once)
require "net/http"
require "rexml/document"
class GoogleContactList
attr_reader :token
attr_accessor :response
class << self
def cache
@reggieb
reggieb / hostess.rb
Created November 11, 2013 08:52
geminabox hostess. Version at point where rolled back to just proxy bundler actions.
require 'sinatra/base'
require 'httpclient'
module Geminabox
class Hostess < Sinatra::Base
%w[/specs.4.8.gz
/latest_specs.4.8.gz
/prerelease_specs.4.8.gz
#!/bin/bash
# usage: $0 source_dir [source_dir] ...
# where source_dir args are directories containing git repositories
red="\033[00;31m"
green="\033[00;32m"
yellow="\033[00;33m"
blue="\033[00;34m"
purple="\033[00;35m"