Skip to content

Instantly share code, notes, and snippets.

View amay077's full-sized avatar
🏠
Working from home

amay077 amay077

🏠
Working from home
View GitHub Profile
@amay077
amay077 / PromiseCompletionSource.ts
Created July 24, 2018 06:16
PromiseCompletionSource what is like TaskCompletionSource<T> in C#
export class PromiseCompletionSource<T> {
public readonly promise: Promise<T>;
private resolver: (x?: T) => void;
private rejector: (reason?: any) => void;
constructor() {
this.promise = new Promise<T>((resolve, reject) => {
this.resolver = resolve;
this.rejector = reject;
package your.awesome.domain
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MediatorLiveData
fun <T> LiveData<T>.filter(matcher: (T?)->Boolean): LiveData<T> {
val result = MediatorLiveData<T>()
result.addSource(this, {
if (matcher.invoke(it)) {
@amay077
amay077 / BroadcastChannelExt.kt
Created June 7, 2018 07:01
Convert BroadcastChannel(via Kotlin coroutines) to LiveData
package your.awesome.domain
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.consumeEach
import kotlinx.coroutines.experimental.launch
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Diagnostics;
namespace GesturesSample
{
public partial class GesturesSampleViewController : UIViewController
{
@amay077
amay077 / clean.ps1
Created January 29, 2018 08:59
Script for delete bin/ and obj/ directory in child directories.
$dirs = Get-ChildItem -Recurse * | ? { $_.PSIsContainer} | % { $_.FullName} | grep -e bin$ -e obj$
foreach ($dir in $dirs) {
# echo $dir
rm -rf $dir
}
@amay077
amay077 / whitelist.md
Last active January 22, 2018 11:25 — forked from okohs/whitelist.md
20180122_定時前に帰宅できた企業

はじめに

書き方

該当する各社の対応欄に企業名を書いてください。備考があれば適宜カッコ書きしてください。

目的

  • 定時前に帰宅させてくれるホワイトな会社を気軽に作りたい
  • 定時前に帰宅させてくれるホワイトな会社がホワイトアピールできる場があれば良いな

@amay077
amay077 / firstIndexOrNull.kt
Created December 6, 2017 05:58
firstIndexOrNull in Kotlin collections
inline fun <T> Iterable<T>.firstIndexOrNull(predicate: (T) -> Boolean): Int? {
return this.mapIndexed { index, place -> Pair(index, place) }
.firstOrNull() { predicate(it.second) }
?.first
}
@amay077
amay077 / <= Forms 2.3.2
Created January 11, 2017 12:43 — forked from jimmgarrido/AdjustResize.md
AdjustResize Workaround for Xamarin.Forms
protected override void OnCreate(Bundle bundle)
{
ToolbarResource = Resource.Layout.toolbar;
TabLayoutResource = Resource.Layout.tabs;
base.OnCreate(bundle);
Window.SetSoftInputMode(SoftInput.AdjustResize);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
@amay077
amay077 / LiveDataExtensions.kt
Created November 2, 2017 08:52
LiveData.observe is NOT onChanged.
package your.awesome.package
fun <T> LiveData<T>.observeOnChanged(owner : LifecycleOwner, observer : Observer<T>) : Unit {
var prev : T? = null
this.observe(owner, Observer<T> {
if (!(prev?.equals(it) ?: false)) {
observer.onChanged(it)
}
prev = it
})
public void singleThreadExecutorBasicTest() throws Exception {
final ExecutorService executor = Executors.newSingleThreadExecutor();
Log.d(TAG, "Primary ThreadID:" + Thread.currentThread().getId());
executor.submit(new Runnable() {
@Override
public void run() {
Log.d(TAG, "Run task A. ThreadId:" + Thread.currentThread().getId());
}
});