Skip to content

Instantly share code, notes, and snippets.

@kurbmedia
kurbmedia / spec_runner.rb
Created April 29, 2011 23:02
minitest runner for specdoc style output (beta)
require 'rubygems'
require 'minitest/unit'
require 'colored'
module MiniTest
class SpecRunner < Unit
def before_suites
super if defined?(super)
end
@kurbmedia
kurbmedia / compressor.rb
Created April 18, 2011 22:20
JS Packaging, modeled after jammit but much lighter, and uses remote closure compiler.
module Packager
class Compressor
attr_accessor :templates, :javascripts
def initialize(config)
@templates = config['templates'] || {}
@javascripts = config['javascripts'] || {}
end
@kurbmedia
kurbmedia / flash_header.rb
Created March 11, 2011 18:06
Adds flash messages to the response header so they can be picked up via js.
after_filter :add_flash_messages
# Adds flash messages to the HTTP headers so they can be used on the current request with AJAX
def add_flash_messages
return true unless response.content_type.to_s.match(/javascript/i)
return true if flash.keys.empty?
response.headers['X-Flash-Messages'] = flash.to_json
flash.discard
end
@kurbmedia
kurbmedia / _base.scss
Created March 6, 2011 01:58
Starter files for compass/blueprint
/*
Sets up any compass imports, as well as variables used throughout css files. This way all files can access the libraries, but without
adding additional code to every css file.
*/
////////////////////////////////////////////////
// Import Blueprint defaults
////////////////////////////////////////////////
@import "blueprint/grid";
@import "blueprint/typography";
@kurbmedia
kurbmedia / jabbah.rb
Created February 27, 2011 19:48
Basic daemon to run a jabber bot
class JabberBot
attr_accessor :daemon
attr_accessor :messenger
def initialize
end
def activate!
@daemon = Daemons.run_proc('dev_bot', :dir => "#{Rails.root}/tmp/pids", :dir_mode => :normal, :monitor => false, :log_output => true ) do
@kurbmedia
kurbmedia / Growl.rb
Created February 7, 2011 21:52
watchr + growl + rspec
class Growl
attr_accessor :report, :status
def initialize(report, opts = {})
@report, options = report, create_options(opts)
message = create_message
opts = options.inject([]) do |arr, item|
key, value = item.first, item.last
@kurbmedia
kurbmedia / manifest.yml
Created January 31, 2011 16:11
watchr script to minify js files on save
somepackage:
- somefile.js
anotherpackage:
- somefile.js
@kurbmedia
kurbmedia / spec_growl.rb
Created January 13, 2011 06:35
Rspec spec_helper to add growl support internally
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
@kurbmedia
kurbmedia / spec.watchr
Created January 13, 2011 02:17
.watchr for spec files. if anyone knows how to show result #s in growl AND keep color output <3
# vim:set filetype=ruby:
def growl
title = "Watchr Test Results"
image = $?.success? ? "~/.watchr/images/passed.png" : "~/.watchr/images/failed.png"
message = $?.success? ? "success" : "failed"
growlnotify = `which growlnotify`.chomp
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
end
@kurbmedia
kurbmedia / factories.rake
Created January 12, 2011 02:58
Generates FactoryGirl factories.rb from the database tables/columns
namespace :factories do
task :generate => :environment do
# Make a new factory file, moving the old one to factories_old.rb if one exists.
factory_file = "#{Rails.root}/spec/factories"
FileUtils.mv("#{factory_file}.rb", "#{factory_file}_old.rb") if File.exists?("#{factory_file}.rb")
fixture_file = File.open("#{factory_file}.rb", 'w') do |file|