Skip to content

Instantly share code, notes, and snippets.

View fujimura's full-sized avatar

Daisuke Fujimura fujimura

View GitHub Profile
require 'test/unit'
require 'test/unit/ui/testrunnermediator'
require 'test/unit/ui/testrunnerutilities'
require 'rubygems'
require 'redgreen'
module Test::Unit
class TestCase
def name
module SMarkUp
def markup(&block)
yield
end
TAGS = %w(body h1 h2 p div)
TAGS.each do |tag|
send(:define_method, tag) do |*args, &block|
r = block.call
r = case r
when Array
class Test::Unit::TestCase
def self.should_require_login(http_method, method)
should "require login wth #{http_method.to_s.upcase} :#{method}" do
raise "http verb(#{http_method} is not my cup of tea)" unless [:put, :get, :post, :delete].include? http_method.to_sym
if UserSession.find
UserSession.find.destroy
end
eval(http_method.to_s + "(\"#{method}\")")
assert_redirected_to new_user_session_path
end
module RecordNotFoundMacros
def should_raise_record_not_found(&block)
should "raise 'Record not Found'" do
assert_raise(ActiveRecord::RecordNotFound) {block.bind(self).call}
end
end
end
// Set passed background-image to form type=submit just before ajax request was submitted.
// reset with ajax:complete.
// options:
// loadingImage: background-image
// loadingText: text
jQuery.fn.swapBackgroundToLoading = function(options){
$(this).live('ajax:before', function(){
var submit = $(this).find('input[type=submit]')
var text = submit.val();
var backgroundImage = submit.css('background-image');
# -*- encoding: utf-8 -*-
require 'httparty'
class RemoteRedmine
include HTTParty
def initialize(cap)
raise ArgumentError, 'Please set your redmine settings' if !cap[:redmine]
self.class.base_uri cap[:redmine][:url]
self.class.default_params :key => cap[:redmine][:access_key]
ls -t1|awk '{if(/f/ && nlines++ >= 5) print $1;}'|xargs rm
after 'deploy' do
run "crontab -r && crontab #{File.join(current_path, 'cron')}"
end
class ApplicationController < ActionController::Base
helper_method :count_something
def count_something
cache_of_today "count-of-something" do
Something.count
end
end
@fujimura
fujimura / jquerish.rb
Created October 17, 2010 14:38
enables jquery-like dynamic function adding. ignores closure like 'this' in js.
require 'active_support/all'
class HashWithJavaScriptishAccess < Hash
def method_missing(name, *args)
if name.to_s =~ /=$/
name_to_be_set = name.to_s.gsub(/=$/, '').to_sym
self[name_to_be_set] = args.first
else
self[name] || super
end