Skip to content

Instantly share code, notes, and snippets.

View ngsw-taro's full-sized avatar

Taro Nagasawa ngsw-taro

View GitHub Profile
@ngsw-taro
ngsw-taro / Yavi.kt
Created October 31, 2018 07:20
Yavi Kotlin Extensions
data class UserPostBody(val age: Int?,
val name: String?)
@JvmName("intConstraint")
fun <T> ValidatorBuilder<T>.constraint(prop: KProperty1<T, Int?>, block: IntegerConstraint<T>.() -> Unit): ValidatorBuilder<T> {
return this.constraint(prop, prop.name) { it.apply(block) }
}
@JvmName("charSequenceConstraint")
fun <T, E : CharSequence?> ValidatorBuilder<T>.constraint(prop: KProperty1<T, E>, block: CharSequenceConstraint<T, E>.() -> Unit): ValidatorBuilder<T> {
@ngsw-taro
ngsw-taro / kiyoshi.kt
Last active March 15, 2016 12:42
ズンドコ
/**
* 実行結果例:
* ドコズンズンズンズンズンズンドコズンドコドコドコズンドコズンズンズンドコズンズンズンズンドコキ・ヨ・シ!
* ドコズンドコズンドコズンドコドコドコドコ┗(^o^)┛wwwwww┏(^o^)┓ドコドコドコドコwwwwwww
*/
fun キヨシ() {
val random = Random()
fun next() = if (random.nextBoolean()) "ズン" else "ドコ"
tailrec fun go(zunOrDoko: String, zunCount: Int, dokoCount: Int) {
print(zunOrDoko)
@ngsw-taro
ngsw-taro / Sample.kt
Last active January 7, 2016 02:53
Type class in Kotlin (failed)
import Option.None
import Option.Some
interface Type<out A, out B: Type<A, B>>
sealed class Option<out A>: Type<A, Option<A>> {
object None: Option<Nothing>() {
override fun toString(): String = "None"
}
import com.google.inject.Guice
import javax.inject.Inject
import kotlin.properties.Delegates
class Greeter {
fun greet() {
println("Hello")
}
}
@ngsw-taro
ngsw-taro / game.rs
Created October 28, 2014 11:42
Rust超入門勉強会でつくったやつ #learnrust_jp
// TODO かっこよくする
use std::io;
use std::rand;
const MAX: uint = 100;
fn main() {
println!("数当てゲーム");
println!("範囲: 0~{}", MAX);
fun main(args : Array<String>) {
}
enum class TicketStatus {
OPEN
FIXED
}
trait Ticket {
val id: Long
@ngsw-taro
ngsw-taro / gist:9202801
Created February 25, 2014 04:41
Scala朝練(2)
package com.taroid.scala.practice
import scala.annotation.tailrec
object SlidePuzzle {
def main(args: Array[String]) {
val board = Board(List(3, 1, 2, 4, 0, 5, 6, 7, 8), 3, 0)
solve(List(new History(List(board)))).boards.foreach(println)
@ngsw-taro
ngsw-taro / OnePersonGame.scala
Last active August 29, 2015 13:56
Scala朝練
package com.taroid.scala.practice
import scala.collection.immutable.Queue
object OnePersonGame {
def main(args: Array[String]) {
import Operations._
test(solve(List()), List())
test(solve(List(5)), List(REMOVE))
@ngsw-taro
ngsw-taro / Main.scala
Last active December 24, 2015 01:38
駅すぱあとのWebAPIを使って駅名しりとり
package com.taroid.ekisample
import scala.collection.mutable
import scala.xml.XML
import java.net.URLEncoder
object Main {
def main(args: Array[String]) {
val shiritori = new Shiritori()
import java.awt.AWTException;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.InputEvent;
public class Main {
public static void main(String[] args) throws InterruptedException, AWTException {
final Robot robot = new Robot();