Posts by Lacobus • 13,510 points
596 posts
-
1
votes1
answer739
viewsA: Create Function to update column
Assuming the following structure: CREATE TABLE tb_suprimento ( cod INTEGER, capacidade INTEGER ); CREATE TABLE tb_estoque ( cod_suprimento INTEGER, capacidade_usada INTEGER, percentual_usado INTEGER…
-
0
votes3
answers6300
viewsA: How to add numerical values inside a C string?
How about: #include <stdio.h> int digsum( const char * s ) { int i = 0; int soma = 0; while( s[i] ) soma += ( s[i++] - '0' ); return soma; } int main( void ) { printf( "%d\n",…
-
1
votes3
answers121
viewsA: How can this be improved? (It’s just a little game)
Each group of numbers can be calculated dynamically by means of a function (obter_grupo()), which, in turn, can be called inside a loop, thus avoiding the unnecessary repetition of code and the…
-
0
votes1
answer180
viewsA: Problem with hashlib
Code: import hashlib def hash_sha512( text ): return hashlib.sha512( text.encode('utf-8') ).hexdigest() print hash_sha512( "teste" ) Exit:…
-
3
votes3
answers16313
viewsA: Comparison of char in C
How about using a function to check if the letter is a vowel: int eh_vogal( char c ) { int i = 0; static const char v[] = "aeiouAEIOU"; while( v[i] ) if( v[i++] == c ) return 1; return 0; } With…
-
0
votes2
answers102
viewsA: Create sets for 16-bit variable composed of two 8-bit
I suggest you use two macros different, one for reading and one for recording. Reading: #define PORTAB ((unsigned short)(((PORTA) << 8) | (PORTB))) Recording: #define PORTAB( value ) do{…
-
4
votes4
answers4160
viewsA: Copy from txt file to other
Here is a solution (tested) in language C capable of performing a buffered binary copy of two files: #include <stdlib.h> #include <stdio.h> #include <string.h> #include…
-
3
votes3
answers957
viewsA: Random numbers are always the same
The sequence of random numbers generated, in fact, will always be the same for the same seed, this is a fundamental feature of a PRNG. To obtain different sequences it is necessary that the seed…
-
1
votes1
answer698
viewsA: Manipulation of values in input files c . txt code
Here is an example (tested), with functions exemplifying how to calculate the average and the variance of a finite set of samples obtained from a text file: #include <stdio.h> #include…
-
0
votes3
answers290
viewsA: Doubt with Insert in Postgres Bank
Literal constants: INSERT INTO empresa ( id, nome ) VALUES ( 1, '{ testeA, testeB, testeC }'::text[] ); Expressions with ARRAY: INSERT INTO empresa ( id, nome ) VALUES ( 1, ARRAY[ 'testeA',…
-
1
votes2
answers387
viewsA: Save file data to a c++ map
In your case, using a blank space as a field delimiter is not a good idea. I suggest that your data use another type of delimiter, such as the semicolon (;): Arroz Integral;10.50;100 Arroz…
-
7
votes8
answers4052
viewsA: How to generate 200,000 primes as fast as possible in Python?
Code: p = [] def gerar_primos(): limite = 2750159 + 1 primos = [] nao_primo = set() for n in range( 2, limite ): if n in nao_primo: continue for f in range( n * 2, limite, n ): nao_primo.add( f )…
-
2
votes1
answer696
viewsA: Search records referencing the same table
You need a recursive query to solve your problem. Structure: CREATE TABLE tbl_historico ( id INTEGER, id_anterior INTEGER ); ALTER TABLE tbl_historico ADD PRIMARY KEY (id); ALTER TABLE tbl_historico…
postgresqlanswered Lacobus 13,510 -
1
votes1
answer82
viewsA: Reading only odd records
You can assume that it is the end of a record every time a blank line is found: #include <stdio.h> #include <string.h> #define NOME_ARQUIVO "Teste.txt" #define LINHA_MAX_TAM (100) int…
-
5
votes2
answers125
viewsA: Doubt regarding Count in SQL command
How about grouping using sum() with a conditional sum: SELECT sum( CASE WHEN usado = '0' THEN 1 ELSE 0 END ) quantidade, codigosuprimento FROM public.estoque GROUP BY codigosuprimento ORDER BY…
-
3
votes1
answer134
viewsA: Check which one is larger using a python formula
How about: a = int(input('a: ')); b = int(input('b: ')); c = int(input('c: ')); maior = max( a, b, c ); print(maior); repl it.…
-
0
votes2
answers130
viewsA: Why can’t all if have Isis?
The problem is not in the syntax of if/else and yes on the comparison operator <= you are using in place of the assignment operator :=, how about: if rising_edge(clk) then status := '1'; else…
-
0
votes2
answers112
viewsA: What is the logic behind this challenge?
The logic behind this challenge is a variation of Backpack problem and of Problem of Frobenius. Both problems can be solved with methods of Dynamic Programming.…
-
1
votes2
answers1174
viewsA: Data Comparison in Files [C]
Here is a possible solution to your problem: #include <stdlib.h> #include <stdio.h> #include <string.h> #define LINHA_MAX_TAM (100) #define NOME_MAX_TAM (50) typedef struct…
-
1
votes3
answers868
viewsA: Catch string inside <a> tag without attributes
Use the method evaluate() class DOMXPath: <?php $html = "<a href=\"link\"><font style=\"font-size: 14px;\" color=\"black\" face=\"arial\"><b>String que eu quero…
-
2
votes3
answers1585
viewsA: How to generate large random numbers in C++?
The function rand() is able to return whole numbers in the range between 0 and RAND_MAX. It is guaranteed by the standard that RAND_MAX never has a value less than 32.767, what makes it rand()…
-
3
votes1
answer148
viewsA: Insert character by character of the Russian alphabet into a char vector in C++
The call of setlocale( LC_ALL, "" ); (with the second blank parameter), causes the default locale of the program to be set according to the variables of its environment. If you are working with the…
-
1
votes1
answer137
viewsA: subconsulta with 3 different tables using ilike in postgres
How about using the UNION: SELECT 'M', id, descricao FROM metodo WHERE descricao ILIKE '%texto%' UNION SELECT 'F', id, descricao FROM forma WHERE descricao ILIKE '%texto%' UNION SELECT 'A', id,…
-
4
votes3
answers2285
viewsA: How to get the local ip in shell-script?
Remembering that the same machine may have several addresses of IP. The solutions proposed here apply to machines Linux and return only the address of IP primary: 1) Using hostname + cut: $ hostname…
-
1
votes1
answer2467
viewsA: How to count the total Characters of a txt file, including spaces and ' n'?
You do not need to load the contents of a file into memory to calculate its total size, this becomes impractical in cases where the file size exceeds the available memory size. Calculating the size…
-
2
votes1
answer1699
viewsA: How to calculate the time difference between certain hours?
In PHP, the method diff() class DateTime is able to calculate the difference between two dates: $agora = new DateTime(); $data = new DateTime('2020-01-25 12:21:33'); var_dump( $agora->diff($data)…
-
1
votes3
answers1525
viewsA: How to create an incremental Update sql command
How about using a field of the type BIGSERIAL: Table creation: CREATE TABLE Estoque ( produto TEXT, n_serie BIGINT, etiqueta BIGSERIAL ); Data entry: INSERT INTO Estoque ( produto, n_serie ) VALUES…
-
0
votes1
answer61
viewsA: Definition of Macros with Indexing in C
You can write your macro using ternary operators: #define EXEMPLO(idx) ((idx==1)?(a * c + b):((idx==2)?(a + b + c):((idx==3)?(b * c + a):0))) Follow an Example of how to use: #include…
-
0
votes2
answers720
viewsA: Recover struct data in C
Here is an illustrative (tested) example of how to read and write data from a "struct" into a binary file. #include <stdio.h> #include <stdlib.h> #include <string.h> #define…
-
1
votes1
answer90
viewsA: fprintf() C error when printing, value displayed(-1,#R) other than being allocated(0)
The following are two examples based on your racecinio line. 1) Reading/Saving in text mode: #include <stdio.h> #include <stdlib.h> typedef struct registro_s { double terreno; double…
-
1
votes2
answers4957
viewsA: How to search records from the previous month?
In the SQL Server 2008 you can do something like this: SELECT SUM(DIFERENÇA) AS Mesanterior FROM TOTALIZADOR WHERE NID = 252 AND DATAHORA BETWEEN DATEADD(s,-1,DATEADD(mm,DATEDIFF(m,0,GETDATE()),0))…
-
2
votes4
answers17451
viewsA: How to check Postgresql logs?
It is possible to have the server register on LOG all commands (DDL, DML, DCL and TCL) executed on the Databases that are hosted on it. In the settings file data/postgresql.conf from your Postgres…
-
1
votes1
answer424
viewsA: How to create a mapped file with an Std::map
Follow two routines illustrating how to serialize and deserialize a std::map from/to a text file. All standard C++11 and using the library boost: Recording (serialize.cpp): #include <string>…
-
6
votes2
answers4812
viewsA: How do I check if there is a special character or number in a string in C?
In practice, this "idiomatic": (!(nome[i] >= 'a' && nome[i] <= 'z')) Not usually used for standardization issues. This happens because not all languages in the world use latin alphabet…
-
1
votes1
answer2425
viewsA: Python -> how to merge multiple csv files
The new line hidden can be removed from a string through the method rstrip(). The header of input files can be ignored (skipped) by calling the method next(). Let’s see: from os import listdir from…
-
1
votes1
answer1463
viewsA: How to create Trigger postgre
Creating Structure of Tables: -- CLIENTE CREATE TABLE tb_cliente ( id BIGINT, nome TEXT ); -- MOVIMENTACAO CREATE TABLE tb_movimentacao ( id BIGINT, id_cliente BIGINT, tipo VARCHAR(1), valor REAL );…
-
0
votes1
answer114
viewsA: Performance difference between C and Matlab
In fact you don’t need a high resolution timer to solve your problem. The secret is to perform your test over and over and then calculate the average time. See only: #include <stdio.h>…
-
4
votes2
answers74
views -
1
votes3
answers68
viewsA: Shell: download and unpack in a row
How about: $ wget -O - https://ftp.gnu.org/gnu/binutils/binutils-2.7.tar.gz | tar xvzf -
-
1
votes1
answer216
viewsA: http connection to c++ and Curl or any other library
The error is occurring because the third argument (WriteCallback) past the call of curl_easy_setopt(CURLOPT_WRITEFUNCTION) is a class method and not a pointer to a function. One way to solve this…
-
1
votes2
answers1297
viewsA: Find the name and number of doctors who have appointments with all patients
Assuming your table structure is anything like this: CREATE TABLE paciente ( id_paciente INTEGER PRIMARY KEY, nome TEXT ); CREATE TABLE medico ( id_medico INTEGER PRIMARY KEY, nome text, cpf text );…
postgresqlanswered Lacobus 13,510 -
3
votes1
answer463
viewsA: Query using order by slowly
First a scenario similar to what you described was created: identical structure and a random data mass: -- -- MODELO DA TABELA app_event -- create table app_event ( ae_id serial primary key,…
postgresqlanswered Lacobus 13,510 -
2
votes2
answers7160
viewsA: Decimal to binary conversion in C language
DECIMAL FOR BINARY Algorithm: Implementation: #define swap( a, b ) do{ int tmp = a; a = b; b = tmp; }while(0) const char * dec2bin( char * bin, int d ) { int i = 0; int j = 0; for( i = 0; d > 0;…
-
1
votes2
answers61
viewsA: Make a SQL language design that returns the number of clients who have no business done
Assuming your model has a similar structure: CREATE TABLE cliente ( cod INTEGER, identidade INTEGER ); CREATE TABLE negocio ( cod INTEGER, identidade INTEGER ); With this data: INSERT INTO cliente(…
-
3
votes2
answers4463
viewsA: Sum in sql update
Solution to a scenario uncompetitive: UPDATE cadastro SET pontos = pontos + 1 WHERE id = 102; A very important consideration when doing this type of update is the competition of write accesses in…
-
3
votes2
answers151
viewsA: How to optimize images?
OptiPNG: $ optipng /tmp/saturno.png ** Processing: /tmp/saturno.png 1041x1041 pixels, 8 bits/pixel, 195 colors in palette Input IDAT size = 119947 bytes Input file size = 120793 bytes Trying: zc = 9…
-
1
votes3
answers205
viewsA: How to get mime from a file through Python?
Solution with the Python-Magic: import magic m = magic.Magic(mime=True) mime_type = m.from_file("arquivo.pdf") print mime_type Edit: According to the official library website Python-magic there are…
-
2
votes2
answers2441
viewsA: How do I round a float number from two decimal places to one if you only have one number? example: 2.10 to 2.1
The conversion specifier %g is able to display only the significant digits of a type float. For example: #include <stdio.h> int main( int argc, char * argv[] ) { float a = 1.1230000; float b =…
-
2
votes3
answers1242
viewsA: Point inside a polygon
This function checks whether a Ponto is contained within the area occupied by a Rectangle. Points P and R are the coordinates of two opposite vertices of this Rectangle: Assuming Ponto be something…
-
1
votes2
answers70
viewsA: Parse feed in Python
How about: import feedparser rssfeed = """ <horoscope> <date>20170627</date> <listItem> <item> <signTitle begin="21/03" end="19/04">Aries</signTitle>…