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
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
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'
@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
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: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
## 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
Writing is hard, so do it.
==========================
Over the last few months I've been working on something that I wouldn't have seen myself doing at any point in my life, and that's the task of writing a book. I'm not talking about a 'Janet & John' novel, or some sort of 'Fifty Shades of Grey' sort of affair, but a proper printed dead tree, trip over it, technical book.
It all started back in May/June time when I was approached by a good friend at [Heroku](http://www.heroku.com), who had been approached in turn by [O'Reilly](http://www.oreilly.com), to produce a book about the platform and some rough ideas for what sort of book might be relevant and saleable. At the end of a fairly lengthy process it ended up that I was the author, had a contract in my hand and a schedule to try and stick to.
Cripes
## Getting started
class Array
def foo
puts self
end
end
class Bar < ActiveRecord::Base
...blah
end
LOG: could not bind IPv4 socket: Can't assign requested address
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
$ ~/ nslookup
> server 8.8.8.8
Default server: 8.8.8.8
Address: 8.8.8.8#53
> o localhost
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: o.dev.kyanmedia.net