Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrey Breslav abreslav

View GitHub Profile
View calc.java
import java.io.FileReader;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Created with IntelliJ IDEA.
* User: smevok
* Date: 05.07.12
View akka.kt
package sample.hello
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.UntypedActor
import akka.actor.UntypedActorContext
import akka.actor.ActorPath
import scala.concurrent.duration.Duration
import java.util.HashMap
import akka.actor.ActorSystem
View sample.kt
class Bar {
fun invoke(x: Int): Int = x
}
class Foo {
val get: Bar = Bar()
}
fun foo () {
View layoutParams.kt
package ru.ifmo.rain.adsl;
import java.io.FileOutputStream
fun main(args: Array<String>) {
val generator = Generator(FileOutputStream("out.kt"), args[0], args[1])
generator.run()
}
@abreslav
abreslav / kotlin-2013-14.markdown
Last active December 26, 2015 20:39
Kotlin Project Theme(s) for Open Academy - 2013/14
View kotlin-2013-14.markdown

The Kotlin Programming Language

Kotlin is a modern statically typed programming language targeting the Java and JavaScript platforms. It is conceived as a "modern language for industry", keeping a balance between flexibility and readability, expressiveness and safety.

Project Overview

A modern programming language is much more than a grammar. Principal susystems of Kotlin include

  • Compiler front-end
  • Lexer/Parser translates text into a syntax tree, reports syntax errors
@abreslav
abreslav / nlr.kt
Created October 10, 2013 11:24
Non-local returns in Kotlin
View nlr.kt
// Sometimes you are inside a lambda and want to return a value from some surrounding function (or surrounding lambda)
fun foo(): Any? {
return withNLR(default = 25) {
listOf(1, 2, 3).forEach {
if (it > 2) doReturn(it)
}
}
}
View Permutations.pas
procedure permutations(var a: array[1..N] of Integer; pos: Integer);
begin
if pos >= N then begin
for i := 1 to N do
Write(a[i], ' ');
WriteLn;
end;
for i := 1 to N do begin
a[i] := i;
@abreslav
abreslav / Sample.java
Last active December 16, 2015 03:39
A question about getClass()
View Sample.java
/*
* A question about Java (not Kotlin!), first asked by Alexander Udalov (@udalov).
*
* How many calls to getClass() does the code below make?
* Curiously enough, the answer is ONE (see the byte codes below).
*
* Now the questions is: why does javac emit the call to getClass()?
*/
class C {
View subsequence.demo.kt
/*
Play with this code at
[http://goo.gl/yPtkb](Kotlin Web Demo)
*/
View fizzbuzz.kt
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) }