Skip to content

Instantly share code, notes, and snippets.

@ruimo
ruimo / JsConstraints.scala
Created July 17, 2014 23:50
ConstraintFormat.pattern alternative
package helpers
import play.api.libs.json.Reads
import play.api.data.validation.ValidationError
import play.api.libs.json.JsError
import play.api.libs.json.JsSuccess
// Use instead of ConstraintFormat.pattern
object JsConstraints {
def regex(r: => scala.util.matching.Regex, error: String = "error.pattern")(implicit reads: Reads[String]) =
package main
import "fmt"
type NamedVisitor struct {
onNormalName func(NormalName)
onFullName func(FullName)
}
type Named interface {
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Objects.requireNonNull;
class Foo<T> {
final List<T> members;
@SafeVarargs
Foo(T... a) {
@ruimo
ruimo / Test.java
Created July 31, 2015 08:20
Java8だと型推論してくれないケース。
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
public class Test {
static final ImmutableMap<String, Function<Void, Integer>> factories =
ImmutableMap.builder()
.put("Hello",
new Function<Void, Integer>() {
@Override
public Integer apply(Void arg) {
@ruimo
ruimo / Mouse.java
Created May 27, 2016 08:54
スクリーンセーバを抑制するせこいプログラム
import java.awt.MouseInfo;
import java.awt.PointerInfo;
import java.awt.Robot;
public class Mouse {
public static void main(String... args) throws Exception {
Robot r = new Robot();
while (true) {
PointerInfo pi = MouseInfo.getPointerInfo();
r.mouseMove(pi.getLocation().x + 1, pi.getLocation().y + 1);
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
fn tail() -> io::Result<String> {
BufReader::new(File::open("/tmp/foo.txt")?).lines().last().unwrap_or(Ok(String::new()))
}
fn main() {
public class FooTest {
static class WithValue<T> {
final T v;
WithValue(T v) {
this.v = v;
}
void doTest(Consumer<T> f) {
f.accept(v);
}
class Foo {
private final OptionalInt testPort = new Supplier<OptionalInt>() {
public OptionalInt get() {
String tp = System.getProperty("test.port");
return tp == null ? OptionalInt.empty() : OptionalInt.of(Integer.parseInt(tp));
}
}.get();
}
abstract class Iterator<E extends Exception> {
abstract boolean hasNext() throws E;
}
class DumbIterator extends Iterator<RuntimeException> {
boolean hasNext() throws RuntimeException {
return true;
}
}
use std::io;
fn main() {
println!("Input number!");
let mut inp = String::new();
io::stdin().read_line(&mut inp);
println!("Your input is: {}", inp);
}