Skip to content

Instantly share code, notes, and snippets.

@andyh
andyh / ctrl.rb
Last active December 27, 2015 12:39 — forked from anonymous/ctrl.rb
def create
parent_resource = params[:parent_type].constantize
parent_id = params[:parent_id]
# both of the above values are empty because both params are not passed as parameters.
@comment = parent_resource.find(parent_id).comments.create(comment_params.merge(account: current_account))
respond_with :dashboard, @comment
end
@andyh
andyh / gist:6697426
Created September 25, 2013 09:49 — forked from ebinion/gist:5690817
UPDATE pg_database SET datallowconn = TRUE where datname = 'template0';
\c template0
UPDATE pg_database SET datistemplate = FALSE where datname = 'template1';
drop database template1;
create database template1 with template = template0 encoding = 'UNICODE' LC_CTYPE = 'en_US.UTF-8' LC_COLLATE = 'C';
UPDATE pg_database SET datistemplate = TRUE where datname = 'template1';
\c template1
UPDATE pg_database SET datallowconn = FALSE where datname = 'template0';
class Api::TradesController < ApplicationController
respond_to :json
def index
render json: DataTable.new(Trade, params)
end
def create
trade = Trade.new(safe_params)
trade.save
class SpreadsheetTagService
include Roo
def initialize(uploaded_file)
@spreadsheet = open_spreadsheet(uploaded_file)
do_stuff
end
private
def do_stuff
@andyh
andyh / books.md
Created May 18, 2013 16:11
Programming Book List

Ruby Oriented

  • Beginning Ruby
  • Practical Object-Oriented Design in Ruby
  • Programming Ruby (aka the pickaxe book)
  • The RSpec Book
  • Everyday Scripting with Ruby
  • Refactoring Ruby
  • Design Patterns in Ruby
  • Exceptional Ruby
@andyh
andyh / wmrug-meetup-ideas.md
Created May 17, 2013 09:00
WMRUG Meetup Talk & Activity Ideas

Talks

  • Ruby Refactoring Techniques (Series)
  • What's new in Ruby 2.0?
  • Learning Ruby series for newcomers to the language

Activities

  • Group coding kata's (e.g. cyber-dojo.com)
  • Battleships or other code competitions
class HospitalBooking
def self.send_overtime_mail(user, bookings)
OvertimeMailer.overtime_pdf(user, hospital_booking).deliver
end
end
class ApplicationController...
def clear_cart
@cart.destroy
session[:cart_id] = nil
end
end
@andyh
andyh / open_uri.rb
Last active December 15, 2015 05:49 — forked from anonymous/open_uri.rb
require 'spec_helper'
require 'open-uri'
it 'sends get request to web.memc to invoke the php script create_user_with_hashed_password - then validates the password in rails' do
password = 'testphp'
open_uri_result = ''
expect do
open("http://web.memc/create_user_with_hashed_password.php?password=#{password}").each do |f|
open_uri_result << f
end
class AccountsController < ApplicationController
load_and_authorize_resource
# do not need to be logged in for :new or :create
skip_before_filter :authorize_user, only: [:new, :create]
def new
@account.users.build
@account.offices.build
@account.phone_numbers.build