Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
=begin
- clone current source before execute this.
$ git clone --depth=1 git://github.com/sandal/prawn.git
- fix font in line 14
=end
$KCODE = "u"
$: << "./prawn/lib"
#
# get current IP addr.
# reject internal netwok(eg. vmnet0, for VMware) at the end of method chain.
# is there better way?
#
Socket.getaddrinfo(Socket.gethostname, 0, Socket::AF_INET).
map{|e| e[2] }.
uniq.
reject{|addr| addr =~ /\.1\Z/ }
#!/usr/bin/env ruby
# vim:set fileencoding=utf-8 filetype=ruby
$KCODE = 'u'
describe "text spliting" do
before do
special = [
[0x3001].pack("U"), # ten
[0x3002].pack("U"), # maru
[0x30fc].pack("U"), # bar/multibyte hyphun
#!/usr/bin/env ruby
# vim:set fileencoding=utf-8 filetype=ruby
$KCODE = 'u'
require 'webrick/httpserver'
s = WEBrick::HTTPServer.new(:Port=>3030)
s.mount_proc("/deploy") do |req, res|
IO.popen("cap deploy"){|x| res.body = x.read }
res.status = ($? == 0 ? WEBrick::HTTPStatus::OK : WEBrick::HTTPStatus::BadRequest).code
end
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def javascript_include_file(filename)
if ::Rails.env == "development"
fullpath = File.expand_path("public/javascripts/#{filename}.js", ::Rails.root)
javascript_tag File.read(fullpath)
else
javascript_include_tag filename
end
end
# ============= Definition ==============
class User < ActiveRecord::Base
has_many :memberships
def accessible(klass)
klass.scoped( :conditions=>[<<-SQL, klass.name, self] )
#{klass.table_name}.id IN (
SELECT a.accessible_id
FROM accessibilities AS a
JOIN memberships AS m ON a.role_id = m.role_id
#!/usr/bin/env ruby
$KCODE = 'u'
require 'rubygems'
require 'hpricot'
require 'thin'
require 'rack'
describe "My Rails App" do
@moro
moro / gist:20013
Created October 27, 2008 03:10 — forked from eto/gist:20008
皆様,
産総研の江渡です.お世話になっております.
第130回SIGHCI研究会の参加募集です.
今回は招待講演が3件もあり,充実しています.
今回は特に,ニコニコ動画の開発者として有名な戀塚昭彦氏に来ていただける
ことになりました.ニコニコ動画の裏側に,どのようなインタラクション上の
工夫があるかについてお話ししていただきます.
# Commonly used webrat steps
# http://github.com/brynary/webrat
When /言語は"(.*)"/ do |lang|
header("ACCEPT_LANGUAGE", lang)
end
When /^"(.*)"ボタンをクリックする$/ do |button|
clicks_button(button)
end
@moro
moro / env.rb
Created December 11, 2008 02:35
# Sets up the Rails environment for Cucumber
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/rails/world'
Cucumber::Rails.use_transactional_fixtures
# Comment out the next line if you're not using RSpec's matchers (should / should_not) in your steps.
require 'cucumber/rails/rspec'
ActionController::Base.class_eval do