Skip to content

Instantly share code, notes, and snippets.

View msakamoto-sf's full-sized avatar

Masahiko Sakamoto msakamoto-sf

View GitHub Profile
@msakamoto-sf
msakamoto-sf / t_tcp_echo_client_1.groovy
Last active August 29, 2015 13:56
very simple TCP Echo server and client, with "strace"ing server thread : example #1.
/*
* (no copyright, license-free, AS-IS, for any commercial or oss or free source code)
*/
String host = args[0]
int port = args[1].toInteger()
int to_connect = 10 * 1000 // connect timeout in milli secs
int to_read = 10 * 1000 // read timeout in milli secs
SocketAddress sa_local = null // bind to system default address and port.
SocketAddress sa_remote = new InetSocketAddress(host, port)
@msakamoto-sf
msakamoto-sf / t_jna_linux64_syscall_1.groovy
Created February 15, 2014 04:47
JNA(Java Native Access) and Linux 2.6 (x86_64) system call example #1 using 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 */
@msakamoto-sf
msakamoto-sf / groovy_enum_metaClass_demo1.groovy
Last active December 20, 2015 18:19
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
// 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 / 00_README.md
Last active October 11, 2020 02:49
JavaMail + Groovy samples.

JavaMail + Groovyのサンプル

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

サンプルコードの解説

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

@msakamoto-sf
msakamoto-sf / start_jetty.groovy
Last active January 5, 2021 19:54
Jetty + GroovyServlet + Groovy Script = Start Jetty Anywhere !! You only need 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 / hogan_ex1.groovy
Created March 17, 2013 15:57
Hogan.groovy examples
@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 / .bashrc
Last active May 10, 2020 13:57
My Dot Files
# move to https://github.com/msakamoto-sf/dot-files
@msakamoto-sf
msakamoto-sf / TestFoo.java
Last active March 13, 2018 05:49
Nested Test Cases with TestNG (nearly equals JUnit's "Enclosed" TestRunner)
// "(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 / Singleton.java
Created November 18, 2012 02:08
Java + Groovy + TestNG + Maven combination example3 (replace singleton field)
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 / Calc1.groovy
Created November 11, 2012 07:50
Java + Groovy + TestNG + Maven combination example1
package gjt1;
public class Calc1 {
int v1;
int v2;
def Calc1(int a, int b) {
v1 = a;
v2 = b;
}
int calc() {