Skip to content

Instantly share code, notes, and snippets.

View koic's full-sized avatar

Koichi ITO koic

View GitHub Profile
@koic
koic / irb
Created October 6, 2014 07:09
muryoimpl hitter
#!/usr/bin/env ruby
require 'irb'
class Array
def sample
detect {|elem| elem.to_sym == :muryoimpl }
end
end
IRB.start(__FILE__)
@koic
koic / map_chain.rb
Last active August 29, 2015 14:07
Array#map_chain
#
# RSpec の its('foo.bar.baz') { ... } にインスパイアされたものです。
#
# array.map(&:foo).map(&:bar).map(&:baz) を array.map_chain('foo.bar.baz') と
# 書けるものを書いてみたけれど、実際のところ AR でもちいると n+1 query が起きるため
# Gems にするには今ひとつはばかれるのであった。
#
class Array
def map_chain(method_names)
case method_names
module Readline
def readline
# ...
end
module_function :readline
def self.input=(input)
# ...
end
@koic
koic / gist:351603
Created April 1, 2010 09:39
Get test method names from TestCase.
import junit.framework.TestSuite;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.notification.RunListener;
public class Main {
public static void main(String[] args) {
JUnitCore core = new JUnitCore();
core.addListener(new RunListener() {
$:.unshift(File.dirname(__FILE__))
require 'spec_helper'
module BowlongGameMacro
class BowlongGamePlayer
def initialize
@game = Game.new
end
def roll_spare
@koic
koic / gist:366765
Created April 15, 2010 06:33
Create mock object using jMock.
import org.jmock.cglib.MockObjectTestCase;
public class ExampleTest extends MockObjectTestCase {
public void testExample() throws Exception {
...
final Mock mock = new Mock(ClassName.class);
mock.expects(once()).method("methodName").will(returnValue("returnValue"));
mock.proxy();
...
@koic
koic / gist:420662
Created June 1, 2010 07:00
Example of interval task using java.util.Timer and java.util.TimerTask.
Timer timer = new Timer(true);
...
TimerTask task = new TimerTask() {
public void run() {
// The action to be performed by this timer task.
}
};
timer.scheduleAtFixedRate(task, 0, watchInterval);
ruby -e 'Dir.glob("*").each { |jar| system("jar tvf #{jar}") }'
@koic
koic / gist:3174968
Created July 25, 2012 07:46
Resizing image file using MiniMagick
image = MiniMagick::Image.open('original.png')
image.resize '800x600'
image.write('resized.png')
@koic
koic / cflt_for_rubykaigi2015.md
Last active November 16, 2015 12:10
CFLT for RubyKaigi 2015 (@koic)

CFLT for RubyKaigi 2015

Title

Agile Software Development with Edge Ruby

Abstract

Ruby / Rails をもちいたソフトウェア開発の中で、Ruby の開発バージョン (発表時 2.3.0-dev) を取り入れているお話をします。本番環境は本番環境、開発環境は開発環境ということで、明日から個人ではじめられる話です。 プログラミングを楽しくする言語 Ruby のことをもっと知りたいという気持ちを持ち帰って頂ければ幸いです。