Skip to content

Instantly share code, notes, and snippets.

View hannesstruss's full-sized avatar
🤖

Hannes Struß hannesstruss

🤖
View GitHub Profile
@hannesstruss
hannesstruss / ChannelSwitchMap.kt
Last active August 6, 2018 06:57
Attempt at implementing RxJava's switchMap for Kotlin Coroutine Channels
import kotlinx.coroutines.experimental.Unconfined
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.consumes
import kotlinx.coroutines.experimental.channels.produce
import kotlinx.coroutines.experimental.selects.whileSelect
import kotlin.coroutines.experimental.CoroutineContext
fun <T, R> ReceiveChannel<T>.switchMap(context: CoroutineContext = Unconfined,
transform: suspend (T) -> ReceiveChannel<R>): ReceiveChannel<R> {
val input = this
diff -ru api/myapp/Gemfile noapi/myapp/Gemfile
--- api/myapp/Gemfile 2017-05-30 16:10:00.000000000 +0200
+++ noapi/myapp/Gemfile 2017-05-30 16:09:43.000000000 +0200
@@ -12,21 +12,8 @@
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
-# Use SCSS for stylesheets
-gem 'sass-rails', '~> 5.0'
-# Use Uglifier as compressor for JavaScript assets
//: Playground - noun: a place where people can play
import UIKit
import RxSwift
protocol ListSource {
associatedtype ItemT
func getItems(index: Int) -> [ItemT]
}
@hannesstruss
hannesstruss / BaseActivity.java
Created November 22, 2016 21:59
Conductor Injection
class BaseActivity extends AppCompatActivity {
private ActivityComponent activityComponent;
@Override public void onCreate(Bundle savedInstanceState) {
activityComponent = DaggerActivityComponent.builder()
.appComponent(((MyApp) getApplicationContext()).getComponent())
.build();
activityComponent.inject(this);
}
@hannesstruss
hannesstruss / time.swift
Created October 27, 2016 09:20
Swift measure time
import Foundation
func measure(op: () -> ()) -> Double {
let startTime = CFAbsoluteTimeGetCurrent()
op()
let elapsed = CFAbsoluteTimeGetCurrent() - startTime
return Double(elapsed)
}
@hannesstruss
hannesstruss / EasterEggTimer.java
Created July 15, 2016 12:34
Easter Egg Timer
import java.util.List;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.subjects.PublishSubject;
public class KonamiTimer {
private final PublishSubject<Integer> input;
private final int triggerCount;
import android.util.Log;
import rx.Observable;
import rx.Observer;
class Either<T> {
private final T value;
private final Throwable throwable;
public static <T> Either<T> ofValue(T value) {
@hannesstruss
hannesstruss / gist:827dad670971456adb8b
Last active August 29, 2015 14:09
Treat an object as a singleton in one scope, the Yo-Dawg way
@Module(injects = MyActivityModule.class)
class MotherModule {
// ...snip
}
@Module(
addsTo = MotherModule.class,
injects = {MyActivity.class, MyFragment.class}
)
class MyActivityModule {
@hannesstruss
hannesstruss / build.gradle
Created June 24, 2014 14:23
What fixed Android Instrumentation Tests on Gradle for me
configurations {
androidTestCompile.exclude group: 'com.android.support', module: 'support-v4'
}