Skip to content

Instantly share code, notes, and snippets.

# Add fixture-generation methods to ControllerExampleGroup. We load
# this file within our spec_helper.rb
Spec::Rails::Example::ControllerExampleGroup.class_eval do
# Saves the markup to a fixture file using the given name
def save_fixture(markup, name)
fixture_path = File.join(RAILS_ROOT, '/tmp/js_dom_fixtures')
Dir.mkdir(fixture_path) unless File.exists?(fixture_path)
// Loads fixure markup into the DOM as a child of the jasmine_content div
spec.loadFixture = function(fixtureName) {
var $destination = $('#jasmine_content');
// get the markup, inject it into the dom
$destination.html(spec.fixtureHtml(fixtureName));
// keep track of fixture count to fail specs that
// call loadFixture() more than once
spec.loadFixtureCount++;
@mavenlink
mavenlink / snapabug_lazy.js
Created December 14, 2010 21:22
javascript
$(function() {
$("head").append("<sc" + "ript src='" + ((document.location.protocol=="https:")?"https:":"http:") + "//snapabug.appspot.com/snapabug.js" + "' type='text/javascript'></sc" + "ript>");
(function() {
var snapABugLoader = setInterval(function() {
if (typeof SnapABug != "undefined") {
SnapABug.setButton("https://snapabug.appspot.com/statusImage?w=OUR KEY",35,90);
SnapABug.addButton('OUR KEY',"1","400px");
SnapABug.setButtonEffect('-4px');
clearInterval(snapABugLoader);
@mavenlink
mavenlink / finder_finder.sh
Created March 18, 2011 22:44
Find and count uses of find_by_xxx
#!/bin/sh
grep -R .find_by . | ruby -e 'STDIN.each do |l| puts "#{$1} #{$2}" if l =~ /([_\w]+)\.find_by_([_\w]+)/ && !%w[class self].include?($1) && !%w[solr sql id param].include?($2); end' | sort | uniq -c
@mavenlink
mavenlink / refreshBackgrounds.js
Created February 15, 2012 19:52
Fix Chrome background refresh bug
function refreshBackgrounds(selector) {
// Chrome shim to fix http://groups.google.com/a/chromium.org/group/chromium-bugs/browse_thread/thread/1b6a86d6d4cb8b04/739e937fa945a921
// Remove this once Chrome fixes its bug.
if (/chrome/.test(navigator.userAgent.toLowerCase())) {
$(selector).each(function() {
var $this = $(this);
if ($this.css("background-image")) {
var oldBackgroundImage = $this.css("background-image");
setTimeout(function() {
$this.css("background-image", oldBackgroundImage);