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
@kekyo
kekyo / task.md
Last active July 8, 2019 00:51
Task.Runで非同期APIをシミュレートすべきかどうかの判断

朝バタバタしてクリアじゃなかった... ちょっと間違ってましたこういうことです:

  • 多数同時並行するタスクがある場合
    • Windowsの場合はI/O完了ポートの「ブロックされたスレッドを検出するとワーカースレッドを世に放つ」機能があるので、同期APIがブロックしても、ワーカースレッド上限まではOK(ThreadPool.SetMaxThreadsの第二引数completionPortThreads)。
    • Windowsではない環境では必ず上記機能が使えるとは言えない(多分単純スレッドプール)ので、同期APIによるスレッドブロックが発生すると、同時並行動作数はそれ以上伸びない。これを避けたい場合、Task.Run を使わざるを得ない。
  • 多数同時並行したいタスクがない、GUIの場合
    • 同期APIでブロックすると、それがUIスレッドの場合はUIが固まってしまうので、それを避けたいなら Task.Run を使わざるを得ない。但し、継続処理がUIを操作する場合はUIスレッドにマーシャリングすることになり、そのコストはかなり高いことに注意(≒await後の処理でUI部品を操作する場合など)。
  • 多数同時並行したいタスクがない場合
    • 同期APIと非同期APIを比較すると、非同期APIのほうが余分なハンドリングを必要とするコストがあるので、この場合は同期APIをそのまま使うのがいい。

Taskを使うかValueTaskを使うかによる差については、本来はすべてをTaskを返す非同期APIとして定義したいが、ほとんどの場合同期的に完了してしまう(つまり一瞬で操作が完了する、待機する可能性が0ではないが殆ど待機しないというような)処理を、いつもTaskで管理するのはコストが高いので、代わりにValueTaskを使って初めから完了しているものはコストをほとんど0とするようにするという話です。

@stoshiya
stoshiya / selenium chrome.md
Last active June 7, 2019 07:14
MacでSeleniumをつかってChromeを起動するまで

MacでSeleniumをつかってChromeを起動するまで

必要なもの

  • Mac OS X
  • Google Chrome
  • Homebrew
  • Node.js
  • selenium-server-standalone
  • chromedriver
@koral--
koral-- / ImageCaptureHelper.java
Last active January 16, 2019 10:57
Helper for sending ACTION_IMAGE_CAPTURE intent and retrieve its results. Handles all low level operations
//MIT License
//Copyright (c) 2015 Karol Wrótniak, Droids On Roids
package pl.droidsonroids.imagehelpers;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
@rudyryk
rudyryk / CustomTableViewRenderer.cs
Created August 3, 2015 13:17
C# — Custom Xamarin.Forms renderer for TableView to hide empty cells at the bottom
// NoEmptyRowsTableViewRenderer.cs
//
// No Rights Reserved
// http://creativecommons.org/publicdomain/zero/1.0/
//
// Assume you have `MyProject.MyTableView` sublass of
// `Xamarin.Forms.TableView` and want to hide extra
// empty rows at the bottom. All you need on iOS is to set
// `TableFooterView` to empty `UIView` in custom renderer.
//
<div id=root />
<script type=module>
import React from 'https://dev.jspm.io/react@16'
import ReactDOM from 'https://dev.jspm.io/react-dom@16'
ReactDOM.render(
React.createElement('h1', null, 'hello'),
document.querySelector('#root')
)
</script>
@k-kagurazaka
k-kagurazaka / Main.kt
Last active December 20, 2017 01:35
RxCommand with double context extension pattern
interface HasDisposables {
fun Disposable.autoDispose()
fun dispose()
companion object {
operator fun invoke(): HasDisposables = object : HasDisposables {
private val disposables = CompositeDisposable()
@mbostock
mbostock / .block
Last active July 20, 2017 07:30
Circle-Polygon Intersection
license: gpl-3.0
@smallgeek
smallgeek / BusyNotifierCommand.cs
Created April 28, 2017 08:49
2度押し防止コマンド試作
using Reactive.Bindings.Notifiers;
using System;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Reactive.Bindings
{
public class BusyNotifierCommand : BusyNotifierCommand<object>
{
public BusyNotifierCommand(Func<Task> execute)
@azyobuzin
azyobuzin / Program.cs
Created February 20, 2017 18:24
Xamarin の base メソッドを呼ばなければいけない/呼んではいけない奴を抽出
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
@mpen
mpen / ApacheHttpClientGet2.scala
Created October 30, 2009 10:47
Apache HttpComponents HttpClient Get ResponseHandler
// Apache HttpComponents HttpClient Get ResponseHandler
import java.io.File
import java.io.IOException
import java.net.URI
import java.net.URISyntaxException
import java.net.URLDecoder
import java.net.UnknownHostException
import org.apache.commons.io.FileUtils
import org.apache.commons.io.FilenameUtils