Skip to content

Instantly share code, notes, and snippets.

View masayuki038's full-sized avatar

Masayuki Takahashi masayuki038

View GitHub Profile
package test;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.junit.Test;
import test.entity.Bar;
import test.entity.Foo;
@masayuki038
masayuki038 / Bar.java
Created May 5, 2011 15:09
morphia test
package test.entity;
import java.util.List;
import com.google.code.morphia.annotations.Embedded;
@Embedded
public class Bar {
private long id;
@masayuki038
masayuki038 / gist:1209689
Created September 11, 2011 15:09
Serializing HashMap By MessagePack for Java.
@Test
public void testSerliazingMapByMessagePack(){
Map<String, Object> map = new HashMap<String, Object>();
map.put("int", 1);
map.put("long", 1L);
map.put("date", new Date());
map.put("string", "test");
byte[] buffer = MessagePack.pack(map);
for (byte b : buffer) {
@masayuki038
masayuki038 / gist:1343248
Created November 6, 2011 18:02
MBeanRegister using jmx4r
require 'rubygems'
require 'jmx4r'
import java.lang.management.ManagementFactory
import javax.management.ObjectName
class MBeanRegister < JMX::DynamicMBean
operation "regster mbean script"
parameter :string, "mbean class name"
parameter :string, "object name"
@masayuki038
masayuki038 / ImplicitConversionTest.scala
Created July 16, 2012 13:18
Implicit conversion test in Scala.
package net.wrap_trap.scala.examples
object ImplicitConversionTest {
def main(args : Array[String]) : Unit = {
val s1 : String = "Foo"
val i : Int = s1 // compile error 'type mismatch; found : String required: Int' without string2Int
System.out.println("i: " + i);
}
implicit def string2Int(str: String) : Int = {
@masayuki038
masayuki038 / OrderedComparableTest.scala
Created July 16, 2012 13:29
Ordered[A] and Comparable[A]
package net.wrap_trap.scala.examples
object OrderedComparableTest {
def main(args : Array[String]) : Unit = {
val s1 : String = "Hoge"
val s2 : String = "Bar"
System.out.println(new Sample1[String](s1).compare(s2))
System.out.println(new Sample2[String](s1).compare(s2)) // 'Implicit conversions found: s1 => augmentString(s1)'
}
}
@masayuki038
masayuki038 / OrderedCompareTest.scala
Created July 22, 2012 13:26
A comparision of Ordered.
package net.wrap_trap.scala.examples
import java.util.Comparator
object OrderedCompareTest {
def main(args : Array[String]) : Unit = {
System.out.println("called main")
System.out.println(
compareAB(new OrderedClass(2), new OrderedClass(1)))
@masayuki038
masayuki038 / OrderedCompareTest2.scala
Created July 22, 2012 13:28
A comparision of Non-Ordered.
package net.wrap_trap.scala.examples
import java.util.Comparator
object OrderedCompareTest2 {
def main(args : Array[String]) : Unit = {
System.out.println("called main")
// compile error when disabling nonOrderedClassToComparable Method.
// No implicit Ordering defined for
@masayuki038
masayuki038 / ReadBlackTree.scala
Created July 29, 2012 13:24
Red-Black Tree written in Scala.
package net.wrap_trap.utils.rbtree
object RedBlackTree {
object Color extends Enumeration {
val Red, Black = Value
}
class Hash[K, V] {}
@masayuki038
masayuki038 / btree.rb
Created August 8, 2012 17:57
btree.rb
class AbstractNode
@@root = nil
def initialize(n, keys, parent)
@slot = n
@keys = keys
@parent = parent
@@root = self unless @@root
end