Skip to content

Instantly share code, notes, and snippets.

@dtmilano
dtmilano / colors
Created November 26, 2019 01:31
Shows terminal colors
#! /bin/bash
n=32
arg=setaf
text='Hello World! This is %s %d'
_help()
{
printf 'usage: %s [--help|-H] [--16] [--256] [-t|--tiny] [--background|-b]\n' "$(basename $0)"
exit 0
@dtmilano
dtmilano / lex-bot-tester-alexa-bitcoin.py
Created May 12, 2018 21:00
Culebra Alexa Android script sample
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2018 Diego Torres Milano
Created on 2018-04-07 by Culebra v15.1.2
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
@dtmilano
dtmilano / test_book_my_trip_reserve_car.py
Last active February 21, 2018 06:57
urutu create test
#! /usr/bin/env python
import sys
import unittest
from lex_bot_tester.aws.alexa.alexaskilltest import AlexaSkillTest
verbose = True
class GeneratedTests(AlexaSkillTest):
def test_book_my_trip_reserve_car(self):
@dtmilano
dtmilano / test_crypto_get_price.py
Created February 6, 2018 22:13
AlexaSkillManagementClientTests test for Crypto skill
class AlexaSkillManagementClientTests(AlexaSkillTest):
def test_crypto_get_price(self):
skill_name = 'CryptoSkill'
intent = 'GetPrice'
coin = 'Bitcoin'
conversation = [
{'slot': None, 'text': 'ask Crypto what is the {} price?'.format(coin)},
]
simulation_result = self.conversation_text(skill_name, intent, conversation, verbose=verbose)
self.assertRegex(
@dtmilano
dtmilano / plot_dumpsys_meminfo.py
Created January 25, 2018 04:35
Plots the dumpsys output using AndroidViewClient/culebra
def __plot_dumpsys_meminfo(self, pkg, activity, method=None):
self.device.shell("am force-stop %s" % pkg)
for n in range(20):
if n % 5 == 0:
self.device.shell(
"run-as %s pgrep -L 10 %s" % (pkg, pkg))
self.device.startActivity("%s/%s" % (pkg, activity))
time.sleep(2)
if method:
method()
@dtmilano
dtmilano / test_book_my_trip_reserve_a_car.py
Created January 23, 2018 16:46
Sample test showing an Alexa conversation for BookMyTripSkill
class AlexaSkillManagementClientTests(AlexaSkillTest):
def test_book_my_trip_reserve_a_car(self):
skill_name = 'BookMyTripSkill'
intent = 'BookCar'
conversation = [
{'slot': None, 'text': 'ask book my trip to reserve a car'},
{'slot': 'CarType', 'text': 'midsize'},
{'slot': 'PickUpCity', 'text': 'buenos aires'},
{'slot': 'PickUpDate', 'text': 'tomorrow'},
@dtmilano
dtmilano / test_conversation_text_booj_car.py
Last active December 16, 2017 06:02
lex-bot-tester sample: Data oriented approach
def test_conversations_text_book_car(self):
bot_name = 'BookTrip'
bot_alias = 'BookTripLatest'
user_id = 'ClientId'
conversation_definition = {
'BookCar': [
('reserve a car', DialogState.ELICIT_SLOT, {}),
('L.A.', DialogState.ELICIT_SLOT, {}),
('next week', DialogState.ELICIT_SLOT, {'PickUpDate': RE_WEEK}),
('a month from now', DialogState.ELICIT_SLOT, {'ReturnDate': RE_DATE}),
@dtmilano
dtmilano / lex-bot-tester-sample.py
Created December 7, 2017 23:07
lex-bot-tester sample: AWS Lex Bot tester demonstration code
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Lex Bot Tester
Copyright (C) 2017 Diego Torres Milano
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 3 of the License, or
(at your option) any later version.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import re
import sys
import os
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
@dtmilano
dtmilano / adb-emu-kill.exp
Last active November 17, 2016 16:10
`adb emu kill` does not work in latest `adb` versions. This is a workaround using `expect`.
#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Wed Jun 29 12:07:46 2016
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,