Skip to content

Instantly share code, notes, and snippets.

View toolmantim's full-sized avatar
:shipit:
🎉

Tim Lucas toolmantim

:shipit:
🎉
View GitHub Profile
@toolmantim
toolmantim / production.rb
Created December 20, 2012 23:40
How to serve up JS assets from your app URL, and all other assets from a CDN
# Serve images and stylesheets (but not JS files) from a CDN
config.action_controller.asset_host = Proc.new {|source|
source !~ /\.js$/ ? "mycdn.com" : nil
}
@toolmantim
toolmantim / 1 Readme.md
Created July 26, 2012 19:39
Minification with newlines using the Rails 3 asset pipeline

Retaining line numbers with the Rails asset pipeline

By default the Rails 3 asset pipeline uses the Uglifier gem to optimize and minify your Javascript. One of its many optimisations is to remove all whitespace, turning your Javascript into one very long line of code.

Whist removing all the newlines helps to reduce the file size, it has the disadvantage of making your Javascript harder to debug. If you've tried to track down Javascript errors in minified Javascript files you'll know the lack of whitespace does make life harder.

Luckily there is a simple solution: to configure Uglifier to add newlines back into the code after it performs its optimisations. And if you're serving your files correctly gzip'd, the newlines add only a small increase to the final file size.

You can configure Uglifier to add the newlines by setting the following in your Rails 3 config/production.rb file:

@toolmantim
toolmantim / application.rb
Created May 10, 2012 13:34
There's gotta be a better way to silence the Rails 3.2 vendor/plugin deprecation warnings from Heroku's plugin injection
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Silence deprecation warnings until Heroku stops injecting plugins into
# vendor/plugins
if Rails.env.production?
ActiveSupport::Deprecation.silenced = true
end
@toolmantim
toolmantim / router.coffee
Created April 25, 2012 14:46
A Backbone.js router subclass that disables the hash fallback mechanism in favour of just navigating to the location (just like a normal link would behave)
class MyApp.Router extends Backbone.Router
hasPushState: window.history and window.history.pushState
# Override the navigate function to remove Backbone's #hash fallback for
# non-pushState browsers. Instead we just navigate to the new location using
# window.location
navigate: (fragment, trigger) ->
if @hasPushState
super(arguments...)
@toolmantim
toolmantim / simpler_goliath_test_helpers.rb
Created March 25, 2012 18:57
Simpler test helpers for Goliath
# Additional methods for Goliath::TestHelper to make simple Goliath testing
# simple. You might need the other syntax for testing gnarly stuff, but I've
# yet to need it. To use, just include this in your spec_helper.rb.
#
# Your spec must respond to #api and return the Goliath API class to test.
#
# @example
# describe MyAPI do
# let(:api) { MyAPI }
# describe "GET /" do
@toolmantim
toolmantim / profile.rb
Created September 7, 2011 11:05
TimeWithZone marshalling slow down
# re. commit
# https://github.com/rails/rails/commit/0d3615f04c79f6e90d8ab33fdfc920b8faac9cb8
#
# Example of the slowdown if you `require 'tzinfo'` every time Time.find_zone is called
#
# This became a big problem when unmarshal'ing TimeWithZone objects, in say a Rails action, from memcache. 500ms was added to every request.
#
# e.g. of the problem:
#
# ActiveSupport::TimeWithZone#marshal_load calls
def pluralize(number, singular)
<<-HTML
<span class="#{singular.downcase}">
#{number}
<span>#{number == 1 ? singular : singular.pluralize}</span>
</span>
HTML
end
# An example of rolling your own simple content_for helper in Sinatra
helpers do
def content_for(key, &block)
@content ||= {}
@content[key] = capture_haml(&block)
end
def content(key)
@content && @content[key]
end
end

(a gist based on the old toolmantim article on setting up remote repos)

To collaborate in a distributed development process you’ll need to push code to remotely accessible repositories.

This is somewhat of a follow-up to the previous article setting up a new rails app with git.

For the impatient

Set up the new bare repo on the server: