Skip to content

Instantly share code, notes, and snippets.

Avatar

Masahiko Sakamoto msakamoto-sf

View GitHub Profile
@msakamoto-sf
msakamoto-sf / Calc.java
Created Nov 11, 2012
Java + Groovy + TestNG + Maven combination example2
View Calc.java
package gjt2;
public class Calc {
private int v1;
private int v2;
public Calc(int a, int b) {
v1 = a;
v2 = b;
}
public int calc() {
@msakamoto-sf
msakamoto-sf / Calc1.groovy
Created Nov 11, 2012
Java + Groovy + TestNG + Maven combination example1
View Calc1.groovy
package gjt1;
public class Calc1 {
int v1;
int v2;
def Calc1(int a, int b) {
v1 = a;
v2 = b;
}
int calc() {
@msakamoto-sf
msakamoto-sf / Singleton.java
Created Nov 18, 2012
Java + Groovy + TestNG + Maven combination example3 (replace singleton field)
View Singleton.java
package gjt3;
public class Singleton {
private static Singleton instance = null;
private String myarg;
private Singleton(String arg) {
myarg = arg;
}
public synchronized static Singleton getInstance(String arg) {
if (Singleton.instance == null) {
@msakamoto-sf
msakamoto-sf / TestFoo.java
Last active Mar 13, 2018
Nested Test Cases with TestNG (nearly equals JUnit's "Enclosed" TestRunner)
View TestFoo.java
// "(root)/t1/TestFoo.java"
package t1;
import static org.testng.Assert.*;
import org.testng.annotations.*;
public class TestFoo {
static void log(Class k, String mes) {
System.out.println(Thread.currentThread() + " - " + k.toString() + " - " + mes);
}
@msakamoto-sf
msakamoto-sf / .bashrc
Last active May 10, 2020
My Dot Files
View .bashrc
# move to https://github.com/msakamoto-sf/dot-files
@msakamoto-sf
msakamoto-sf / hogan_ex1.groovy
Created Mar 17, 2013
Hogan.groovy examples
View hogan_ex1.groovy
@Grab(group='com.github.plecong', module='hogan-groovy', version='3.0')
import com.github.plecong.hogan.Hogan
def expected = ''
def template = null
def data = [:]
def template_s = ''
// {{{ basic compile()
@msakamoto-sf
msakamoto-sf / start_jetty.groovy
Last active Jan 5, 2021
Jetty + GroovyServlet + Groovy Script = Start Jetty Anywhere !! You only need Groovy :)
View start_jetty.groovy
@Grapes([
@Grab('org.eclipse.jetty.aggregate:jetty-all:8.1.10.v20130312'),
@Grab('com.h2database:h2:1.3.171'),
@Grab('javax.servlet:servlet-api:2.5'),
])
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.*
import org.eclipse.jetty.webapp.*
import javax.servlet.*
import javax.servlet.http.*
@msakamoto-sf
msakamoto-sf / 00_README.md
Last active Oct 11, 2020
JavaMail + Groovy samples.
View 00_README.md

JavaMail + Groovyのサンプル

GroovyでJavaMailの使い方を勉強した時のサンプルコードです。 基本的に JavaMailでのメール送信まとめその1 - あられねこのめも をGroovyでちょこっと手直しした感じのものになります。

サンプルコードの解説

01 - 09 まではひたすらMimeMessageを元にしたメッセージの組み立て方の勉強です。

@msakamoto-sf
msakamoto-sf / groovy_enum_metaClass_demo1.groovy
Last active Dec 20, 2015
Groovy and enum demo. Groovy 1.8.9 doesn't suport enum's abstract method, but static initializer and metaClass makes nealy likely enable it. This is a work arround for http://jira.codehaus.org/browse/GROOVY-4641
View groovy_enum_metaClass_demo1.groovy
// tested on Groovy 1.8.9.
enum GreetEnum {
MORNING("Good Morning"),
AFTERNOON("Good Afternoon"),
EVENING("Good Evening");
static {
MORNING.metaClass.greeting = { String you ->
return delegate.emphasize() + " " + you + ", I'm sleeping..."
}
@msakamoto-sf
msakamoto-sf / t_jna_linux64_syscall_1.groovy
Created Feb 15, 2014
JNA(Java Native Access) and Linux 2.6 (x86_64) system call example #1 using Groovy.
View t_jna_linux64_syscall_1.groovy
/*
* JNA and Linux 2.6 (x86_64) system call example #1.
* (no copyright, license-free, AS-IS, for any commercial or oss or free source code)
*/
@Grapes(
@Grab(group='net.java.dev.jna', module='jna', version='4.0.0')
)
import com.sun.jna.*
/** @see /usr/include/asm/unistd_64.h */