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) {
#!/bin/sh
SOURCE="/PFAD/ZU/Apps Native/Android/_Assets"
TARGET=/PFAD/ZU/openfish/GYG_Android/res
set -x
cp "$SOURCE/mdpi/$1" "$TARGET/drawable-ldpi/"
cp "$SOURCE/mdpi/$1" "$TARGET/drawable-mdpi/"
cp "$SOURCE/hdpi/$1" "$TARGET/drawable-hdpi/"
@hannesstruss
hannesstruss / gist:4761410
Created February 12, 2013 10:22
get a list of postgres table and index sizes
DBNAME=
QUERY="select tablename from pg_catalog.pg_tables where tablename not like 'sql_%' and tablename not like 'pg_%';"
for table in `psql $DBNAME -t -c "$QUERY"`; do
TABLE_QUERY="select pg_size_pretty(pg_relation_size('$table'));"
TABLE_SIZE=`psql $DBNAME -t -c "$TABLE_QUERY"`
TOTAL_QUERY="select pg_total_relation_size('$table');"
TOTAL=`psql $DBNAME -t -c "$TOTAL_QUERY"`
INDEX_QUERY="select pg_size_pretty(pg_total_relation_size('$table') - pg_relation_size('$table'));"