Skip to content

Instantly share code, notes, and snippets.

View averyvery's full-sized avatar

Doug Avery averyvery

View GitHub Profile
@averyvery
averyvery / index.html
Created January 13, 2012 21:27
Tracking Window Dimensions with GA
<!DOCTYPE HTML>
<html>
<head>
<title>Tracking Window Size</title>
</head>
<body>
<script type="text/javascript">
var _gaq = _gaq || [];
@averyvery
averyvery / gist:1665543
Created January 23, 2012 21:09
Trackiffer Snippets
// tracking page title and url
'a' : ['_trackEvent', 'foo', document.title, window.location.url]
// tracking a concatenated string
'a' : ['_trackEvent', 'foo', document.title + ' page', 'bar']
// tracking a non-interaction event - set the sixth value to true
'a' : ['_trackEvent', 'foo', 'bar', 'foobar', undefined, true]
// tracking a click on a JS interaction
@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)$/,
...
@averyvery
averyvery / seeds.rb
Created April 11, 2012 19:27
Seeding images in Rails
# encoding: utf-8
environment_seed_file = File.join(Rails.root, 'db', 'seeds', "#{Rails.env}.rb")
def seed_image(file_name)
File.open(File.join(Rails.root, "/app/assets/images/seed/#{file_name}.jpg"))
end
products = [
{:name => 'foo', :description => 'lorem ipsum', :product_type => ProductType.find_by_name('Sandwiches')},
@mixin mobile_bg($file){
background-image: image-url('mobile/standard/#{$file}');
@media screen and (-webkit-min-device-pixel-ratio: 2) {
background-image: image-url('mobile/retina/#{$file}');
background-size: image-width('mobile/standard/#{$file}') image-height('mobile/standard/#{$file}');
}
}
// Usage
@averyvery
averyvery / fit_bg.css.scss
Created July 3, 2012 21:02
Fitted backgrounds using Compass
@mixin fit_bg($url){
background-image: image-url($url);
display: block;
height: image-height($url);
width: image-width($url);
}
// Usage
.nav-about {
@include fit_bg('assets/structure/nav/about.png');
@averyvery
averyvery / spread.sass
Last active May 16, 2020 22:07
spread.sass
// strip-units required by spread mixin
// http://stackoverflow.com/questions/12328259/how-do-you-strip-the-unit-from-any-number-in-sass
@function strip-units($number)
@return $number / ($number * 0 + 1)
// pow and sqrt required by ease function
// adapted from https://github.com/at-import/Sassy-math/blob/master/sass/math.scss
@function pow($base, $exponent)
$value: $base
@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 / dimension.scss
Created January 31, 2017 19:54
lil trick
/*
example:
dimension(foo, bar, 2, 10px);
- gets the value bar inside foo map
- multiplies it by two
- adds 10px
*/
$dimensions: (
global: (
require('colors');
import webpack from 'webpack';
import prettysize from 'prettysize';
import fs from 'fs';
import { execSync } from 'child_process';
import Table from 'cli-table';
import config from '../config/build.js';
webpack(config).run((error, stats) => {
if (error) console.log(error.red);