Sunday, April 30, 2023

Using async in inline Editor of GCP Dialogflow. But, timeout too short.

 


Using async in inline Editor of GCP Dialogflow 

/* experimental: [asyncawait] */

https://stackoverflow.com/questions/42637630/does-jshint-support-async-await/48772304#48772304


to know queryText from the user

https://stackoverflow.com/questions/60408929/how-do-you-read-query-the-response-body-in-api-v2-of-dialogflow-fulfillment


function handleRequest(request, response) { const queryText = request.body.queryResult.queryText; // use the queryText variable to process the user's input }


sample code (without async)

https://github.com/priyankavergadia/AppointmentScheduler-GoogleCalendar/blob/master/index.js


Dialogflow CX timeout only 30 sec

Dialogflow ES timeout only 15 sec

https://groups.google.com/g/dialogflow-cx-edition-users/c/jajSEPqhYZE


Following code didn't work.

  async function answerQuestion(agent) {

    const response = await axios.post(

...    {

      message: JSON.stringify(request.body.queryResult.queryText)

    },

    {

      headers: { 'Content-Type': 'application/json' },

      timeout: 2 * 60 * 1000

    }

    );

    agent.setContext({ name: "Question", result: response });

    agent.add(`${response.data.data.answer} \n\n ${response.data.data.sources}`);

  }


Thursday, November 18, 2021

Wednesday, June 30, 2021

mysql 5.7 mac app my.cnf

 Mysql 5.7 from mysql 

$ /usr/local/mysql-5.7.31-macos10.14-x86_64/bin/mysql --help --verbose | grep my.cnf

                      order of preference, my.cnf, $MYSQL_TCP_PORT,

/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf


It works when I created /etc/my.cnf

$ cat /etc/my.cnf

[mysqld]

default_time_zone='-08:00'


Homebrew mysql

$ mysql --help --verbose | grep my.cnf

                      order of preference, my.cnf, $MYSQL_TCP_PORT,

/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf


/usr/local/etc/my.cnf exists


Thursday, November 5, 2020

python json serialization dacite

 

 Handle nested Dict

https://github.com/konradhalas/dacite


Tuple issue

Tuple --> json list --> python list

from_dict(A, {'x': x}, config=Config(check_types=False))


Friday, April 4, 2014

Sending touch event to the android device by using monkeyrunner



Using the monkeyrunner, you can control the device with connected on a pc.
It is contained in the android sdk from google.

http://developer.android.com/tools/help/monkeyrunner_concepts.html


Preparation

  1. Install android sdk (recent version, maybe?)
  2. Turn on the debugging option of the device

  3. If DOWN_AND_UP is not working well,
    Settings >  Pointer speed > Lower the speed


Write following python for the first try.

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Presses the Menu button
device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)
# Touches (x, y) position
device.touch(x, y, MonkeyDevice.DOWN_AND_UP)

Connect your device to your pc, confirm it is well being debugging.
Type the following script.
$ adb devices

If it is well connected, it will reply device's some string.

To confirm that the touch is working well, I suggest you run some paint app first such as Sketchbook express, Evernote skitch.

With the device connected to the pc, run monkeyrunner with your python script.

<android sdk directory>/tools/monkeyrunner <your script>.py

(x, y) position is dependent on your device's resolution (pixel coordination).
(500, 500) is ok, I think.

If you want to know exact position of the device, turn some settings on.

  1. Developer options > Input > Show touches CHECK
  2. Developer options > Input > Pointer location CHECK
With this setting, you can check the exact coordinate of the location when you touch somewhere.
Location will be shown on the top of the screen.