This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type NamedVisitor struct { | |
onNormalName func(NormalName) | |
onFullName func(FullName) | |
} | |
type Named interface { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FooTest { | |
static class WithValue<T> { | |
final T v; | |
WithValue(T v) { | |
this.v = v; | |
} | |
void doTest(Consumer<T> f) { | |
f.accept(v); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Iterator<E extends Exception> { | |
abstract boolean hasNext() throws E; | |
} | |
class DumbIterator extends Iterator<RuntimeException> { | |
boolean hasNext() throws RuntimeException { | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
fn main() { | |
println!("Input number!"); | |
let mut inp = String::new(); | |
io::stdin().read_line(&mut inp); | |
println!("Your input is: {}", inp); | |
} |
OlderNewer