Skip to content

Instantly share code, notes, and snippets.

View rhiguchi's full-sized avatar
🏠
Working from home

HIGUCHI Ryusuke rhiguchi

🏠
Working from home
  • Yokohama, Japan
View GitHub Profile
/**
* Creating a instance by using FEST Reflection for testing of Swing Application Framework
* require import static org.fest.reflect.core.Reflection.*;
*/
protected static <C extends Application> C createApplicationInstance(Class<C> appClass, String[] args) {
C application =
staticMethod("create")
.withReturnType(appClass)
.withParameterTypes(Class.class)
.in(appClass)
@rhiguchi
rhiguchi / invoke_method.php
Created January 16, 2011 01:25
A function for invoking private or protected method with reflection.
/**
* Invoke method by using reflection.
* Require PHP5 (>= 5.3.2)
* @param $method_name
* @param $obj - An object that invokes the method.
* @param mothod_args... Arguments for the method.
*/
public static function invoke_method($method_name, $obj) {
$class_name = get_class($obj);
$class = new ReflectionClass($class_name);
{
'A': 'A', 'C': 'C', 'G': 'G', 'T': '[TU]',
'R': '[AG]', 'Y': '[CTU]', 'S': '[GC]',
'W': '[ATU]', 'K': '[GTU]', 'M': '[AC]',
'B': '[CGTU]', 'D': '[AGTU]',
'H': '[ACTU]', 'V': '[ACG]',
'N': '[ACGTU]'
}
@rhiguchi
rhiguchi / VBACodeExporter.vba
Created April 11, 2011 06:48
Excel VBA のコードを出力する。文字コードはUTF-8(BOM無し)に変換される
Option Explicit
Private exportSelf As Boolean
Public Const MODULE_NAME_SPACE As String = "VBACodeExporter"
Private Enum ComponentType
STANDARD_MODULE = 1
CLASS_MODULE = 2
USER_FORM = 3
DOCUMENT_MODULE = 100
@rhiguchi
rhiguchi / MainView.java
Created January 29, 2012 13:41
Swing を MVC パターンで設計する流れの確認。
import static javax.swing.SpringLayout.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
@rhiguchi
rhiguchi / AlphaDigitsHexNumberColorDecodingTest.java
Created February 4, 2012 14:23
アルファ値を持つ16進数文字列からColorオブジェクトを作成するテスト
import static org.junit.Assert.*;
import java.awt.Color;
import org.junit.Test;
public class AlphaDigitsHexNumberColorDecodingTest {
@Test
public void decodeHexStringToColor() {
Color color = Color.decode("#000000");
@rhiguchi
rhiguchi / ViewTest.java
Created February 5, 2012 01:48
Swingビューテストのテンプレート
import javax.swing.JFrame;
public class ViewTest {
ViewTest craeteView() {
return new ViewTest();
}
public static void main(String[] args) {
final ViewTest test = new ViewTest();
@rhiguchi
rhiguchi / LimitValueTest.java
Created February 6, 2012 02:00
MIN_VALUEの値のテスト
public class LimitValueTest {
@Test
public void limitOfInteger() {
assertEquals(2147483647, Integer.MAX_VALUE);
assertEquals(0x7fffffff, Integer.MAX_VALUE);
assertEquals(-2147483648, Integer.MIN_VALUE);
assertEquals(-0x80000000, Integer.MIN_VALUE);
}
@Test
@rhiguchi
rhiguchi / PropertyChangePublisher.scala
Created February 24, 2012 16:31
Scala で PropertyChangeEvent の発行とかを実装するミックスイン用トレイト ref: http://qiita.com/items/2791
import java.beans.{PropertyChangeListener, PropertyChangeSupport, PropertyChangeEvent}
trait PropertyChangePublisher {
private lazy val propertyChangeSupport = new PropertyChangeSupport(this)
def addPropertyChangeListener(listener: PropertyChangeListener) =
propertyChangeSupport.addPropertyChangeListener(listener)
def removePropertyChangeListener(listener: PropertyChangeListener) =
propertyChangeSupport.removePropertyChangeListener(listener)
@rhiguchi
rhiguchi / LoanPatternLock.scala
Created February 25, 2012 13:55
Scala で ReadWriteLock にローンパターンを使う ref: http://qiita.com/items/2805
object LoanPatternLock {
import java.util.concurrent.locks.{Lock, ReadWriteLock}
def lockWith[A <% Lock, B](l: A)(e: => B) = {
l.lock()
try e finally l.unlock()
}
def readLockWith[A <% ReadWriteLock, B](l: A)(e: => B) =
lockWith(l.readLock)(e)