2020/06,江端さんの技術メモ

c:\Users\ebata\Desktop\codelab-master>set GOOS=js
c:\Users\ebata\Desktop\codelab-master>set GOARCH=wasm
c:\Users\ebata\Desktop\codelab-master>go build -o main.wasm
package main

import (
    "fmt"
    "syscall/js"
)

type Test struct {
    Num int
}

func (t *Test) Print(this js.Value, args []js.Value) interface{} {
    fmt.Println(t)
    return nil
}

func (t *Test) Twice(this js.Value, args []js.Value) interface{} {
    t.Num *= 2
    return nil
}


func (t *Test) Add(this js.Value, args []js.Value) interface{} {
    t.Num += args[0].Int()
    return nil
}

func (t *Test) GetNum(this js.Value, args []js.Value) interface{} {
    return js.ValueOf(t.Num)
}

func registerCallbacks() {
    var test = &Test{
        Num: 1,
    }
    js.Global().Set("test", js.ValueOf(
        map[string]interface{}{
            "Print": js.FuncOf(test.Print),
            "Twice": js.FuncOf(test.Twice),
            "Add":    js.FuncOf(test.Add),
            "GetNum": js.FuncOf(GetNum),
        },
    ))
}

func main() {
    c := make(chan struct{}, 0)
    registerCallbacks()
    <-c
}
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Go wasm</title>
</head>

<body>
    <script src="wasm_exec.js"></script>
    <script>
        const go = new Go();
        WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
            go.run(result.instance);
        });
    </script>
    <script>
        function getNum(){
            console.log(test.getNum())
        }
    </script>
    <button onClick="test.Print();" id="runButton" >print</button><br>
    <button onClick="test.Twice()" id="runButton">twice</button><br>
    <button onClick="test.Add(1)" id="runButton">add</button><br>
    <button onClick="test.GetNum()" id="runButton">get test.Num</button><br>
</body>
</html>

2020/06,江端さんの技術メモ

このページをまるまる試しました。

Roaming Geofences - Tile38

Roaming Geofences

Tile38 1.2では、geofencesを動的に使用できる強力な新機能が導入されました。これにより、1つ以上の移動体が近くにある場合のリアルタイム監視が可能になります。

一般的な使用例としては、次のようなものがあります。

  • 車両ピックアップサービス: ピックアップを待っている人が近くにいるとき、または人が車に近づいたとき、または車が近くにいるときに瞬時に通知されます。

  • 近接型ソーシャルアプリ: 常にデータベースを照会しなくても、2人のユーザーが近くにいるかどうかを確認する必要がある場合に非常に便利です。


簡単な例:

NEARBY people FENCE ROAM people * 5000

これは people コレクションのローミングフェンスを開きます。フェンスは、同じコレクション内の他のオブジェクトから5000メートル以内にあるオブジェクトを監視しています。

テストするには、2つの端子を開きます。:

ターミナル1

Tile38サーバーに接続し、fenceコマンドを入力します。

$ tile38-cli

localhost:9851> NEARBY people FENCE ROAM people * 5000

ターミナル2

peopleコレクションに2点を追加します。2つ目のsetコマンドは、もう一方の端末に表示されるフェンスイベントをトリガーします。

$ tile38-cli

localhost:9851> SET people bob POINT 33.01 -115.01

localhost:9851> SET people alice POINT 33.02 -115.02

イベントはターミナル1に表示され、以下のようになります。

{

"command":"set",

"detect":"roam",

"hook":"",

"key":"people",

"id":"alice",

"time":"2016-05-24T09:19:44.08649461-07:00",

"object":{"type":"Point","coordinates":[-115.02,33.02]},

"nearby":{

"key":"people",

"id":"bob",

"meters":1451.138152186708

}

}

アリスが更新されてボブは1,451メートル離れていることがわかります。

他にもいくつかの例があります。

# アリスボブがお互いに100メートル以内にいるかを見張ります。

NEARBY people MATCH alice FENCE ROAM people bob 100

# 'a'で始まるオブジェクトは、友達のコレクション内の任意のオブジェクトの100メートル以内にいるかを見張ります。

NEARBY people MATCH a* FENCE ROAM friends * 100

また、webhooksを使用している場合は、このようなフェンスを割り当てることができます。

SETHOOK myhook http://10.0.1.5/hook NEARBY people FENCE ROAM people * 5000

NODWELL Keyword

副次的な効果としては、2つの場合に近くの通知がたくさん届くことがあります。 オブジェクトがお互いに近くに存在し続けます。これが問題であれば nodwellキーワードを使います

tile38-cli> NEARBY people FENCE NODWELL ROAM people * 5000

これにより、2つの接続オブジェクトに対して、近くの通知と遠くの通知が繰り返されるようになります。

2020/06,江端さんの技術メモ

これをやられると、コマンドのコピペをする時に、困ったことになるので、対応を探していたら、"WordPress 半角の「"」や「'」が、全角に変換されてしまう件"と同じ対応したら上手くいったので、メモを残しておきます。

remove_filter("the_content", "wptexturize");
remove_filter("the_excerpt", "wptexturize");
remove_filter("the_title", "wptexturize");

の3行をまとめてfunctions.php(https://wp2.kobore.net/wp-admin/theme-editor.php?file=functions.php&theme=luxech)に追記したら、上手くいきました。

ここを弄って、WordPressが立ち上がらくなって、青さめたことがあったので、動いている状態のログを取っておく。

ただ、動かなくなったら、この画面にすら行けなくなるので、ffftpの画面も付けておく

現時点でのfunctions.phpの中身は以下の通り。

<?php
/**
 * Luxeritas WordPress Theme - free/libre wordpress platform
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * @copyright Copyright (C) 2015 Thought is free.
 * @link http://thk.kanzae.net/
 * @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
 * @author LunaNuko
 */

/* 以下、好みに応じて子テーマ用の関数をお書きください。
 ( Below here, please write down your own functions for the child theme. ) */
remove_filter("the_content", "wptexturize");
remove_filter("the_excerpt", "wptexturize");
remove_filter("the_title", "wptexturize");

ところで、驚くべきことが書かれていたのですが「PHPの最後の終了タグ ?> は付けないでおこう」だそうです。(事実、タグを付けたら、WPが動かなくなった)

functions.phpはあまりさわらないこと、ですね。