Skip to content

Instantly share code, notes, and snippets.

View bsodmike's full-sized avatar

Michael de Silva bsodmike

View GitHub Profile
@bsodmike
bsodmike / howto.md
Last active August 30, 2017 04:15
HOWTO: Setup mail forwarding with Sendmail in Ubuntu 10.04 LTS

Copyright (c) 2011, Michael de Silva (michael@mwdesilva.com) Blog: http://www.bsodmike.com ~ Twitter: @bsodmike

Fix: 'config error: mail loops back to me (MX problem?)'

To prevent receiving config error: mail loops back to me (MX problem?) errors, you need to add each virtualdomain.tld to the /etc/mail/local-host-names file and re-compile your sendmail config via make.

You have asked mail to a domain (e.g., domain.net) to be forwarded to a specific host (in this case, relay.domain.net) by using an MX record, but the relay machine doesn't recognise itself as domain.net. Add domain.net to /etc/mail/local-host-names [known as /etc/sendmail.cw prior to version 8.10] (if you are using FEATURE(`use_cw_file')) or add "Cw domain.net" to your configuration file.

Source: http://www.sendmail.com/sm/open_source/support/support_faq/general_issues_faq/#4.5

@bsodmike
bsodmike / gist:1012044
Created June 7, 2011 11:12
How to find out everything you can override in a refinerycms project
cd /tmp
refinerycms bar
cd bar
git init .
git add .
git commit -a -m "Hide these files"
rake refinery:override view=**/*
rake refinery:override controller=**/*
rake refinery:override model=**/*
git add -N .
# create methods in an object’s singleton class
# by adding the object reference to the method definition
# class Test
# @var = 99
# def self.var
# @var
# end
# def self.var=(var)
# @var = var
# end
@bsodmike
bsodmike / messages_controller.rb
Created June 17, 2011 04:55
app/mailer/notifier.rb
class MessagesController < ApplicationController
def index
new
render :new
end
def new
@message = Message.new
end
@bsodmike
bsodmike / gist:1035875
Created June 20, 2011 15:58
Revised take on the authentications_controller incorporating Authentication from scratch and Omniauth

See lines 11-15 of authentications_controller.rb. Excerpt shown below

def create
  omniauth = request.env["omniauth.auth"]
  authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
  # give a user account priority over authentications; therefore, 
  # merge the authentication with the signed in account.
  if current_user && authentication
    authentication.update_attribute(:user_id, current_user.id)

session[:user_id] = current_user.id

@bsodmike
bsodmike / gist:1037846
Created June 21, 2011 13:24
DRYing out database.yml (DRY) in Rails 3.1

Note that Rails 3.1 uses Psych instead of Syck as its YAML parser. Stick YAML::ENGINE.yamler = "syck" at the top of config/application.rb

This would still work

login: &login
  adapter: mysql
  username: username
  password: password
 host: mysql.example.com
@bsodmike
bsodmike / gist:1039964
Created June 22, 2011 12:27
Correctly backing up and restoring MySQL DBs

Correctly backing up and restoring MySQL DBs

Backing up all databases to a dumpfile

mysqldump -A --add-drop-table -u root | gzip > $OUTFILE

Restoring a select database

Make sure to pass the -o flag to denote

--one-database, -o

@bsodmike
bsodmike / spec_helper.rb
Created June 27, 2011 10:52
RSpec + Cucumber BDD Stack for Rails 3 with Spork and Guard

RSpec + Cucumber BDD Stack for Rails 3 with Spork and Guard

Steps to follow, Ref:

  • Update Gemfile
  • bundle install
  • rails g rspec:install
  • Edit .rspec
# I deleted this...
commit 94915c43fbe47e3a0f7dbb81affdd0106ba4a72c
Author: Daniel <znowm4n@gmail.com>
Date: Tue Jul 5 20:56:23 2011 +0200
update
diff --git a/app/views/layouts/_menu.haml b/app/views/layouts/_menu.haml
index 0a4d03f..8ea6eff 100644
@bsodmike
bsodmike / gist:1068376
Created July 6, 2011 21:29 — forked from tshddx/gist:1068361
Rails. Render a layout outside a controller, with text and locals
av = ActionView::Base.new(Rails::Configuration.new.view_path)
av.render(
{:text => this_goes_to_yield, :layout => "layouts/blah.html.erb"}, # the options hash
{:title => 'blah', :body => 'hello'} # the locals hash
)