Skip to content

Instantly share code, notes, and snippets.

@roschlau
roschlau / MutableLazy.kt
Last active November 26, 2017 20:50
Lazy Delegate implementation for a mutable, but lazily initialized variable
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
/**
* Property delegate to allow lazy initialization of a mutable variable.
*/
class MutableLazy<T>(val init: () -> T) : ReadWriteProperty<Any?, T> {
private var value: Optional<T> = Optional.None()
@mgodave
mgodave / futures.kt
Created November 14, 2013 04:35
Akka Futures API in Kotlin (for fun)
import com.google.common.util.concurrent.ListeningExecutorService
import com.google.common.util.concurrent.MoreExecutors
import java.util.concurrent.Executors
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.FutureCallback
import com.google.common.util.concurrent.SettableFuture
import java.util.ArrayList
object KFutures {
@hstaudacher
hstaudacher / Clauses.java
Last active December 19, 2015 02:38
Util to throw exceptions in a nicer way then if( .. ) throw...
/*******************************************************************************
* Copyright (c) 2013 EclipseSource and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* EclipseSource - initial API and implementation
******************************************************************************/
@ulmangt
ulmangt / StayOpenMenuManager.java
Created September 6, 2012 18:56
A SWT/RCP/JFace MenuManager subclass which stays open when one of its MenuItems is clicked
import java.lang.reflect.Field;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.MenuDetectListener;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
@r10r
r10r / gist:2305091
Created April 4, 2012 19:49
embed SWT widget into Swing JFrame
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.browser.Browser;