This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.tabularize = function(options) { | |
if ( typeof options === 'string' ) { | |
var args = Array.prototype.slice.call( arguments, 1 ); | |
this.each(function() { | |
var instance = $.data( this, 'tabularize' ); | |
if ( !instance ) { | |
console.log( "cannot call methods on tabularize prior to initialization; " + | |
"attempted to call method '" + options + "'" ); | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Module = (function(document, window, $){ | |
var self = {}, | |
// DOM/jQuery | |
$document = $(document), | |
$window = $(window), | |
// flags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helpers to output either link, or span based on the condition | |
def link_to_span_unless(condition, name = nil, options = {}, html_options = {}, &block) | |
if condition | |
content_tag :span, name, html_options, &block | |
else | |
link_to name, options, html_options, &block | |
end | |
end | |
def link_to_span_if(condition, *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/spoof_ip.rb | |
class SpoofIp | |
def initialize(app, ip) | |
@app = app | |
@ip = ip | |
end | |
def call(env) | |
env['REMOTE_ADDR'] = env['action_dispatch.remote_ip'] = @ip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: http://www.sitepoint.com/create-one-time-events-javascript/? | |
// create a one-time event | |
function onetime(node, type, callback) { | |
// create event | |
node.addEventListener(type, function(e) { | |
// remove event | |
e.target.removeEventListener(e.type, arguments.callee); | |
// call handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Ryan Bates | |
# see: https://github.com/railscasts/137-memoization-revised/blob/master/store-after/app/helpers/application_helper.rb | |
def report_time(code) | |
start = Time.now | |
result = eval(code) | |
finish = Time.now | |
render "report", code: code, result: result, time: finish - start | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An encapsulated class for i18n-related widgets in the footer | |
# | |
# It includes: | |
# - Locale switcher | |
# - Currency switcher | |
# | |
# Also it's state stores available translated locales for current pages | |
# | |
class I18nWidgets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in config/environments/production.rb | |
require 'ext/conditional_uglifier' | |
# Compress JavaScripts and CSS. | |
config.assets.js_compressor = ConditionalUglifier.new | |
# in lib/ext/conditional_uglifier.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
initMasonry = function(){ | |
console.log( "init masonry" ); | |
// We don't need masonry on one-column layouts! | |
if ( checkMasonryBreakpoint() ) { | |
requestAnimationFrame(function(){ | |
masonry = new Masonry( artworks, self.settings.masonry ); | |
masonry.on( 'postLayout', function(){ | |
console.log('layout done, just this one time'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AlbumFormBuilder < SimpleForm::FormBuilder | |
def polymorphic(association, options={}) | |
options = options.dup | |
raise ArgumentError, "Association cannot be used in forms not associated with an object" unless @object | |
raise ArgumentError, "You need to pass types for select" unless options[:types] | |
reflection = find_association_reflection(association) | |
raise "Association #{association.inspect} not found" unless reflection |
OlderNewer