how long will it last before it’s rewritten? Once it’s in production, how will its execution affect resource usage? How much so I expect CPU/memory/disk/network to increase or decrease? Will others be able to understand this code? Am I making it as easy as I can for others to extend or introspect this work?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/views/layouts/application.html.erb | |
<%= render_stylesheets content_for(:stylesheets) %> | |
# app/helpers/layout_helper.rb | |
def render_stylesheets(tag_html = nil) | |
html = [] | |
if tag_html.present? | |
html << tag_html | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://blog.arkency.com/2014/04/mastering-rails-validations-contexts/ | |
# http://blog.arkency.com/2014/05/mastering-rails-validations-objectify/ | |
# The idea was, that it should not be possible to delete user who already took part of some important business activity. | |
class User < ActiveRecord::Base | |
has_many :invoices | |
validate :does_not_have_any_invoice, on: :destroy | |
def destroy | |
transaction do |
http://www.reinteractive.net/posts/116-12-tips-for-the-rails-asset-pipeline
- Every file that is not a Javascript file or CSS file that is in the app/assets folder will be copied by Rails into the public/assets folder when you compile your assets.
- config.assets.compile
- If it is set to "true" (which it is by default in development) then Rails will try to find a Javascript or CSS file by first looking in the public/assets directory and if it can't find it, will hunt through your app/assets folder looking for the file. If it finds it in app/assets it will go ahead and compile on the fly and then serve this asset up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://makandracards.com/makandra/17751-render-a-view-from-a-model-in-rails | |
# https://github.com/yappbox/render_anywhere | |
# http://stackoverflow.com/questions/18263220/rendering-partials-view-in-a-rake-task-background-job-model-in-rails-4 | |
# http://ruby-china.org/topics/12193 | |
# http://alphahydrae.com/2013/06/rails-3-rendering-views-outside-a-controller/ | |
def render_to_string(options = {}) | |
av = ActionView::Base.new(ActionController::Base.view_paths) | |
av.extend TranslationHelper | |
av.render(:template => "contacts/index.pdf.erb", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/princely/asset_support.rb | |
# Rails.application.assets.find_asset is useful to find asset. | |
# you could get the content through | |
# Rails.application.assets.find_asset('analytics.css.sass').body | |
# get pathname through | |
# Rails.application.assets.find_asset('analytics.css.sass').pathname | |
def asset_file_path(asset) | |
# Remove /assets/ from generated names and try and find a matching asset | |
Rails.application.assets.find_asset(asset.gsub(%r{/assets/}, "")).try(:pathname) || asset | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the prefix to ^A. | |
unbind C-b | |
set -g prefix ^a | |
set -g base-index 1 | |
# other ^A | |
unbind ^A | |
bind ^A last-window |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# require 'rubygems' | |
require 'mechanize' | |
require 'debugger' | |
require 'sidekiq' | |
# Sidekiq server is multi-threaded so our Redis connection pool size defaults to concurrency (-c) | |
Sidekiq.configure_server do |config| | |
config.redis = { :namespace => 'treehouse', :url => 'redis://127.0.0.1:6379' } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The user order I want | |
ids = [1, 3, 5, 9, 6, 2] | |
indexed_people = Person.find(ids).index_by(&:id) | |
people_in_order = indexed_people.values_at(*ids) |
require "i18n" rescue LoadError
module Money::Currency::Loader
extend self
DATA_PATH = File.expand_path("../../../../config", __FILE__)