Skip to content

Instantly share code, notes, and snippets.

# github_api.rb
require 'rubygems'
require 'uri'
require 'net/http'
require 'yaml'
Net::HTTP.version_1_2
class GitHubApi
def repository(user_name, repos_name)
# github_api_test.rb
require 'rubygems'
require 'test/unit'
require 'fakeweb'
require File.join(File.dirname(__FILE__), 'github_api.rb')
class Test::Unit::TestCase
end
class GitHubApiTest < Test::Unit::TestCase
#!/usr/bin/env ruby
# =======================================================
# 外部連携するRails開発において外部サーバのモックアプリとRailsアプリを同時起動するスクリプト
#
# ex.)
# RAILS_ROOT/lib/external_server/server.rb
#
# $ ruby script/external_server
# => Rails'command run 'script/server'
#!/usr/bin/env ruby
require 'optparse'
require "rubygems"
require "activerecord"
host = 'localhost'
password = ''
username = db = nil
help = ''
@matsuda
matsuda / schema_dumper_extension.rb
Created December 7, 2009 10:31
MyISAMテーブルの場合はMyISAMオプションを付けてダンプ
module SchemaEngine
module SchemaDumper #:nodoc:
def self.included(mod)
mod.module_eval do
alias_method_chain :table, :schema_engine
end
end
private
def table_with_schema_engine(table, stream)
#
# 検索用クラス
# ActiveFormプラグインに似ている
#
# これまでのActiveSearchをモジュール化し、ActiveFormを拡張するようにしました
# selectable_attrがインクルードされています
# ------------------------------------------------------
# 使い方
# SearchFormクラスを継承
# Ext::ActiveSearch::Baseモジュールをインクルード
@matsuda
matsuda / _environment.rhtml
Created April 20, 2010 06:11
Extend exception_notification plugin
<%# app/views/exception_notifier/_environment.rhtml %>
<% max = @request.env.keys.max { |a,b| a.length <=> b.length } -%>
<% @request.env.keys.select{|key| key =~ /^[A-Z|_]+$/ }.sort.each do |key| -%>
* <%= "%-*s: %s" % [max.length, key, filter_sensitive_post_data_from_env(key, @request.env[key].to_s.strip)] %>
<% end -%>
* Process: <%= $$ %>
* Server : <%= `hostname -s`.chomp %>
@matsuda
matsuda / blank.rb
Created July 2, 2010 09:29
全角スペース対応 blank? メソッド
class String #:nodoc:
def blank?
self !~ /\S/ || self =~ /\A( |\s)+\Z/
end
end
@matsuda
matsuda / application_helper.rb
Created July 14, 2010 04:08
Rails' utility helpers
module ApplicationHelper
#
# JavaScriptコードを<head>タグに挿入する
#
def content_for_javascript_tag(content_or_options_with_block = nil, html_options = {}, &block)
content_for :javascript do
javascript_tag(content_or_options_with_block, html_options, &block)
end
end
@matsuda
matsuda / jQuery-Utility.js
Created August 16, 2010 08:19
Utility methods with jQuery
(function($){
// force focus() using timer because focus() is not working in IE
// jQuery('#focus-element').focusForce();
$.extend($.fn, {
focusForce: function() {
var self = this;
setTimeout( function() { $(self).focus(); }, 100);
}
});
})(jQuery);