Skip to content

Instantly share code, notes, and snippets.

View nobeans's full-sized avatar

Yasuharu Nakano nobeans

  • Yokohama, Japan
View GitHub Profile
package main
import (
"errors"
"fmt"
"os"
)
func main() {
test1()
package main
import "fmt"
func main() {
l1 := make([]string, 0, 0)
fmt.Println(append(l1, "1"))
fmt.Println(append(l1, "2"))
fmt.Println(append(l1, "3"))
fmt.Println(append(l1, "4"), append(l1, "5"), append(l1, "6"))
import org.apache.commons.lang3.RandomUtils
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import org.junit.rules.TestName
import org.springframework.util.StopWatch
import spock.lang.Shared
import spock.lang.Specification
class FileIOSpec extends Specification {
@nobeans
nobeans / deffer_error_sample.go
Created June 12, 2019 06:53
defferでのエラーのハンドリング
package main
import "fmt"
func main() {
fmt.Println("-----")
if err := hoge(); err != nil {
fmt.Println(err)
}
fmt.Println("-----")
def f = new File("/tmp/test.dat")
f.text = "1234567890" * 2
def tryRead(ins) {
def buff = new byte[9]
println ins.read(buff)
println new String(buff)
}
f.withInputStream { ins ->
//
// Helpers
//
void log(String message, boolean linefeed = true) {
if (linefeed) {
System.err.println message
} else {
System.err.print message
}
class ApacheCollectionsSpec extends Specification {
def "BoundedFifoBuffer"() {
given:
def buffer = new BoundedFifoBuffer(3)
when:
buffer.add(1)
buffer.add(2)
buffer.add(3)
import org.spockframework.runtime.SpockTimeoutError
import spock.lang.FailsWith
import spock.lang.Specification
import spock.lang.Timeout
import java.util.concurrent.CopyOnWriteArrayList
class PipedStreamsSpec extends Specification {
PipedOutputStream pout = new PipedOutputStream()
@nobeans
nobeans / trait_issue.groovy
Last active May 15, 2018 04:30
GroovyのTraitのコーナーケースを踏んだ?
// in Groovy 2.4.14
import groovy.transform.CompileStatic
// このようなprivate staticメソッドを使うメソッドをもつtraitに対して...
@CompileStatic
trait Trait {
String traitMethod() { _traitMethod() }
private static String _traitMethod() { "TRAIT" }
}
@nobeans
nobeans / syntax_improvement_in_groovy3.groovy
Last active May 5, 2018 13:11
Groovy 3.0.0から改善されるシンタックス互換性
// Groovy 3.0.0からラムダ記法が使えます。
//def twice = (int num) -> { num * 2 }
//def twice = (num) -> { num * 2 }
def twice = num -> num * 2
twice(100)
assert twice instanceof Closure
def hoge = () -> "HOGE"
assert hoge() == "HOGE"