Skip to content

Instantly share code, notes, and snippets.

View neilmiddleton's full-sized avatar
🏠
Working from home

Neil Middleton neilmiddleton

🏠
Working from home
View GitHub Profile
## Rails Upgrade check
#
# Check your github repos for out of date rails apps
#
# usage: $ ENV=yourusername PASSWORD=yourpassword ruby railscheck.rb
# or
# usage: $ ENV=yourusername PASSWORD=yourpassword ORG=yourorgname ruby railscheck.rb
#
# n.b requires the octokit gem
@neilmiddleton
neilmiddleton / gist:4470806
Created January 6, 2013 22:43
Parse S3 URL for credentials
require 'uri'
if ENV.has_key? "BUCKET_URL"
uri = URI.parse(ENV["BUCKET_URL"])
ENV["S3_ACCESS_KEY"] = uri.user
ENV["S3_ACCESS_SECRET"] = uri.password
end
class ContactsController < ApplicationController
def create
@contact = Contact.new(params[:contact])
if @contact.valid?
ContactMailManager.delay.send_contact_mail(@contact)
redirect_to contact_path(1), :notice => t("contact.sent")
else
...
end
@neilmiddleton
neilmiddleton / gist:4135225
Created November 23, 2012 11:33
Globalize3 conditional migrations
unless MyModel::Translation.column_names.map(&:to_sym).include?(:new_attrib)
add_column MyModel::Translation.table_name, :new_attrib, :string
end
ActionView::Template::Error (Can't mass-assign protected attributes: locale):
1: <div id='recent_activity'>
2: <h2><%= t('.latest_activity') %></h2>
3: <% if (activity = @recent_activity.collect { |a|
4: activity_message_for(a)
5: }.reject(&:blank?)).present? %>
6: <ul class='clickable'>
7: <% activity.each do |message| %>
activemodel (3.2.8) lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
activemodel (3.2.8) lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
create table johns_problem as
select distinct trim(name) as name
from drugs
where customer_id IS NOT NULL
order by name;
select distinct name from drugs
-- delete table johns_problem
@neilmiddleton
neilmiddleton / gist:3811369
Created October 1, 2012 12:24
Report Mailer
@report = Reports::BusinessIntelligenceReport.new
@report.customer_id = customer_id.to_i
@report.start_date = Date.strptime(start_date, "%m/%d/%Y")
@report.end_date = Date.strptime(end_date, "%m/%d/%Y")
attachments['business_intelligence_report.csv'] = @report.to_csv
mail(to: email, subject: "Business Intelligence Report") do |format|
format.text
end
@neilmiddleton
neilmiddleton / gist:3157328
Created July 21, 2012 21:53
50 shades of grey
rgb(39,39,39) => #272727
rgb(40,40,40) => #282828
rgb(41,41,41) => #292929
rgb(43,43,43) => #2b2b2b
rgb(44,44,44) => #2c2c2c
rgb(46,46,46) => #2e2e2e
rgb(49,49,49) => #313131
rgb(50,50,50) => #323232
rgb(52,52,52) => #343434
rgb(53,53,53) => #353535
@neilmiddleton
neilmiddleton / gist:3012412
Created June 28, 2012 16:41
Use Ctrl+L to flip between absolute and relative line numbering in VIM
" use Ctrl+L to toggle the line number counting method
function! g:ToggleNuMode()
if(&rnu == 1)
set nu
else
set rnu
endif
endfunc
nnoremap <C-L> :call g:ToggleNuMode()<cr>
@neilmiddleton
neilmiddleton / gist:2841924
Created May 31, 2012 08:32
Create MEDRA database from Soc, PT and LLT
DROP TABLE IF EXISTS soc;
DROP TABLE IF EXISTS pt;
DROP TABLE IF EXISTS llt;
CREATE TABLE soc (
soc_code BIGINT constraint ix1_soc01 PRIMARY KEY,
soc_name varchar(100) constraint ix1_soc02 NOT NULL,
soc_abbrev varchar(5) NOT NULL,
soc_whoart_code varchar(7),
soc_harts_code BIGINT,