Skip to content

Instantly share code, notes, and snippets.

View twogood's full-sized avatar

David Eriksson twogood

View GitHub Profile
@twogood
twogood / ScopeFunctions.cs
Last active March 7, 2025 02:59
Kotlin Scope Functions (Also, Let, Run) in C# .NET Core
public static class ScopeFunctions
{
public static T Also<T>(this T self, Action<T> action)
{
action(self);
return self;
}
public static TResult Let<T, TResult>(this T self, Func<T, TResult> func) => func(self);
[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service
[Service]
SyslogIdentifier=%i
Restart=always
WorkingDirectory=/etc/docker/compose/%i
@twogood
twogood / DaggerViewModelFactory.kt
Created January 25, 2019 22:32
Android Jetpack ViewModel, Dagger 2, Kotlin coroutines
package example
import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import dagger.Binds
import dagger.MapKey
import dagger.Module
import javax.inject.Inject
import javax.inject.Provider
import kotlin.reflect.KClass
@twogood
twogood / transformAsyncPair.kt
Created November 14, 2017 13:56
Create ListenableFuture<Pair<A, B>> from ListenableFuture<A> and ListenableFuture<B>
fun <A, B> transformAsyncPair(futureA: ListenableFuture<A>, futureB: ListenableFuture<B>, executor: Executor): ListenableFuture<Pair<A, B>> {
return Futures.transformAsync(futureA, AsyncFunction<A, Pair<A, B>> { a ->
Futures.transformAsync(futureB, AsyncFunction<B, Pair<A, B>> { b ->
Futures.immediateFuture(Pair<A, B>(a!!, b!!))
}, executor)
}, executor)
}
@twogood
twogood / studio.sh
Created October 20, 2017 20:55
Android studio 3 beta fix
LC_NUMERIC="en_US.UTF-8"
@twogood
twogood / LocalDateColumnMapper.java
Created June 13, 2017 13:26
Using LocalDate fields with BeanMapper in JDBI
//
// USAGE:
//
// jdbi.registerColumnMapper(new LocalDateColumnMapper());
//
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
@twogood
twogood / LocalDateArgumentFactory.java
Created June 13, 2017 13:23
ArgumentFactory to support LocalDate with @BindBean in JDBI
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.time.LocalDate;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.Argument;
import org.skife.jdbi.v2.tweak.ArgumentFactory;
package com.claimtowers.common.asynctask;
public class AsyncTaskResult<T> {
private T result;
private Exception exception;
public AsyncTaskResult(T result) {
this.result = result;
}
@twogood
twogood / gist:209aaa495f87a5563fe3
Last active May 17, 2016 15:12
idea phpstorm ibus keyboard fix
ibus restart && sleep 1 && ibus engine xkb:se::swe
@twogood
twogood / CustomMenu.php
Created November 9, 2012 11:53
Customizing Zend\View\Helper\Navigation\Menu
<?php
namespace Application\View\Helper\Navigation;
use Zend\View\Helper\Navigation\Menu;
class CustomMenu extends Menu
{
// override methods as needed
}