Skip to content

Instantly share code, notes, and snippets.

@yamkazu
yamkazu / Book.groovy
Last active October 23, 2015 04:09
jggug-grails-bootcampの資材
package sample
class Book {
String title
Integer price
static constraints = {
}
}
@yamkazu
yamkazu / gist:4b29897075c544cb16f5
Created February 2, 2015 14:38
Grails 3.0からなくなったコマンド
add-proxy
clear-proxy
create-hibernate-cfg-xml
create-multi-project-build
create-pom
create-scaffold-controller
install-dependency
install-plugin
install-templates
integrate-with
@yamkazu
yamkazu / 0_reuse_code.js
Created April 3, 2014 13:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#if (${PACKAGE_NAME} != "") package ${PACKAGE_NAME} #end
import spock.lang.Specification
#parse("File Header.java")
class ${NAME} extends Specification {
}
@yamkazu
yamkazu / 111.txt
Last active December 15, 2015 02:29
111
buildGradle = '''\
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
import spock.lang.FailsWith
import spock.lang.Specification
class MockAndStubSpec extends Specification {
@FailsWith(AssertionError)
def "MockとStubを別のインタラクションとして宣言できない"() {
setup:
def publisher = new Publisher()
@yamkazu
yamkazu / DatabaseCleaner.groovy
Last active December 14, 2015 11:29
PostgreSQLですべてのデータを削除する
import groovy.sql.Sql
class DatabaseCleaner {
static excludes = ["databasechangelog", "databasechangeloglock"]
static clean(sql) {
// テーブルデータの削除
sql.eachRow("SELECT tablename FROM pg_tables WHERE schemaname = 'public';") { row ->
if (row.tablename in excludes) return
@Grab('com.googlecode.gbench:gbench:0.3.1-groovy-2.0')
import groovyx.gbench.BenchmarkBuilder
import java.security.MessageDigest
def r = new BenchmarkBuilder().run {
'sha256' {
def digest = MessageDigest.getInstance("SHA-256")
1000000.times { digest.digest("$it".getBytes("UTF-8")) }
}
'sha512' {
def chars = 'a'..'g'
// collate(int size)
// sizeの個数ごとにサブリストを作ってくれる
assert chars.collate(3) == [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
assert chars.collate(5) == [['a', 'b', 'c', 'd', 'e'], ['f', 'g']]
// collate(int size, int step)
// stepの数毎にsizeの個数をとってサブリストを作ってくれる
assert chars.collate(4, 2) == [['a', 'b', 'c', 'd'], ['c', 'd', 'e', 'f'], ['e', 'f', 'g'], ['g']]