Skip to content

Instantly share code, notes, and snippets.

View akm's full-sized avatar

Takeshi Akima akm

View GitHub Profile
@akm
akm / gist:9360
Created September 8, 2008 02:19 — forked from taka2/gist:9289
require 'java'
require 'poi-3.1-FINAL-20080629.jar'
java.io.FileOutputStream.new("test2.xls") do |io|
wb = org.apache.poi.hssf.usermodel.HSSFWorkbook.new
wb.createSheet("First")
wb.write(io)
end
@akm
akm / gist:9362
Created September 8, 2008 02:21 — forked from taka2/gist:9290
require 'java'
require 'poi-3.1-FINAL-20080629.jar'
class RubyOutputStream < java.io.OutputStream
def set_io(io)
@io = io
end
def write(b)
if b.is_a?(Fixnum)
@akm
akm / tree_ancestors method
Created September 21, 2008 07:18
tree_ancestors method
class Module
def tree_ancestors
puts_tree_acestors(0, [self])
end
protected
def puts_tree_acestors(indent, displayed_modules)
puts "%s[%s] %s" % [' ' * indent, (self.is_a?(Class) ? 'C' : 'M'), self.name]
nested_included_modules = included_modules.map{|mod| mod.included_modules}.uniq.flatten # - displayed_modules
my_included_modules = included_modules - nested_included_modules
class Module
def def_trace_method(method_name, suffix = :rubeus)
self.module_eval(<<-"EOS")
def #{method_name.to_s}_with_#{suffix.to_s}(*args, &block)
puts "\#{self.name}.#{method_name}(\#{args.map{|arg| arg.inspect}.join(', ')})"
puts caller.join("\n ") if block_given?
#{method_name.to_s}_without_#{suffix.to_s}(*args, &block)
end
EOS
self.module_eval do
# 仕事用に作ってみたクラス
# 結局ボツにしました
class WhereBuilder
attr_accessor :joiner, 'AND'
attr_accessor :where_parts
attr_accessor :values
attr_accessor :filters
attr_accessor :wrapper
def initialize(*filters)
# -*- coding: utf-8 -*-
require 'yaml/encoding'
class String
alias :old_to_yaml :to_yaml
def to_yaml(ops = {})
YAML.escape(self).old_to_yaml(ops)
end
end
require "yaml"
@akm
akm / gist:109835
Created May 11, 2009 01:49
.bash_profile
# http://kazmax.zpp.jp/lin/etc_passwd.html
alias users_list="cut -d: -f1 /etc/passwd | sort"
alias groups_list="cat /etc/group | sort"
@akm
akm / rhtml_to_html_erb.rb
Created May 30, 2009 17:56
rhtml_to_html_erb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'fileutils'
require 'optparse'
FileUtils.cd(RAILS_ROOT)
runtime_options = {}
@akm
akm / database.yml.example
Created September 17, 2009 02:08
database.yml.example
<%
db_proj_name = 'your project name on db'
scm_proj_name = 'your project name on scm'
branch = `git status`.scan(/\# On branch ([^\s]+?)$/).flatten.first if File.exist?('./.git')
branch ||= `svn info`.scan(/\/#{scm_proj_name}\/(?:branches\/(.*?))\/|(trunk)/).flatten.compact.first if File.exist?('./.svn')
branch = branch ? '_' << branch.sub(/^local[\-_]/, '').sub('-', '_') : ''
%>
common: &common
adapter: mysql
# http://henrik.nyh.se/2008/10/cap-gems-install-and-a-gem-dependency-gotcha
namespace :gems do
desc "setup gemcutter"
task :gemcutter, :roles => :app do
run "#{sudo} gem install gemcutter"
run "#{sudo} gem tumble"
end
desc "Install gems"
task :install, :roles => :app do