Skip to content

Instantly share code, notes, and snippets.

View stevenharman's full-sized avatar

Steven Harman stevenharman

View GitHub Profile
@jeremy
jeremy / gist:4211803
Created December 5, 2012 03:05
Template- and asset-aware ETags

Declared ETags, together with Russian Doll caching, can be used to automatically mix your template and asset versions into the ETags set in your controllers. This avoids the need to blow all browser caches on each deploy and neatly contains the scope of "freshness fallout" when you tweak a view.

To include the template's version in the ETag:

  # Incorporate the cache version for this action into our ETag.
  # This allows template changes to bubble up into HTTP cache
  # freshness and bust browser caches when we make changes.
  etag do
    begin
db/schema.rb merge=railsschema
@practicingruby
practicingruby / mrdi.md
Created December 19, 2012 22:29
Models, Roles, Decorators, and Interactions -- A modest proposal for a toned done version of DCI that isn't as janky as Concerns.

Models, Roles, Decorators, and Interactions

A modest alternative to DCI that might be worth further thought

One of the problems with advancing the discussion on DCI is that we lack a comparable alternative pattern that has the same goals, but favors a low ceremony approach. The closest thing we have to that is Rails concerns, but they are more like distant relatives of the DCI concepts rather than first cousins, and that makes comparisions between the two approaches not especially fruitful.

I am considering the idea of experimenting with my own paradigm that captures the intent and purity of DCI, but with the convenience of concerns. Please note that this is just the starting point of a conversation, it is NOT a promise of comercially available cold fusion or a cure for cancer. It's just a gist with an idea on it I'd like to hear your thoughts on.

What if we had a top-level topology that was split into Models, **Rol

= simple_form_for @sign_up, url: sign_up_path, html: { class: "form-horizontal" } do |form|
= form.simple_fields_for @sign_up.customer do |fields|
= fields.input :first_name
= fields.input :last_name, label: false
= form.simple_fields_for @sign_up.user do |fields|
= fields.input :email
= fields.input :password
= form.simple_fields_for @sign_up.customer do |fields|
= fields.input :zip_code
.form-actions
gem 'rails', '3.2.12' # change version to 3.2.11 to see this working, 3.2.12 is broken
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
ActiveRecord::Schema.define do
create_table :users, :force => true do |t|
@mudge
mudge / en.rb
Last active September 5, 2023 09:32
Using date ordinals in Rails through an I18n time format.
# This goes in config/locales/en.rb (*not* en.yml)
{
:en => {
:time => {
:formats => {
:full => lambda { |time, _| "%H:%M | %A, #{time.day.ordinalize} %B %Y" }
}
}
}
}
@searls
searls / git-unmaster
Created March 27, 2013 14:07
A git command for logging all the commits on the current branch that are not on your first master as of your nearest common ancestor. Additional git-log flags come along for the ride (e.g. `git unmaster --oneline`)
#!/bin/sh
git log HEAD ^$(git merge-base master HEAD) --no-merges $1
@avdi
avdi / macro_modules.rb
Last active August 29, 2018 07:43
Modules for macros. In reference to: http://thepugautomatic.com/2013/07/dsom/
class SomeORM
def self.attributes(*names)
if const_defined?(:DynamicAttributes, false)
mod = const_get(:DynamicAttributes)
else
mod = const_set(:DynamicAttributes, Module.new)
include mod
end
mod.module_eval do
names.each do |name|
@lisamelton
lisamelton / transcode-video.sh
Last active May 24, 2024 17:42
Transcode video file (works best with Blu-ray or DVD rip) into MP4 (or optionally Matroska) format, with configuration and at bitrate similar to popular online downloads.
#!/bin/bash
#
# transcode-video.sh
#
# Copyright (c) 2013-2015 Don Melton
#
about() {
cat <<EOF
$program 5.13 of April 8, 2015
c.filter_sensitive_data('<AUTH FILTERED>') {|interaction|
Array(interaction.request.headers['Authorization']).first
}