Skip to content

Instantly share code, notes, and snippets.

View chsh's full-sized avatar
👍
Love your code.

CHIKURA Shinsaku chsh

👍
Love your code.
View GitHub Profile
class LatLng
attr_reader :lat, :lng, :srid
WGS84 = 4326
SRID = WGS84
def initialize(lat, lng, srid = WGS84)
@lat = lat.to_f
@lng = lng.to_f
@srid = srid.to_i
@chsh
chsh / poi_test.rb
Created January 29, 2009 14:04
sample ruby script for reading excel file using rjb + poi-3.5
require 'rubygems'
require 'rjb'
JARS = Dir.glob('./javalib/**/*.jar').join(':')
Rjb::load(JARS)
class CellConverter
DateUtil = Rjb::import 'org.apache.poi.ss.usermodel.DateUtil'
blue_hosts = [
'hoge.jp', 'grey.jp', 'hoge.com'
]
def blue?(line)
blue_hosts.each do |blue_host|
return true if line.index(blue_host)
end
false
end
class Processor
BLUE_HOSTS = [
'hoge.jp', 'grey.jp', 'hoge.com'
]
def process(lines)
lines.each do |line|
if blue? line
blue_lines << line
else
red_lines << line
#!/bin/bash
if [ "$@" ]
then
ARGS=$@
else
ARGS=.
fi
ps uxww | grep -v grep | grep Emacs >/dev/null
unless Object.respond_to? :class_config
def Object.class_config
ccs = @@____class_config_saver____ ||= (
target = "#{RAILS_ROOT}/config/class_config.yml"
if File.exist? target
YAML.load_file(target)
else
{}
end
)
@chsh
chsh / utf8_file.rb
Created October 11, 2009 06:12
This class allows you to treat some japanese encoded file as UTF-8.
require 'tempfile'
require 'nkf'
require 'iconv'
class UTF8File
def self.convert(filename, &block)
encoding = guess_encoding(filename)
raise "Couldn't detect encoding" unless encoding
fp = make_instance(filename, encoding)
if block_given?
@chsh
chsh / XMLEqualityChecker
Created October 21, 2010 07:57
2つのXMLが同じかどうかだけを調べるチェッカー
require 'rubygems'
require 'nokogiri'
module XMLEqualityChecker
def equal_as_xml(left, right)
left_x = Nokogiri::XML(left.to_s)
right_x = Nokogiri::XML(right.to_s)
compare_element(left_x.root, right_x.root)
end
def compare_element(left_elm, right_elm)
@chsh
chsh / rails_version_rprompt.sh
Created October 23, 2010 10:52
Show RAILS version using zsh RPROMPT.
_set_env_git_current_branch() {
GIT_CURRENT_BRANCH=$( git branch &> /dev/null | grep '^\*' | cut -b 3- )
}
_set_env_rails_version() {
RAILS_VERSION=$( rails -v &> /dev/null | cut -b 7- )
}
_update_rprompt () {
if [ "`git ls-files 2>/dev/null`" ]; then
RPROMPT="[$RAILS_VERSION:%2.:$GIT_CURRENT_BRANCH]"
@chsh
chsh / rvm-prompt.sh
Created October 23, 2010 12:09
Show ruby version and gemset name on RPROMPT using rvm-prompt
_update_rprompt () {
if [ "`git ls-files 2>/dev/null`" ]; then
RPROMPT="[$(rvm-prompt v g):%2.:$GIT_CURRENT_BRANCH]"
else
# RPROMPT="[%~]"
RPROMPT="[$(rvm-prompt v g):%2.]"
fi
}