Skip to content

Instantly share code, notes, and snippets.

View abreslav's full-sized avatar

Andrey Breslav abreslav

View GitHub Profile
fun Int.divides(d: Int) = this % d == 0
fun fizzbuzz(n: Int) = when {
n divides 15 -> "fizzbuzz"
n divides 3 -> "fizz"
n divides 5 -> "buzz"
else -> "$n"
}
fun result(max: Int) = (0..max) map { n -> fizzbuzz(n) }
annotation class A
fun main(args: Array<String>) {
val f = @A {}
f.javaClass.methods.filter { it.name == "invoke" && it.parameterTypes.isEmpty() }.forEach {
it.annotations.forEach(::println)
println(it)
println()
}
fun main(args: Array<String>) {
val array = Class.forName("java.util.Collection")?.getInterfaces()!!
for (c in array) {
println(c)
c!!.accept(ClassVisitor())
}
}
class ClassVisitor
interface Comparator<T> {
boolean lt(T left, T right);
}
static Object NULL = new Object();
static class LtInf implements Comparator<Object> {
@Override
public boolean lt(Object left, Object right) {
ModuleConfiguration moduleConfiguration = new ModuleConfiguration() {
@Override
public void addDefaultImports(@NotNull Collection<JetImportDirective> directives) {
for (ImportPath defaultJetImport : DefaultModuleConfiguration.DEFAULT_JET_IMPORTS) {
directives.add(JetPsiFactory.createImportDirective(project, defaultJetImport));
}
}
@Override
public void extendNamespaceScope(
class A(val b : B, val c : C) {...}
fun test() {
val a = A(
b = B(),
c = C()
)
}
public static void compareNamespaces(@NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb, boolean includeObject,
@NotNull File txtFile) {
String serialized = new NamespaceComparator(includeObject).doCompareNamespaces(nsa, nsb);
try {
if (!txtFile.exists()) {
FileUtil.writeToFile(txtFile, serialized);
Assert.fail("Expected data file did not exist. Generating: " + txtFile);
}
String expected = FileUtil.loadFile(txtFile);
@abreslav
abreslav / gist:2569478
Created May 1, 2012 16:37
Kotlin + JUnit
package hhh.csp
import org.junit.*
import org.junit.rules.ExpectedException
import junit.framework.TestCase
import junit.framework.TestSuite
public class IntervalTest(name :String) : TestCase(name) {
fun testIntervalPlus() {
@abreslav
abreslav / hello.kt
Created March 29, 2012 07:53
Hello, world!
fun main(args : Array<String>) {
println("Hello, GitHub!")
}
@abreslav
abreslav / JavaKeywords.kt
Created March 27, 2012 07:45
Running functions named as Java keywords (in Kotlin)
fun assert(i : Int) = println(i)
fun abstract(i : Int) = println(i)
fun boolean(i : Int) = println(i)
fun `break`(i : Int) = println(i)
fun byte(i : Int) = println(i)
fun case(i : Int) = println(i)
fun catch(i : Int) = println(i)
fun char(i : Int) = println(i)
fun `class`(i : Int) = println(i)
fun const(i : Int) = println(i)