Posts by Lacobus • 13,510 points
596 posts
-
1
votes1
answer3879
viewsA: How do I determine a square matrix in python?
You can use the package NumPy, who owns a wide collection of functions mathematics capable of working with multidimensional matrices. To compute the determinant of a matrix you can use the function…
-
1
votes1
answer76
viewsA: Result of a SELECT in Postgresql is not the same in Sqlite
The difference may be in how each of the databases is interpreting the strings containing dates in the format DD/MM/YYYY. The SQLite3 interprets strings containing dates in the format ISO8601, that…
-
1
votes2
answers766
viewsA: Iterate through multiple Xmls files with Python
First, you can implement a function capable of extracting the CNPJ from the sender from the file .XML containing the data of an Electronic Invoice. The example below makes use of the module…
-
1
votes2
answers396
viewsA: How to create a shell script that puts an echo at the beginning of each line in a file
You can use the utility awk to solve your problem with just one line, see only: $ awk '{ print "echo \"" $0 "\" >> log" }' script.sh > saida.txt…
-
1
votes1
answer302
viewsA: How to escape quotes from a json key in Postgresql?
There’s nothing wrong with your job! This data in format JSON that you’re trying to process is malformed, see well: '[{"nome":"João - "Carlos" - "}, {"nome":"Maria Silva"}]' Note that there is no…
-
4
votes2
answers59
viewsA: How to instantiate objects in shared memory?
Note that the static attribute of the parent class ParalelizationMode::barrier is being overwritten immediately after the call of shmat(): ... ParalelizationMode::barrier = (Barrier*) shmat(ptr_id,…
-
1
votes2
answers1544
viewsA: Script . sh to run a python script from within Cron
Since apparently Voce is in Linux, you could dispense with your .sh passing the responsibility to check if there is already another process running for your code Python, look at you: import fcntl,…
-
1
votes3
answers684
viewsA: Call database function that receives a list as parameter
Consultation within the function public.fnGetEmailUsuarios( ids int[] ) has an error in its clause WHERE. The operator IN() expects a list of scalar values and its function is passing to IN() an…
-
1
votes2
answers212
viewsA: Pointer to struct
The member vetor is part of the structure Firma! The compiler will return an error saying that vetor was not declared if you try something like: vetor[firma->qtdFuncionario]->nome /* ERRO! */…
-
-1
votes2
answers112
viewsA: Problem banknotes and coins
You can use a variable of type double to store a floating point value and read it with scanf() using the format specifier %lf, look at you: double valor; scanf("%lf",&valor); Finally, your last…
-
1
votes1
answer65
viewsA: Initialize members of a structure, accessed via pointer, in the constructor of a C++ class
If date is a private member of its class and its life cycle always accompanies the class instance DateTime, I don’t see the need to use dynamic allocation to boot it. Note that the struct tm has a…
-
0
votes1
answer169
viewsA: Numeric Counter
You don’t need all this paraphernalia to build your accountant! A simple solution would be to use the bitwise operator & to independently verify the 3 bits less significant of n, for example:…
-
1
votes1
answer1406
viewsA: How to see which tables are accessed in postgresql?
Internally, the PostgreSQL has a subsystem (known as Statistics Collector) responsible for monitoring all activities that are performed by the server. This monitoring information is made available…
postgresqlanswered Lacobus 13,510 -
0
votes2
answers3999
viewsA: How to define the SET CLIENT_ENCODING = UTF8 permanently?
You can set environment variables directly on ROLE responsible for the session/connection, for example: ALTER ROLE foobar SET CLIENT_ENCODING = 'UTF8';
-
4
votes2
answers140
viewsA: How to verify if a type is numerical in C++?
From the C++11 you can use the function std::is_arithmetic of the standard library type_traits to check whether an arbitrary type is an integer or a real number (floating point), see only: #include…
-
2
votes2
answers2513
viewsA: SQL - How to Get Last Day of the Previous Month Dynamically In This Situation
As in your case you need to compare dates in the format of Era UNIX, you need to get the last second of the previous month and not the last day as you mentioned in the question! To get the date of…
-
0
votes2
answers161
viewsA: Pointer for C functions is not calling
Your statements and definitions are correct. The problem is time to call the functions via the pointer. The following lines are having no effect on your code, see: calculo[0]; ... calculo[1]; ...…
-
1
votes3
answers83
viewsA: I need to do a function that passes an n * m matrix, is transformed into a unidimesional tam n *m vector
You don’t need any auxiliary pointer to convert the matrix, check this out: int * Vetor_Unidim( int ** matriz, int m, int n ) { int i, x, y; int * vetor = (int*) malloc( n * m * sizeof(int) ); for(…
-
2
votes3
answers1219
viewsA: What is wrong with the Python code?? Bhaskara
You are changing the quadratic coefficient a by the constant coefficient c in the denominator of the formula: You are also not checking whether the root is part of the set of real numbers by testing…
-
3
votes1
answer482
viewsA: Scroll through an array bash script
You don’t need to juggle with arrays, the syntax of case/esac allows you to test a list of values separated by |, look at you: #!/bin/bash read -p "Digite sua opção [S/N]: " RESP case ${RESP,,} in…
-
1
votes1
answer373
viewsA: How to calculate the difference between dates using the time. h library
Missed much code there for your progama to behave the way you described! Follows a code tested and commented able to solve your problem: #include <stdio.h> #include <time.h> #include…
-
3
votes1
answer43
viewsA: What is the lowest weight direct consultation or using views for a double relationship?
I don’t see the need to create any VIEW in your case. And, indeed, the creation of a VIEW not materialized could further degrade performance. For example, even if you specify the clause WHERE for a…
-
0
votes1
answer72
viewsA: Trigger and another field
You don’t need a TRIGGER replication for this. In your case, a TRIGGER it doesn’t seem to make any sense and it’s certainly just complicating the thing. If your application is doing the INSERT of…
-
0
votes3
answers45
viewsA: Error while printing values, the values that are printed have nothing to do with the values that were saved
Your code has several syntax errors, and does not even compile. Your class Clientes does not have a constructor in which class attributes altPC and largPC could be properly initialized, which would…
-
1
votes3
answers64
views -
2
votes2
answers131
viewsA: Error of logica shell script
The following comparison is unnecessary and will never be true: elif [ "$HORA" -ge 12 -a "$HORA" -lt 06 ] then echo "Boa Noite!"; else Look at the solution: #!/bin/bash HORA=$(date +%H) if [ "$HORA"…
-
2
votes2
answers254
viewsA: Intensive python course by Eric Matthes ex8.10
You can use a compreensão de lista to concatenate the string O grande in front of each element/string of the magic list, see only: lista=['Howard Thurston', 'David Copperfield', "Lance Burton",…
-
1
votes1
answer530
viewsA: How to split Files in c++
Your file division is correct, but some details should be noted: Your class Celular does not have none constructor. In the main code, you try to instill the class Celular by means of a builder that…
-
1
votes2
answers828
viewsA: Doubt when creating table with dates in postgresql
You can solve your problem by using a Window Function calling for lead() combined with a UNION ALL. Assuming your tables are something like: CREATE TABLE tb_tabela1 ( id BIGSERIAL PRIMARY KEY, data…
-
0
votes2
answers32
viewsA: Copy a square matrix of tam n into another complemetar n-1, omitted row 0 and column 0 of matrix n
Basically, the copy/conversion code between the matrices would look something like this: for( i = 0; i < N - 1; i++ ) for( j = 0; j < N - 1; j++ ) comp[i][j] = mat[i+1][j+1]; Follow your…
-
-2
votes3
answers2181
viewsA: Python functions-Global and local variables
In Python, variables declared within functions are treated as attributes within objects, and these attributes can be accessed from the global scope using the name of the object/function that…
-
5
votes3
answers3476
viewsA: Grep with multiple parameters
You can use regular expression [\|], look at you: grep: $ diff -y ontem.csv hoje.csv | grep '[\|]' egrep: $ diff -y ontem.csv hoje.csv | egrep '[\|]' awk: $ diff -y ontem.csv hoje.csv | awk…
-
6
votes1
answer4911
viewsA: Eoferror type exception treatment
Attention on the indentation of your code, the block try/except should be one level below the block while, look at you: while True: try: x = input().split() l.append(x) except EOFError: break To…
-
0
votes2
answers92
viewsA: Does Python Command Exist Similar to (Catch and Throw) Ruby?
In Python there are reserved words try, raise and except which are used exclusively for the treatment of exceções. In the case exemplified in your question, there is no need for an exception control…
-
4
votes1
answer1763
viewsA: Calculate SQL mean with time field
Assuming you have something like: CREATE TABLE tb_evento ( id INTEGER PRIMARY KEY, dt_inicial DATETIME, dt_final DATETIME ); INSERT INTO tb_evento (id, dt_inicial, dt_final) VALUES (1, '2016-05-01…
-
1
votes2
answers475
viewsA: Auto increment (Postgresql)
There’s no problem in that! A chave primária does not need to be sequential and not even begin at a specific value to serve its purpose. A chave primária need only be a identificador único No matter…
postgresqlanswered Lacobus 13,510 -
3
votes1
answer72
viewsA: How do I create a CSV in C by incrementing the first number?
Instead of changing the input file, you can simply convert it by writing an output file with the new content, see only: #include <stdio.h> #include <stdlib.h> #define LINHA_MAX_LEN (256)…
-
1
votes1
answer43
viewsA: Enumeration and print error
You can use a dictionary to solve your problem. To calculate all combinations in which the sum of the tens is between 280 and 520: from itertools import combinations lis =…
-
1
votes2
answers1633
viewsA: Doubt in a simple c++ ENCRYPTION program
This "encryption" algorithm presented is Cifra de César, and is one of the simplest and most well-known encryption techniques in existence. It is a type of substitution cipher in which each letter…
-
3
votes2
answers65
viewsA: Convert milliseconds to 16-digit hexadecimal
According to the documentation, dechex() supports only integers with values up to 4294967295. In this case, you need to write a function capable of converting large integers to hexadecimal, see…
-
0
votes1
answer532
viewsA: How do I return the number of items in a stack
You do not need a recursive function to count the amount of elements in the stack. You can use a loop for to iterate on the stack, from its top, as long as there are as many elements, see only: int…
-
1
votes1
answer234
viewsA: Convert VARCHAR to TIMESTAMP (AWS REDSHIFT/POSTGRESQL)
The conversion function TO_TIMESTAMP() returns the type TIMESTAMP. You need to use a CAST for the guy TIME in order to convert the data, see only: TO_TIMESTAMP( hora, 'HH24:MI:SS' )::TIME In your…
-
1
votes2
answers47
viewsA: Insert filesystem image name in mysql
Assuming your image files are contained in a single directory: $ ls -al ./folder_img/*.png -rw-rw-r-- 1 lacobus lacobus 349237 Jul 4 18:03 ./folder_img/alpha.png -rw-rw-r-- 1 lacobus lacobus 312568…
-
5
votes1
answer690
viewsA: Postgresql autoincrement skips 1 value when Insert is done by a function
This is completely normal. When you create a field in a table of type SERIAL or BIGSERIAL, one SEQUENCE is created implicitly to make the auto-increment control of this field. Fields of the type…
-
5
votes2
answers223
viewsA: In SQL queries should I follow the order of the index?
No, the order in which you construct the expression of your WHERE does not influence performance (or should not). Whichever RDBMS who is able to analyze the plan of the query that is running in…
-
3
votes1
answer294
viewsA: Bubble Sort in Python3
How about using a flag to determine whether the list has been ordered in full: def bubble_sort( lst ): ok = False while not ok: ok = True for i in range(len(lst)-1): if lst[i] > lst[i + 1]:…
-
0
votes1
answer615
views -
0
votes1
answer26
viewsA: Where is the macro LITTLE_ENDIAN_HOST and how does it behave?
LITTLE_ENDIAN_HOST certainly is inherent to some specific project and indicates if the program is being compiled on an architecture little-endian, and is not part of the standard C. It’s a very…
-
4
votes2
answers1211
viewsA: Execute bash commands in C
You can write a Variadic Function capable of receiving a string de formatação as argument, enabling the manipulation of all primitive types in a standard way, see only: #include <stdlib.h>…
-
0
votes2
answers74
viewsA: Printing bug
The guy from CPF can be a string, or an array of chars sized 11 + 1. A CPF number is composed of 11 digits, your buffer needs to be at least 12 elements to be able to retain a CPF, where the last…