Skip to content

Instantly share code, notes, and snippets.

View averyvery's full-sized avatar

Doug Avery averyvery

View GitHub Profile
@averyvery
averyvery / load-view-specific-css.rb
Last active October 30, 2017 14:27
Load view-specific CSS in Rails
def view_css
path = "views/#{params[:controller]}/#{params[:action]}"
stylesheet_link_tag(path) unless Rails.application.assets.find_asset(path).nil?
end
@averyvery
averyvery / application.rb
Last active April 4, 2023 15:02
Inline CSS or JS in Rails
config.assets.precompile += [
# precompile any CSS or JS file that doesn't start with _
/(^inline[^_\/]|\/[^_])[^\/]*.(js|css)$/,
...

Create a shallow clone with the last fifty commits. git clone --depth 50 some-repository

Open the current diff in the editor. git add -e

View ALL branches: git branch -a master

Fetch changes from all remote repositories.

@averyvery
averyvery / production-mode.md
Last active August 29, 2015 14:02
"Production mode" in a Rails development environment

Why do this?

  • Performance evaluation. Without minification and gzip, you can't always make accurate decisions regarding filesize changes, or do reasonable network speed testing locally.
  • Cache-busting. By compiling your files and saving them with unique names, you're removing the need to clear the browser cache when testing on mobile devices and in older IE.
  • Catching bugs.
    • This is rarer now than it used to be, but uglify has historically created occasional issues in IE8. Better to catch them locally than on integration.
    • Running in production mode exposes problems related to explicit filenames, since a production deploy can change filenames and break related code.

Okay, how do I do it?

@averyvery
averyvery / development.rb
Created April 18, 2014 15:28
Testing Rails precompilation in development environment
# just add these lines to development.rb
config.assets.debug = false
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.digest = true
# then on the command line
rake assets:precompile && rails s
// Macro: "data-track-gtm - get from element"
// Returns: Boolean - does this element, or one of its parents, have a data-track-gtm attribute?
function() {
var isSet = function(val) {
return val !== null && val !== '';
};
var el = {{element}};
var val = el.getAttribute('data-track-gtm');
while (el && el !== document.body && !isSet(val)) {
@averyvery
averyvery / resize_mobile_images.rb
Created February 20, 2013 21:48
Save resized copies of retina images at regular size.
require 'rmagick'
source = ARGV[0]
Dir.glob('images/' + source + '/*.*').each do |retina_path|
mobile_path = retina_path.sub(/retina/, 'normal')
retina_file = File.new(retina_path)
mobile_file = File.new(mobile_path) if File.exist?(mobile_path)
.shureicons-font {
font-family: 'shureicons';
-webkit-font-smoothing: subpixel-antialiased;
}
@mixin logo($height) {
@include box-sizing(border-box);
display: block;
height: $height;
padding-top: $height;
@averyvery
averyvery / workflow.textile
Created October 11, 2012 20:04
workflow.textile

Viget’s EE Development Workflow

Goals

  • Optimize for local-first development
  • Manage and sync multiple instances of an EE site
  • Deploy from git
  • Work from files, not the DB, wherever possible

EE’s database

<!doctype html>
<html>
<head>
<title>Easy GA debugging - to test, add ?ga_debug to the URL</title>
<script>
var _gaq = _gaq || [];
var _ga_debug = window.location.href.indexOf('ga_debug') !== -1;
_gaq.push(['_setAccount', 'UA-00000000-1']);
_gaq.push(['_trackPageview']);