Skip to content

Instantly share code, notes, and snippets.

View koic's full-sized avatar

Koichi ITO koic

View GitHub Profile
@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 / 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
@koic
koic / gist:ea337f39012cd9efa775
Last active September 6, 2016 11:18
Example codes for Hamamatsu Ruby Kaigi 01 Lightning Talks https://www.slideshare.net/koic/reading-1st-druby
#
# artist.rb
#
class Artist
def initialize(name)
@name = name
end
attr_reader :name
end
module Readline
def readline
# ...
end
module_function :readline
def self.input=(input)
# ...
end