Posts

Showing posts from January, 2022

JS – Mastering Browser Console: Creating a Dynamic Login Form with Declarative Programming

Image
The browser console is typically utilized by most developers just for output information, using functions like console.log(), console.warn(), or console.error(). However, the browser console is interactive and can assist us in many situation if we know how to interact with that. Normally when we use some console environment to perform some programming, it is most likely to adopt the Declarative Programming paradigm, which we want to receive the result, the output of a certain function after every instruction, and it differs from the Imperative Programming, which we previously define a set of instructions which control the flow of the code execution. Basically from the browser console we can input and execute JS instructions in the same way we do when we programming in JS using .js files or add code inside <script> tags. However, the benefit of using the console is that we can interact with the JS objects in the exact point of interest, then, we can read or write over the obje...

Pymongo: Learn how to integrate mongoDB with Python - Complete CRUD operations for handling mongoDB data using python

Image
MongoDb is one of most popular NoSQL database utilized nowadays. It is so because it is very simple to install and top use, beyond there are several cloud services on cloud which provides a mongoDb instance to use. In the other hand, python is a programming language typically adopted for big data applications because of the simple way it handles with computer memory allowing programs to have large numbers on memory using simple and native data types. In this article it will be presented how to connect in a mongoDB serve using python, and how to perform all CRUD operations. First it is necessary to install the pymongo module, which can be easily installed with pip tool, using the following instruction: python -m pip install pymongo Once it is installed you my use the example code below, which imports the class MongoClient, and when instantiate a object of this class, parametrize with the connection string to create a link with mongo db server. Once it is done, you may access a s...

Java Script - handling multiple browser windows - onfocus

Image
  Very often when we are developing web applications there is a requirement to open additional Windows, typically named as popups or dialogbox. Many modern frontend libraries provides mechanisms to implement this kind of requirement using a combination of CSS and HTML components to create a graphical effect to provide a user experience similar to a new window. But actually the native JS programming contains mechanisms to open additional browser Windows, and to keep to keep the control of the opened Windows. This is the goal of this tutorial, to demonstrate how to open new windows and keep the track of these objects, aiming to implement a few typical requirements regarding the user interface. First, to open a new window, we basically have use the method window.open. This method will open a new window: however, modern web browsers typically opens this window as a new tab, so if you want to have that opened in a popup/dialog box effect you should use the additional method parame...

Dart/Flutter: exception handling

Image
The exceptions are triggered every time an error happens during the software execution. In case exceptions are not handled, the software will abort, and the program execution will ends. To make the software with capability to handle its errors and give to the users a proper feedback and possibility to correct some input or try again, the exceptions can be handled. To perform exception handling using Dart, which is the programming language adopted by Flutter technology, you may use the try / on statement was we have in the example below: int x = 12 ; int y = 0 ; int res ; print( "1) try / on statement" ); try {   res = x ~/ y ; // ~/ => truncating division operator, always returns a int value. } on IntegerDivisionByZeroException {   print( 'Exception:: Cannot divide by zero' ); } Another possibility is to have the same structure but with the addition of the catch keyword. It makes possible to have access to the exception object and to read data from t...

Dart: implementing Object Oriented Programming (OOP)

Image
The object oriented programming provides several benefits for system design. It makes the code easier to maintain, easier to extends, and also implements several well-know design patterns. Using the Dart programing language classes can be simple defined utilizing the class keyword, followed by the class name, and then delimitated the class body with the key brackets {}, like in the example below, presenting one class with two methods. class ProgrammingLanguage {   void compile (){     print( "Compiling..." );   }   void execute (){     print ( "Executing..." );   } } When we need to add new features to this class, it is possible to use the inherence concept, defining a new class that will receive all implementation this ProgrammingLanguage class already has done. And this inherence is done using the extends keywork, like in the example below, which the Dart class has the compile() and the execute() methos from its superclass...

JSON conversion: Built-in functions to convert a string in JSON format to a python object

Image
  Often web services, files or any other data exchange mechanism utilizes the JSON format as a standard to shared data between different processes. In this context, it is important to a programming language to provide functions to parse these JSON strings to a native object, enabling the data processing in a more feasible way then the string processing. For python programming language there is a module name json, which contains a method to load a JSON string, but it needs an additional parameter that is the “hook function”, a function to handle how each object will de translated to object. import json #https://docs.python.org/3/library/json.html from types import SimpleNamespace #https://docs.python.org/3/library/types.html print ( "### JSON to object example with multilevel objects ####" ) data = '{"name": "Ramza Beoulve", "details": {"firstName": "Ranza", "lastName": "Beoulve"}}' # Parse...

Map Reduce: Understanding the reduce function and its limitations. What happens with the processing of first element?

Image
When we have a dataset its often necessary to reduce this dataset to single values that correspond to indicators, for instance, normally related to statistics indicators. Some indicators examples are the average, the variance and the standard deviation. The goal of the reduce function is to assist us to calculate such indicators.   To use the reduce function we have to import that from functools module: from functools import reduce   Now to use the reduce function we need to understand its interface, it has two parameters: a)     a function which responsible for reducing. It needs to have two parameters – the first one a counter (variable shared among the processing of all iterated elements) and the second current element. The function needs to return the updated value of counter, which will be de input of the next iterating element. b)     a list of elements to be reduced. Here a example of how to use the reduce function, which will sum all el...