Skip to content

Instantly share code, notes, and snippets.

View alextkachman's full-sized avatar

Alex Tkachman alextkachman

View GitHub Profile
@alextkachman
alextkachman / gist:9764892
Created March 25, 2014 15:56
Statically typed Angular with Kotlin
package angular.demo
import angular.*
object HelloWorldModule : Module("HelloWorld") {
val hello = constant("hello", "Hello")
val world: String by factory("world") {"World"}
}
@Typed package org.mbte.akkatest
import se.scalablesolutions.akka.actor.*
import java.util.concurrent.TimeUnit
import java.util.concurrent.CountDownLatch
import se.scalablesolutions.akka.config.JavaConfig.AllForOne
import se.scalablesolutions.akka.config.JavaConfig.RestartStrategy
import se.scalablesolutions.akka.config.ScalaConfig.Server
class Akka {
@alextkachman
alextkachman / gist:1006250
Created June 3, 2011 12:17
Type inference in Groovy++ sample
@Typed class GridGainTest {
public static void main(String[] args) {
def local = GridFactory.start("spring-cache.xml").localNode
local.remoteListenAsync(local) { nid, String msg ->
// we infer of course that this is GridListenActor
grid ()
// we infer nid instanceof UUID
println nid.leastSignificantBits
println msg
@alextkachman
alextkachman / gist:998829
Created May 30, 2011 12:22
Simplest web server to handle static content
@Typed package example
import org.mbte.gretty.httpserver.GrettyServer
new GrettyServer() [
// server local address
localAddress: new InetSocketAddress(8081),
// directory where to find static resources
static: "../static",
@alextkachman
alextkachman / gist:981566
Created May 19, 2011 19:45
GPars-like BenchmarkStatelessActorWithArray
@Typed package p
import java.util.concurrent.Executors
import java.util.concurrent.CountDownLatch
import groovypp.channels.ExecutingChannel
import java.util.concurrent.TimeUnit
def pool = Executors.newFixedThreadPool(8)
def t1 = System.currentTimeMillis()
@alextkachman
alextkachman / gist:953764
Created May 3, 2011 17:24
Map/Reduce with Groovy++
ForkJoinPool fjPool = []
def res = fjPool.map(2..<15){ arg ->
// We are in AsyncTaskWithArg<Integer,Integer>
// function which take Integer param and calculate Integer
// both types are type inferenced
//
// method map will fork copy of the task for each element of given Iterable ( 2..<15 Range in this case)
// and when all results ready will merge them in to List<Integer>
// The task itself (the one applied to each element) uses fork/join (which is stupid for Fibonacci)
@alextkachman
alextkachman / gist:829211
Created February 16, 2011 11:05
Groovy++ pattern for listeners
abstract static class Listener<T> {
abstract void call(T oldValue, T newValue)
}
private FList<Listener<T>> listeners = FList.emptyList
final Listener<T> addListener(Listener<T> listener, Executor executor = null) {
if(executor) {
def myListener = listener
listener = { oldValue, newValue ->
@alextkachman
alextkachman / gist:737601
Created December 11, 2010 19:39
Some code on Java & Groovy++ (real piece of Groovy++ compiler)
// Java version
Parameter param = new Parameter(ClassHelper.OBJECT_TYPE, "$it");
VariableExpression ve = new VariableExpression(param);
ve.setSourcePosition(originalProperty);
PropertyExpression prop = new PropertyExpression(ve, originalProperty);
prop.setSourcePosition(originalProperty);
ReturnStatement retStat = new ReturnStatement(prop);
retStat.setSourcePosition(originalProperty);
@alextkachman
alextkachman / gist:701688
Created November 16, 2010 10:55
How 100% statically typed grails controller looks like
def chatService
index: {
def id = request.session.id
[
sessionId: id,
userName: request.session.userName ?: (request.session.userName = chatService.newUserName())
]
}
@Typed package org.mbte.akkatest
import se.scalablesolutions.akka.actor.*
import java.util.concurrent.TimeUnit
import java.util.concurrent.CountDownLatch
import se.scalablesolutions.akka.config.JavaConfig.AllForOne
import se.scalablesolutions.akka.config.JavaConfig.RestartStrategy
import scala.collection.immutable.List as ScalaList
import scala.collection.JavaConversions
import se.scalablesolutions.akka.config.ScalaConfig.Supervise