Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Tkachman alextkachman

View GitHub Profile
@alextkachman
alextkachman / gist:9764892
Created Mar 25, 2014
Statically typed Angular with Kotlin
View gist:9764892
package angular.demo
import angular.*
object HelloWorldModule : Module("HelloWorld") {
val hello = constant("hello", "Hello")
val world: String by factory("world") {"World"}
}
@alextkachman
alextkachman / gist:9802138
Last active Aug 29, 2015
Failing kotlin2js codegen for delegated extension properties
View gist:9802138
// Kotlin example
class Delegate() {
fun get(obj: String, desc: PropertyMetadataImpl) : String = obj.toString() + ".log"
}
val String.log by Delegate()
fun main(args : Array<String>) {
println("Hello, world!".log)
@alextkachman
alextkachman / gist:8d0ad2bc21307b689819
Last active Aug 29, 2015
Any object can be event target
View gist:8d0ad2bc21307b689819
angular.module('EventTarget',[])
.run(['$injector',function($injector){
function removeFromList(list,item) {
var next = item.next || null
var prev = item.prev || null
if (prev) {
prev.next = next
}
else {
@alextkachman
alextkachman / gist:bda667b09c0c4b7f9ee8
Last active Aug 29, 2015
Patch for injector to resolve promises
View gist:bda667b09c0c4b7f9ee8
(function(angular){
"use strict";
/**
* Patched $injector.invoke
*
* It allows in many situations to avoid promise related boilerplate like
*
* factory('$loggedUser',['$login','$loadedConfig',function($login,$loadedConfig){
* return $login.then(function($login){
View Akka with Groovy++
@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
@alextkachman
alextkachman / gist:701688
Created Nov 16, 2010
How 100% statically typed grails controller looks like
View gist:701688
def chatService
index: {
def id = request.session.id
[
sessionId: id,
userName: request.session.userName ?: (request.session.userName = chatService.newUserName())
]
}
@alextkachman
alextkachman / gist:737601
Created Dec 11, 2010
Some code on Java & Groovy++ (real piece of Groovy++ compiler)
View gist:737601
// 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:829211
Created Feb 16, 2011
Groovy++ pattern for listeners
View gist:829211
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:953764
Created May 3, 2011
Map/Reduce with Groovy++
View gist:953764
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:981566
Created May 19, 2011
GPars-like BenchmarkStatelessActorWithArray
View gist:981566
@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()