Skip to content

Instantly share code, notes, and snippets.

View averyvery's full-sized avatar

Doug Avery averyvery

View GitHub Profile
@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
@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?

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 / distribute.sass
Last active August 29, 2015 14:12
Smooth CSS property distribution with media queries
=distribute($property, $min, $max, $start, $end, $precision, $metric)
#{$property}: $min
// get the range we're operating on
$range: $end - $start
// get the number of iterations we need to run by seeing how precise we should be
$loops: strip-units(ceil($range / $precision)) - 1
▓█████▄ ▒█████ █ ██ ▄████ ▄▄▄ ██▒ █▓▓█████ ██▀███ ▓██ ██▓
▒██▀ ██▌▒██▒ ██▒ ██ ▓██▒ ██▒ ▀█▒ ▒████▄ ▓██░ █▒▓█ ▀ ▓██ ▒ ██▒▒██ ██▒
░██ █▌▒██░ ██▒▓██ ▒██░▒██░▄▄▄░ ▒██ ▀█▄▓██ █▒░▒███ ▓██ ░▄█ ▒ ▒██ ██░
░▓█▄ ▌▒██ ██░▓▓█ ░██░░▓█ ██▓ ░██▄▄▄▄██▒██ █░░▒▓█ ▄ ▒██▀▀█▄ ░ ▐██▓░
░▒████▓ ░ ████▓▒░▒▒█████▓ ░▒▓███▀▒ ▓█ ▓██▒▒▀█░ ░▒████▒░██▓ ▒██▒ ░ ██▒▓░
▒▒▓ ▒ ░ ▒░▒░▒░ ░▒▓▒ ▒ ▒ ░▒ ▒ ▒▒ ▓▒█░░ ▐░ ░░ ▒░ ░░ ▒▓ ░▒▓░ ██▒▒▒
░ ▒ ▒ ░ ▒ ▒░ ░░▒░ ░ ░ ░ ░ ▒ ▒▒ ░░ ░░ ░ ░ ░ ░▒ ░ ▒░▓██ ░▒░
░ ░ ░ ░ ░ ░ ▒ ░░░ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░░ ░ ▒ ▒ ░░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
░ ░ ░ ░
module.exports = React.createClass({
getInitialState() {
return {
usingMouse : false,
focusedOnElement : false
}
},
_setUsingMouse(usingMouse) {
this.setState({usingMouse: usingMouse})
@averyvery
averyvery / svg.jsx
Created April 14, 2015 18:42
svg.jsx
// option for inlining (for index)
// option for caching (for SVGs used more than once)
export default React.createClass({
getInitialState() {
return {
svg: ''
}
},
import store from 'data/store'
import browser from 'browser'
import Intro from './Intro'
import LevelEnd from './LevelEnd'
import Questions from './Questions'
import TimeoutTransitionGroup from 'vendor/timeout-transition-group'
export default React.createClass({
_getScreen() {
const level = store.getLevel(this.props.level)
<!DOCTYPE HTML>
<html>
<body>
<form>
<input type="date" /><br />
<input type="number" min="5" max="15" step="3" required/><br />
<input type="month" /><br />
<input type="email" autofocus /><br />
/Library/Ruby/Site/1.8/rubygems/dependency.rb:52:in `initialize': Valid types are [:development, :runtime], not nil (ArgumentError)
from /Users/dougavery/.rvm/gems/ruby-1.9.2-p290@opower/gems/bundler-1.0.18/lib/bundler/resolver.rb:352:in `new'
from /Users/dougavery/.rvm/gems/ruby-1.9.2-p290@opower/gems/bundler-1.0.18/lib/bundler/resolver.rb:352:in `search'
from /Users/dougavery/.rvm/gems/ruby-1.9.2-p290@opower/gems/bundler-1.0.18/lib/bundler/resolver.rb:346:in `gems_size'
from /Users/dougavery/.rvm/gems/ruby-1.9.2-p290@opower/gems/bundler-1.0.18/lib/bundler/resolver.rb:179:in `resolve'
from /Library/Ruby/Site/1.8/rubygems/source_index.rb:95:in `sort_by'
from /Users/dougavery/.rvm/gems/ruby-1.9.2-p290@opower/gems/bundler-1.0.18/lib/bundler/resolver.rb:175:in `each'
from /Users/dougavery/.rvm/gems/ruby-1.9.2-p290@opower/gems/bundler-1.0.18/lib/bundler/resolver.rb:175:in `sort_by'
from /Users/dougavery/.rvm/gems/ruby-1.9.2-p290@opower/gems/bundler-1.0.18/lib/bundler/resolver.rb:175:in `resolve'
from /Us