Pages

Saturday, June 06, 2020

Python / Speech recognition / Google recognition

Install dependencies:
pip3 install SpeechRecognition pip3 install pyaudio
Test installation:
python3 -m speech_recognition
Try:
import speech_recognition recognizer = speech_recognition.Recognizer() exitRequested = False while True: with speech_recognition.Microphone() as source: recognizer.adjust_for_ambient_noise(source, duration = 1) print("Speak: ") audio = recognizer.listen(source) try: text = recognizer.recognize_google(audio, None, "en-US") print("Said: " + text) if (text is not None and text == "exit"): break except: print("Error on trying to recognize audio.")

Sunday, May 17, 2020

TensorFlow - Fedora 32

packages="absl absl-py astunparse gast google google-api-python-client google-cloud-translate \ class="source">google-pasta keras keras_preprocessing matplotlib numpy opt_einsum protobuf tensorboard \ termcolor wrapt tenssorboard tensorflow" for package in $packages; do sudo pip install $package done

Wednesday, February 26, 2020

Apache Tomcat - Administration configuration

In config/tomcat-users.xml add:
<role rolename="admin-gui"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="tomcat" password="<PASSWORD>" roles="admin-gui, manager-gui, manager-script"/>
Replace <PASSWORD> with your Tomcat appropriate password.

Tuesday, January 07, 2020

Python - Return array from array iteration

def x(): return [[i, j] for i in [1, 2, 3] for j in [3, 4, 5]] y = x() for i in y: print(i[0], i[1])
Output:
1 3 1 4 1 5 2 3 2 4 2 5 3 3 3 4 3 5

Tuesday, December 24, 2019

Python / Serialization / JSON / Base64

import json import base64 # JSON account_str = '{ "name": "AJ", "number": "123-4", "bank": {"name": "Abc", "branch": "555", "code": "123"}, "balance": 123.45}' # Encode with base64 algorithm encoded = base64.b64encode(account_str.encode()) print('base64 encoded string:', encoded.decode()) # Decode string from base64 algorithm decoded = base64.b64decode(encoded) print('base64 decoded string:', decoded.decode()) # Parse JSON account = json.loads(decoded.decode()) # Bank account information quotation = {'BRL': {'USD': 4.08}} print('') print('ACCOUNT INFORMATION:') print(30*'-') print('Name: ' + account["name"]) print('Bank: ' + account["bank"]["name"] + ', branch: ' + account["bank"]["branch"]) print('Account number: ' + account["number"]) print('Balance: USD {0:.2f} (BRL {1:.2f})'.format(account["balance"], (account["balance"] * quotation['BRL']['USD']))) print('')

Output:
ACCOUNT INFORMATION: ------------------------------ Name: AJ Bank: Itaú, branch: 555 Account number: 123-4 Balance: USD 123.45 (BRL 503.68)

Python / Call class method by name

class Test: def do(self): print("Test.do()") name = 'status' methodName = 'set' + name.capitalize() print('Method name: ' + methodName) method = getattr(self, 'setStatus') if method is None: print("Method is not valid.") return method(5) method("abcde") def setStatus(self, value): print("Test.setStatus() value=" + str(value)) test = Test() test.do()

Output:
Test.do() Method name: setStatus Test.setStatus() value=5 Test.setStatus() value=abcde

Tuesday, July 17, 2018

Search / replace in VIM with incremental replacement

Search for #1# and replace with incremental number:
let @a=1 | %s/#1#/\=''.(@a+setreg('a',@a+1))/g

Sunday, March 05, 2017

wxWidgets / MinGW / MSys

wxWidgets built in MinGW/MSys 32-bit:

../wxWidgets/configure --prefix=<OUTPUT_DIR> --build=x86-winnt-mingw32 --disable-shared --disable-threads --enable-cxx11 make make install

Tuesday, June 07, 2016

Lua basics 01

Calculate factorial of a number.
-- Calculate factorial function factorial(number) if number == 0 then return 1 else return number * factorial(number - 1) end end -- Main function function main() io.write("Enter the number to get the its factorial value: ") userInput = io.read("*number") if userInput == nil then print("User input is invalid.") os.exit() end number = factorial(userInput) io.write("factorial of ", userInput, ": ", number, "\n") end main()

Saturday, September 19, 2015

wxWidgets - Build - Windows - Msys

../wxWidgets/configure --prefix=<WXWIDGETS_SRC_DIR>/dist \ --enable-static --disable-shared --with-libpng --with-libjpeg --without-libtiff \ --with-libxm --with-libiconv --with-regex=builtin --disable-stc --enable-htmlhelp \ --enable-aui --enable-grid --enable-timer --enable-dynlib --enable-dynamicloader \ --enable-debug --enable-debug_gdb --with-expat=builtin
make
make install

Sunday, March 01, 2015

Financer - Monetary amount internationalization

Amount formats:

9,999.00 - United States
9.999,00 - Brazil

There are 2 categories of amount:

- Generic number value
- Monetary value.

Tuesday, February 17, 2015

Financer - Date and time internationalization

Need to implement a way to work with date and time in a way internationalized way.

There are two modes, input and output.
The output mode is to show date on user interface and the output mode to store in the database.

The output mode to store in the database is based on ISO 8601: YYYY-MM-DD

For the input mode there are predefined supported formats based by region/country:
  • MM/DD/YYYY: Used on United States.
  • DD/MM/YYYY: Used on Brazil.

Other formats for output will be added.

Saturday, February 14, 2015

Financer dependencies on Fedora 21 64-bit

Listing executable dependencies:
[allann@mars gui]$ rpm -q --whatprovides $(ldd build/linux/bin/financer | \ sed 's/.*=>//g' | sed 's/ *(.*//g') | sed 's/-[0-9]\+.*//g' | sort | uniq atk at-spi2-atk at-spi2-core bzip2-libs cairo cairo-gobject cyrus-sasl-lib dbus-libs enchant expat fontconfig freetype gdk-pixbuf2 glib2 glibc graphite2 gstreamer1 gstreamer1-plugins-base gtk3 harfbuzz harfbuzz-icu jbigkit-libs keyutils-libs krb5-libs libcom_err libdrm libffi libgcc libgcrypt libgpg-error libICE libicu libjpeg-turbo libnotify libpng libsecret libselinux libSM libsoup libstdc++ libtiff libuuid libwayland-client libwayland-cursor libwayland-server libwebp libX11 libXau libxcb libXcomposite libXcursor libXdamage libXext libXfixes libXi libXinerama libxkbcommon libxml2 libXrandr libXrender libxshmfence libxslt libXt libXxf86vm mesa-libEGL mesa-libgbm mesa-libGL mesa-libglapi nspr nss nss-softokn-freebl nss-util openldap openssl-libs orc pango pcre pixman postgresql-libs sqlite webkitgtk3 xz-libs zlib
So install Financer dependencies with the command:
# sudo yum install atk at-spi2-atk at-spi2-core bzip2-libs cairo \ cairo-gobject cyrus-sasl-lib dbus-libs enchant expat fontconfig \ freetype gdk-pixbuf2 glib2 glibc graphite2 gstreamer1 gstreamer1-plugins-base \ gtk3 harfbuzz harfbuzz-icu jbigkit-libs keyutils-libs krb5-libs libcom_err \ libdrm libffi libgcc libgcrypt libgpg-error libICE libicu libjpeg-turbo \ libnotify libpng libsecret libselinux libSM libsoup libstdc++ libtiff \ libuuid libwayland-client libwayland-cursor libwayland-server libwebp \ libX11 libXau libxcb libXcomposite libXcursor libXdamage libXext libXfixes \ libXi libXinerama libxkbcommon libxml2 libXrandr libXrender libxshmfence \ libxslt libXt libXxf86vm mesa-libEGL mesa-libgbm mesa-libGL mesa-libglapi \ nspr nss nss-softokn-freebl nss-util openldap openssl-libs orc pango pcre \ pixman postgresql-libs sqlite webkitgtk3 xz-libs zlib