Skip to content

Instantly share code, notes, and snippets.

@siosio
siosio / DegitalSign.groovy
Created July 24, 2012 23:33
デジタル署名の作成&検証
import java.security.KeyStore
import java.security.Signature
// KeyStoreを使用して証明書をロード
KeyStore keyStore = KeyStore.getInstance("PKCS12");
FileInputStream stream = new FileInputStream("certificate.p12");
keyStore.load(stream, "password".chars);
stream.close();
// 秘密鍵と公開鍵を取得するためのalias
--------------------------------------------------------------------------------
-- count(*)
--------------------------------------------------------------------------------
18:18:19 SQL> select count(*) from message;
COUNT(*)
----------
17718
経過: 00:00:00.04
@siosio
siosio / test.kt
Created July 17, 2012 03:32
Kotlinでフィボナッチ数列的な
import java.util.Iterator
fun main(args: Array<String>) {
fibonacci(1000).forEach {println(it)}
}
fun fibonacci(max: Int): Iterator<Int> {
var current = #(1, 1)
return iterate<Int> {
val next = current._1 + current._2
@siosio
siosio / fizzbuzz.sql
Created July 15, 2012 12:23
SQLでfizzbuzz
select case
when mod(seq.col1, 3) = 0 and mod(seq.col1, 5) = 0 then
'fizzbuzz'
when mod(seq.col1, 3) = 0 then
'fizz'
when mod(seq.col1, 5) = 0 then
'buzz'
else
to_char(seq.col1)
end fizzbuzz
@siosio
siosio / Fuga.groovy
Created July 11, 2012 09:28
クロージャの名前
class Hogehoge {
def cls = {}
static hogefuga = {}
}
cls = {}
def cls2 = {}
def method(Closure c) {
println getDeclaredName(c)
package siosio.validator
import grails.validation.ValidationErrors
import org.junit.Test
import org.junit.Before
class NumCharValidatorTest {
NumCharValidator validator
package siosio.validator
import org.codehaus.groovy.grails.validation.AbstractConstraint
import org.springframework.validation.Errors
class NumCharValidator extends AbstractConstraint {
public static final NAME = "number"
private static final String DEFAULT_MESSAGE = "default.invalid.number.message"
@siosio
siosio / gist:2933736
Created June 15, 2012 00:02
なんか違うものになってしまったけど
class Buzz implements Comparable<Buzz> {
private int index
private Buzz(int index) {
this.index = index
}
def static start(int index) {
while (!isBuzz(index)) {index++}
fun main(args: Array<String>) {
println (30.buzzbuzz().toList())
}
fun Int.buzzbuzz(): java.util.Iterator<Int> {
var buzz = #(0, 0)
fun Int.range(size:Int) = (this + 1 .. this + size)
fun buzzer() = {
if (buzz._1 >= this) {
null
apply plugin: 'java'
defaultTasks 'build'
sourceSets {
main {
java {
srcDir 'main/java'
}
}