Skip to content

Instantly share code, notes, and snippets.

@tmeasday
tmeasday / tabbed.js
Created September 29, 2011 23:42
Tom's idea for update()
function update(url) {
var index = $buttons.find('[href=' + url + ']').parents('li').index();
$buttons.removeClass('current').eq(index).addClass('current');
$slides.removeClass('current').eq(index).addClass('current');
}
@tmeasday
tmeasday / gist:1252712
Created September 30, 2011 04:59
Useful Apple Command setups
Turn off stupid* press and hold settings [Needs re-login] *clever
defaults write -g ApplePressAndHoldEnabled -bool false
Turn off broken* spaces settings (*helpful)
defaults write com.apple.Dock workspaces-auto-swoosh -bool NO
killall Dock
@tmeasday
tmeasday / nav.html.erb
Created October 2, 2011 08:55
How to use current_page? to do a nav bar in rails
<%# This is completely boilerplate rails %>
<ul id="navbar">
<li><%= link_to_unless_current("Home", home_path) %></li>
<li><%= link_to_unless_current("About Us", about_path) %></li>
</ul>
<%# More specific %>
<ul id="navbar">
<li><%= link_to "Home", home_path, :class => current_page?(home_path) ? 'current' : '' %></li>
<li><%= link_to "About Us", about_path, :class => current_page?(home_path) ? 'current' : '' %></li>
@tmeasday
tmeasday / gist:1263394
Created October 5, 2011 01:35
Steps required to get performance branch working
# 1. Install rbenv [https://github.com/sstephenson/rbenv]
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
exec $SHELL
# 2. Install ruby-build [https://github.com/sstephenson/ruby-build]
cd [Some source code directory]
git clone git://github.com/sstephenson/ruby-build.git
@tmeasday
tmeasday / URLs
Created October 5, 2011 13:36
How to set up a basic premailer test task
This code is vaguely based on the action mailer rails guide example. Now try:
/test/email?type=welcome&part=text
This is the plain text part of the email
/test/email?type=welcome&part=css
This is the html part, before premailing, standard css, easier to debug
/test/email?type=welcome&part=html
This is the premailed part, there are sometimes subtle differences.
@tmeasday
tmeasday / application_controller.rb
Created October 7, 2011 00:31
How to keep track of the http referer across requests
ApplicationController < ActionController::Base
before_filter :track_referer
protected
def track_referer
@referer = session[:referer] ||= parse_referer(request.headers['HTTP-REFERER'])
end
def parse_referer(url)
@tmeasday
tmeasday / bug.rb
Created December 8, 2011 08:08
Problem with has_many :through counter_caches
require 'rubygems'
require 'active_record'
# Print out what version we're running
puts "Active Record #{ActiveRecord::VERSION::STRING}"
# Connect to an in-memory sqlite3 database
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
@tmeasday
tmeasday / css_splitter.rb
Created January 7, 2012 02:20
A modified CSS splitter that allows you to extract a single part.
# copied from https://gist.github.com/1131536, thanks christian peters.
module CssSplitter
def self.split(infile, outdir = File.dirname(infile), max_selectors = 4095)
charset_statement, rules = self.read_rules(infile)
return if rules.nil?
self.partition_rules(rules, max_selectors).each_with_index do |ruleset, index|
next if index == 0 # no need to write out the first file
$element.on('click', '.next', function() {
// find the next frame that isn't completely on the screen
var $next_frame = $element.find('.frame').filter(function() {
return $(this).position().left + $(this).width() > $element.scrollLeft() + $element.width();
}).eq(0)
// scroll it into view
$element.scrollTo($next_frame, 'medium');
});
@tmeasday
tmeasday / index.html
Created May 17, 2012 06:02
Template code that triggers meteor #142
<head>
<title>Sport Grid</title>
</head>
<body>
{{> screens }}
</body>
<template name="screens">
<div class="container {{ visible_page }}">