Skip to content

Instantly share code, notes, and snippets.

View kikuchy's full-sized avatar

Hiroshi Kikuchi kikuchy

View GitHub Profile
@kikuchy
kikuchy / main.dart
Created April 4, 2019 08:22
Is there any static code analyzer for Dart to detect Future#then's onError arguments?
void main() {
Future(() => throw Exception())
.then((i) => print(i),
// Statically, no issues found. But it causes RUNTIME error 👇
//
// Uncaught Error: TypeError: Closure 'main_closure1': type '() => void' is not a subtype of type '(Object) => dynamic'
onError: () => print("foo"));
Future(() => throw Exception())
.then((i) => print(i),
@kikuchy
kikuchy / main.dart
Created March 15, 2019 11:36
クロージャーは共変ではないらしく、キャストに失敗して例外を出す例
void useSet<T>(Set<T> s) {
print(s);
}
class UseSet<T> {
void Function(Set<T>) onChange;
void Function(Set) ambiguouse;
}
void main() {
@kikuchy
kikuchy / main.dart
Last active February 22, 2019 09:15
We need restriction by Type Systems 💢
class Key<T> {
final String key;
Key._(this.key);
static final a = Key<String>._("a");
}
void useKey<T>(Key<T> key, T value) {
print(T);
}
void main() {
@kikuchy
kikuchy / main.dart
Created January 17, 2019 11:58
foldの第二引数にラムダ式を渡すとreturnが無くてもコンパイルエラーにならない
void main() {
final Set<int> s = Set();
s.add(1);
s.fold(0, (prev, e) {
final a = e * e;
// return prev + a;
});
}
$ GOOS=windows GOARCH=386 go get -u github.com/Microsoft/go-winio
$ GOOS=windows GOARCH=386 go build main.go
# 失敗のパターンは3つあって、どうやらgoroutineの実行タイミングで変わってきているようです。
# 各パターンでwineがUnhandled page faultのメッセージを出している箇所以降は、goroutineが不正終了してListenしたものが閉じられていないためだと思われます。
# クライアント側が失敗するパターン
$ wine main.exe
0009:fixme:process:SetProcessPriorityBoost (0xffffffff,1): stub
0037:fixme:file:SetFileCompletionNotificationModes 0x98 3 - stub
error
The class 'AndroidEngineer' can't be used as a mixin because it extends a class other than Object.
error
The class 'IOSEngineer' can't be used as a mixin because it declares a constructor.
error
The class 'IOSEngineer' can't be used as a mixin because it references 'super'.
require "socket"
s = TCPSocket.open("localhost", 9000)
s.puts "hello!"
s.close
@kikuchy
kikuchy / thread.cpp
Last active June 18, 2018 07:10
Win32APIでJava風スレッドにしてみた。mingw 8.1.0でラムダ式は使えるっぽいけど、std::functionが使えないのでラムダ式で処理を書くことはできないみたい…Wine 3.0.1でiostream使うと実行時クラッシュするのでprintfで我慢
#include <windows.h>
#include <stdio.h>
template<typename Runnable>
class Thread {
private:
Runnable runnable;
HANDLE handle;
DWORD id;
public:

mingwでもタスクトレイ常駐する系のアプリをWin32APIだけでつくりたい

  • タスクトレイを触るにウィンドウハンドラが必要なので、表示しなくても適当なウィンドウは作っておく必要がある
  • アイコンの扱いが面倒
  • とりあえずbrewでmingwだけ入れればビルドできる
  • mingwのg++で -mwindows -static -DUNICODE オプションが必要(つけないとlibstdc++あたりのdllがないって怒られるし文字化けする)
  • windresではオプションに -c 65001 を指定する必要あり(UTF-8)
  • wine 3.0系の問題なのか、Macでは32bitにしないとwineが起動しない
// app/src/test/(java|kotlin))/(package名)/ExampleUnitTest.kt
@RunWith(AndroidJUnit4::class)
class ExampleUnitTest {
@Test
fun useAppContext() {
val context = InstrumentationRegistry.getTargetContext()
val sp = context.getSharedPreferences("hoge", Context.MODE_PRIVATE)
sp.edit().putBoolean("hoge", true).apply()
assertTrue(sp.getBoolean("hoge", false))