Skip to content

Instantly share code, notes, and snippets.

View tristanm's full-sized avatar

Tristan McHardie tristanm

View GitHub Profile
@tristanm
tristanm / wireframe.rb
Created June 18, 2013 03:41
A wireframing scaffold for Rails 2.3
class Wireframe < ActiveRecord::Base
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
def method_missing(method_id, *args, &block)
@tristanm
tristanm / check_box_buttonset.rb
Created June 6, 2013 23:55
jQuery buttonset builder for Formtastic
# Custom input to render "flat" checkbox/label pairs for jQuery UI Buttonsets
class CheckBoxButtonsetInput < Formtastic::Inputs::CheckBoxesInput
def to_html
input_wrapping do
choices_wrapping do
legend_html <<
hidden_field_for_all <<
collection.map { |choice|
choice_html(choice)
}.join("\n").html_safe
@tristanm
tristanm / sort_files.rb
Created May 26, 2013 20:49
Sorts file names by a numeric suffix
files.sort! { |a, b|
[a, b]
.map { |s| s[/_(\d+).jpg/, 1].to_i }
.inject(:"<=>")
}
@tristanm
tristanm / no-iframe.js
Created October 30, 2012 02:11
Always break out of an iframe
if (window.self !== window.top) {
window.top.location.href = window.self.location.href;
}
@tristanm
tristanm / debouncer.js
Created September 16, 2012 20:41
jQuery Debouncer
var debounce_timer = null;
$(window).resize(function(e) {
window.clearTimeout(debounce_timer);
debounce_timer = window.setTimeout(function() {
$(document).trigger("gh:resize");
}, 200);
});
$(document).on("gh:resize", function(e) {
@tristanm
tristanm / gist:3057637
Created July 6, 2012 02:14
Embedded Fonts
// ****************
// **** NORMAL ****
// ****************
// COMPASS:
// Best order for font-files is WOFF->TTF->SVG while the EOT is a separate parameter for font-face
// Best weight and style order is Regular->Bold->Italic->Bold+Italic
@include font-face("Aller", font-files("aller_rg-webfont.woff", "aller_rg-webfont.ttf", "aller_rg-webfont.svg"), "aller_rg-webfont.eot");
@include font-face("Aller", font-files("aller_bd-webfont.woff", "aller_bd-webfont.ttf", "aller_bd-webfont.svg"), "aller_bd-webfont.eot", bold);
@include font-face("Aller", font-files("aller_it-webfont.woff", "aller_it-webfont.ttf", "aller_it-webfont.svg"), "aller_it-webfont.eot", normal, italic);