Skip to content

Instantly share code, notes, and snippets.

@kbaum
kbaum / db_params
Last active December 13, 2017 17:10
Pull out attributes of a postgres url
#!/usr/bin/env ruby
require 'uri'
uri = URI(ARGV[0])
props = {username: uri.user, password: uri.password, host: uri.host, port: uri.port, database: uri.path[1..-1]}
props.each do |key, value|
puts "#{key}=#{props[key]}"
end
class RenameClientCompanyToAccount < ActiveRecord::Migration
def change
safety_assured do
reversible do |dir|
dir.down { update_view :lease_connections, version: 6, revert_to_version: 7 }
end
#if table_exists?(:admin_add_user_to_property_requests) && column_exists?(:admin_add_user_to_property_requests, :client_company_id)
rename_column :admin_add_user_to_property_requests, :client_company_id, :account_id
#end
module Middleware
module Server
class SidekiqNewrelic
def call(worker, msg, queue)
::NewRelic::Agent.add_custom_attributes({
queue: queue
})
yield
end
end
@kbaum
kbaum / Include_or_join.md
Last active May 10, 2016 13:39
To include or to join

Take this rails/squeel code:

UserProperty.includes(:user).where{user.id != nil}

Sometimes it works and sometimes it doesn't. Why? Under the hood, rails makes a decision. Should we do this with an eager_load or a preload? What does this mean?

If we change it to:

gem 'flamegraph'
gem 'rack-mini-profiler'
gem 'stackprof'
gem 'memory_profiler'
def query_params_to_query(request)
query_params = request.params.except(:path, :format)
query_params.any? ? "?#{query_params.to_query}" : ""
end
#redirect apex http://viewthespace.com http://vts.com domain to www.vts.com
constraints(host: %r{^vts.com}) do
redirect_action = ->(params, _request) do
"https://www.vts.com/#{params[:path]}#{query_params_to_query(_request)}"
end
$ heroku certs -a vts
Endpoint Common Name(s) Expires Trusted
----------------- ------------------ -------------------- -------
vts.herokuapp.com *.vts.com, vts.com 2016-01-08 23:59 UTC True
aws iam upload-server-certificate \
--server-certificate-name vts_com \
--certificate-body file://vts_com.crt \
--private-key file://vts_com.key \
--certificate-chain file://vts_com_bundle.pem \
--path /cloudfront/
@kbaum
kbaum / _portfolio_search_results.html.haml
Created December 10, 2013 23:45
portfolio search results
- if portfolio_properties.any?
%fieldset#portfolio-properties
= paginate portfolio_properties
= render partial: 'portfolio_properties', collection: portfolio_properties, as: :property
= paginate portfolio_properties
@kbaum
kbaum / my_portfolio_controller.rb
Last active December 30, 2015 23:39
my portfolio optimized
class MyPortfoliosController < ApplicationController
before_filter :authenticate_user!
helper_method :portfolio_spaces
helper_method :portfolio_properties
def show
end