Posts by Lacobus • 13,510 points
596 posts
-
2
votes1
answer591
viewsA: Struct declaration and initialization outside the main function in C
If the problem is pollution, you could rewrite your main() another way, look at this: typedef enum { corVermelho, corAzul, corVerde, corAmarelo } TipoCor; typedef struct { int numero; TipoCor cor; }…
-
0
votes2
answers459
viewsA: Specific libraries and standards of C compilers on Windows and Linux
The library conio.h and the function strrev() library string.h are not part of the standard C. Avoid using them if your purpose is portability. An alternative implementation of strrev() might be…
-
2
votes2
answers671
viewsA: Select in Python (with BD: Postgres)
Check in which schema the table tb_log is contained! For example, if your table is contained in a schema called xpto, your consultation would look like this: SELECT id_log, nm_ip, dh_chamada,…
-
1
votes1
answer227
viewsA: Pandas: How to make a Serie fragment in the field (Column) of the Dataframe
Instead of using the Pandas, how about using the library xlrd to read the file .xlsx and the library csv to save the file CSV outgoing, check it out: import xlrd import csv # Abre arquivo XLSX de…
-
0
votes1
answer40
viewsA: How can I do that without needing this global variable?
It seems to me that shuffle(), give_cards() and handler_events() are methods of a class! n could be an attribute of your class, look at the class CardGame, based on the code of your question: class…
-
0
votes2
answers231
viewsA: read a txt file and list approved candidates
Assuming that your input file (dados.txt) be something like: 0816187-9;ZULEIDE MARIA NAZARIO VERAS;1,5;2,25;0,75;8 0123456-0;JESUS DE NAZARE;8,5;9,25;3,75;9,25 9876543-9;CHAPOLIN…
python-3.xanswered Lacobus 13,510 -
1
votes1
answer479
viewsA: Parking class in Python
Your parking control class can be something like: class Estacionamento: def __init__( self, max_vagas ): self.max_vagas = max_vagas self.vagas_ocupadas = 0 def maximo( self ): return self.max_vagas…
-
1
votes2
answers1295
viewsA: Create a frequency table based on another column in Python
This table you intend to calculate is called Histogram. Follows a code capable of calculating a Histogram from a file .CSV: import csv import string from collections import Counter palavras = []…
-
1
votes3
answers407
viewsA: Check if a string is composed of digits
You can use the function isdigit() of the standard library ctype.h. Look at that: #include <ctype.h> #include <stdio.h> int isDigit( const char * str ) { if(!str) return 0; /* Se string…
-
0
votes3
answers1839
viewsA: Web scraping python running javascript on the CEF website
You can use the website "http://www.loteriaseresultados.com.br/" to extract all information about all CEF lottery draws using the BeautifulSoup, look at you: import requests from bs4 import…
-
0
votes2
answers249
viewsA: Python script does not generate chart as expected
In your case, as the serve count is linear and sequential, you do not need to compile a list for the x-axis of the graph. A matplotlib is able to do this automatically, and your program could become…
-
0
votes3
answers1839
viewsA: Web scraping python running javascript on the CEF website
The URL "http://loterias.caixa.gov.br/wps/portal/loterias" still available in its content HTML the latest lottery results, and Oce can extract them as follows: import requests from bs4 import…
-
1
votes1
answer105
viewsA: Poorly formatted XML
Link XML is perfectly valid! But look at the tag <overview>, where there is a text in which a kind of quote appears ’ after the word Drake, see: <Overview>Uncharted: The Nathan Drake…
-
3
votes2
answers902
viewsA: Ignore the first line
You can use the utility tail to skip the first line of the input file before redirecting its output to sort, look at you: $ tail -n +2 arquivo.csv | sort -u -o arquivo.csv According to the utility…
-
2
votes1
answer207
viewsA: Add fields in a select
Have you ever tried something like: SELECT a.idautor, a.nomeAutor, o.idobra, o.titulo, ass.descricaoAssunto FROM autor AS a JOIN obra_autor AS oa ON ( a.idautor = oa.idautor ) JOIN obra AS o ON (…
-
0
votes1
answer303
viewsA: Writing in binary file
You are not paying attention to the file opening modes in the constructor call std::ofstream and in the reference position passed as parameter to the method std::ofstream::seekp(). Follows a…
-
2
votes1
answer165
viewsA: Is the <openssl/bn. h> library part of the ANSI C standard?
Standard libraries do not provide support for arithmetic operations with values of more than 64 bits. Operations with large integers can be done using a library from GNU calling for gmplib. Here is…
-
1
votes2
answers73
viewsA: Validate only 1 and 2 in an sql table in the relational and logical model?
You can use a foreign key for a domain table containing all valid and/or acceptable values. Imagine a hypothetical scenario where you want to control book lending. In this scenario, a Livro can only…
postgresqlanswered Lacobus 13,510 -
10
votes2
answers562
viewsA: Why assign NULL on a pointer after a free?
It is a good practice that helps avoid unexpected behavior and greatly facilitates the handling of errors. After the call from free(p) the pointer p no longer points to a valid memory address, which…
-
1
votes1
answer69
viewsA: Declare array in class not knowing it will be its size
You can build your class more or less like this: #include <iostream> class IntArray2D { public: IntArray2D( int ncols, int nlinhas ) { this->m_nlinhas = nlinhas; this->m_ncolunas =…
-
2
votes3
answers2371
viewsA: Download all columns of all tables containing a text
In Postgres this information may be obtained from information_schema, of a VIEW calling for columns. For example, consider the tables tb_foobar and tb_xpto: CREATE TABLE public.tb_foobar ( id…
-
3
votes1
answer1940
viewsA: Decimal to binary conversion
You can implement a function to make this conversion: long dec2bin( long dec ) { int resto; long bin = 0; int i = 1; while( dec != 0 ) { resto = dec % 2; dec /= 2; bin += resto * i; i *= 10; }…
-
1
votes2
answers74
viewsA: How to find the data type of a binary file
This can vary a lot. There is no pattern. Each image file has a layout different and this will depend a lot on each platform/ architecture, see only: SEGA/Genesis:…
-
3
votes2
answers1174
viewsA: Sum values of several lines under condition
The function of aggregation sum() should stay out of of CASE, look at you: SUM( CASE WHEN adm.adm_fl_tipo = 'D' THEN car.car_vl_cartao ELSE 0 END ) AS total This will cause the value zero (0) is…
-
2
votes1
answer7113
viewsA: Eliminate repeated elements of a vector in C
Follows an algorithm capable of removing duplicate value elements in a array whole: #include <stdlib.h> #include <stdio.h> int main( void ) { /* Vetor de entrada com elementos de valor…
-
1
votes2
answers1305
viewsA: How to turn a list into a set in Python?
It is not always possible to convert the contents of a list for a set due to the different nature of each of these types, see only: lst = [ 1, 2, 3, 4, 1, 2, 3, 4 ] s = set( lst ) print( s ) Exit:…
-
4
votes2
answers130
viewsA: Datetime without the year
You can use the function timedelta() standard public datetime to work with a time period instead of working with specific dates, see only: from datetime import date from datetime import timedelta…
-
0
votes2
answers391
viewsA: Bring the second and third line of a query
Assuming you have something like: CREATE TABLE tb_foobar ( id INTEGER PRIMARY KEY ); INSERT INTO tb_foobar( id ) VALUES ( 1 ); INSERT INTO tb_foobar( id ) VALUES ( 2 ); INSERT INTO tb_foobar( id )…
-
4
votes2
answers103
viewsA: How can I select a range of items, after some values using SQL IN operator
Assuming Voce has a table like: CREATE TABLE tb_foobar ( id INTEGER PRIMARY KEY, value INTEGER ); Containing the following data: INSERT INTO tb_foobar ( id, value ) VALUES ( 1, 1 ); INSERT INTO…
-
1
votes3
answers399
viewsA: How to select the last rows added in a mysql table
Assuming you have a table like: CREATE TABLE sir_ter_conversa ( id INTEGER PRIMARY KEY, idterreno INTEGER, idincorporadora INTEGER, idusuario INTEGER, msg TEXT, data DATE ); Containing the data:…
-
2
votes3
answers3331
viewsA: Return the amount of elements repeated in a list
You can do this natively by riding a set() with all repeating elements, and counting the amount of elements in this set using len(): lista = [ 4, 2, 1, 6, 1, 4, 4 ] qtd = len( set( [ item for item…
-
2
votes1
answer177
viewsA: Check if file has already been copied
To copy submissions in C++ with good error control, I suggest something like: #include <fstream> #include <iostream> #include <stdexcept> void copiar( const char * origem, const…
-
1
votes2
answers1533
viewsA: How to select data from a column as columns in SQL?
Assuming your structure and your data are something like: CREATE TABLE tb_foobar ( id INTEGER PRIMARY KEY, nome TEXT ); INSERT INTO tb_foobar ( id, nome ) VALUES ( 1, 'JESUS'); INSERT INTO tb_foobar…
-
1
votes2
answers1533
viewsA: How to select data from a column as columns in SQL?
In Postgres this information may be obtained from information_schema, of a VIEW calling for columns. For example, consider the table tb_foobar: CREATE TABLE public.tb_foobar ( id INTEGER, name TEXT,…
-
6
votes3
answers183
views -
0
votes2
answers217
views -
2
votes2
answers685
viewsA: Fix invalid command dynamically, no alias required
I don’t know if it’s possible to do exactly what you want, but you can use the command trap to capture the signal from DEBUG fired by each command you execute, let’s see: Configuring the trap: $…
-
0
votes2
answers45
viewsA: Use of cinnamon in macros
That point after the #include <stdio.h> will surely cause the compiler to return an error like this: teste.c:1:19: warning: extra tokens at end of #include directive [enabled by default]…
-
1
votes2
answers1061
viewsA: Remove element from a Vector in "C"
If you already "know" the size of the vectors, I don’t see the need to implement an algorithm using dynamic allocation. Follows a program (tested) capable of solving your problem using a specific…
-
2
votes1
answer502
viewsA: Create/manipulate file within a directory other than main.cpp
The error is time to open a file nonexistent for recording. The method call ofstream::open() creates a new file if it does not exist, but, does not create directories! You can include more elaborate…
-
3
votes2
answers3378
viewsA: How to print UTF-8 characters on the c++ console?
You’re probably referring to the Windows console, or cmd.exe. By default, the cmd.exe does not work with the encoding outgoing UTF-8, also known as the Code Page code 65001. To change it, just type…
-
1
votes2
answers855
viewsA: Distance calculation in C
You can use the Haversine’s formula to calculate the distance between two geographical coordinates: Follows a code in C (tested) able to calculate the distance in kilometers between two geographical…
-
1
votes1
answer55
viewsA: I’m having some problems with GROUP BY
Assuming your data structure is something like: CREATE TABLE tb_bico ( id BIGINT PRIMARY KEY, id_empresa BIGINT, id_bomba BIGINT ); CREATE TABLE tb_abastecimento ( id BIGINT PRIMARY KEY, id_bico…
-
1
votes2
answers1119
viewsA: How to compare part of strings in C?
You can use the function strcasestr() of the standard library string.h to check (not considering uppercase or lowercase letters) if a string is contained in another, for example: #define _GNU_SOURCE…
-
2
votes1
answer472
viewsA: Consultation to calculate the number of female and male students
Translate the table Aluno of its model to PL/PgSQL: CREATE TABLE Aluno ( idaluno BIGINT PRIMARY KEY, nome TEXT NOT NULL, cpf VARCHAR(11) NOT NULL, rg VARCHAR(14) NOT NULL, sexo VARCHAR(1) NOT NULL,…
-
0
votes2
answers96
viewsA: What’s wrong with this print line = ('Hello,' + full_name.title() + '!')?
print if it is a language statement, the error is happening because when you use the assignment operator (=) trying to attribute something to print, the interpreter understands that this is a syntax…
-
1
votes1
answer542
viewsA: How to popular a postgres table with JSON?
Assuming the data destination table is something like: CREATE TABLE tb_foobar ( id BIGINT primary key, name TEXT ); You can use the function json_populate_record() of Postgres to insert the data…
-
1
votes1
answer59
viewsA: See how many Products were sold in 2017
Translating your data model to PL/PgSQL: CREATE TABLE Cliente ( idcliente BIGINT NOT NULL PRIMARY KEY, nome VARCHAR(60) NOT NULL, salario NUMERIC(10,2) NOT NULL, dataNascimento DATE NOT NULL, sexo…
-
1
votes1
answer408
viewsA: Can you identify whether a Postgresql command can lock before it is executed?
1) You can use the environment variable statement_timeout, limiting the maximum execution time of transactions in the database. This ensures that no user will stay dangling performing operations in…
postgresqlanswered Lacobus 13,510 -
1
votes2
answers876
viewsA: Query SQL to select student and student name
Translating your model to MySQL: CREATE TABLE pessoa ( matricula BIGINT NOT NULL, senha VARCHAR(32), nome VARCHAR(255), email VARCHAR(255), logradouro VARCHAR(255), bairro BIGINT, cidade BIGINT, uf…