Posts by JJoao • 5,113 points
222 posts
-
0
votes2
answers376
views -
3
votes1
answer244
viewsA: Four different conditions using awk if (Unix)
awk 'BEGIN{split("NN,AA,AB,BB",a,",")} {print $0,a[$2+2]}' input.txt Explanation: At first, split("NN,AA,AB,BB",a,",") defines an array "a" with a[1]=NN, a[2]=AA, a[3]=AB, etc. Note that the indices…
-
0
votes6
answers3344
viewsA: How is an agile way to add and remove code comments in VIM?
reply with 1 year delay... For multi-line comments to there C (/* comment */) (I) Delete the content of a comment: look for the start of comment: /\/\* remove: d% look for next occurrence of start…
-
0
votes1
answer129
viewsA: Redirect output to variable with whitespace
Try something like foo > "${path/\~/$HOME}.abc" In which apspas protect the spaces ${var/pat/sub} replaces the "pat" pattern with the "sub" value in $var…
-
2
votes2
answers941
viewsA: Script or command to sum all directories and show full size
du -hcs $(sed 's!^!/home/!' lista.txt)
-
2
votes2
answers315
viewsA: Shell script with no return function
The function is very confusing: you have the command at the same time ping of the system and the function ping. To properly experience the working of the script changes the function name only then…
-
0
votes3
answers182
viewsA: Is there any way to put Input automatically?
The possibility of redirecting input is a matter of survival for development, testing. Even for the organization of computer tournaments... Taking the case referred "average of two hundred numbers"…
-
2
votes2
answers116
viewsA: Leds and Arduino board
Partial Solution: This question is actually two: how to call and how to program. (Of course it is relevant to know how many doors...) I’ll just talk about the call. The leds only light up if the…
-
-3
votes4
answers5886
viewsA: Language exercise C
A pornographic solution (not to show to anyone): #include <stdio.h> int main(int argc, char**allwaysnull) { int c; if( argc == 8 ){ return 0; } if( argc == 1 ){ printf("6 numeros…
-
1
votes2
answers195
viewsA: Compile Linux-ready Assembly on OSX
I’m not sure what I’m saying!!! but here goes anyway: Intel 80-86 architecture and descendants is a mess! (unlike linux) in OSX the address space exceeds 2 32 so it usually does not support 32-bit…
-
0
votes2
answers573
viewsA: Script to remove GOOD signature from UTF-8 files
#!/usr/bin/perl -pi s/^(\xEF\xBB\xBF)//; ## remove BOM ! This version changes the files themselves. Example of use: rmbom *.js or perl rmbom file1 file2 *.js dir/*…
-
1
votes5
answers2046
viewsA: Compressing PDF files
The PDF format itself already has (by default) a compression block. For extra compression, for example Smallpdf goes to all embedded raster images and replaces them with images with lower resolution…
-
0
votes2
answers3708
viewsA: How to prevent Item started on one page from continuing on another in Latex?
Latex can usually hit this on his own... In this case try: \item \begin{samepage} Um barco de alimentação ou uma balsa auxiliar fornece os tubos (em geral, 12m); \end{samepage} \item ... a hug JJ…
-
0
votes2
answers5841
viewsA: Style quote: "(Author, Date)" to "Author (Date)"
I would suggest: \usepackage{natbib} (several options: sectionbib, square, etc). When quoting uses: \citep{jon90} for a parenthetical citation (Jones et al., 1990), \citet{jon90} for a textual one,…
-
5
votes3
answers1812
viewsA: Questions about Latex
A little answer opinioned: On linux, install a full Latex, texworks, pandoc. Anything goes to start Latex. But after the first few experiments, what we want is: concentrate (only) on the content. do…
-
1
votes2
answers5100
viewsA: How to search in txt file?
To find element number 11 uses awk!: awk '$1==11{print $3}' ficheiro.txt if you really have to use C #include <stdio.h> int main(){ char s[100]; int n; scanf("%d",&n); sprintf(s,"awk…
-
3
votes3
answers300
viewsA: Recover groups of a regular expression in Perl
The previous answers already say everything... One thing I like about Perl is that regular expressions match well with control structures: catches and control structures Capture groups produce lists…
-
0
votes3
answers2209
viewsA: map in C works?
Some maps solve perfectly with an array! Regarding your example, #include <stdio.h> int main(){ char * m[20]; m[1] = "Um"; m[2] = "Dois"; m[4] = "quatro"; printf("%s\n", m[4]); } works…
-
3
votes2
answers2562
viewsA: How to implement the hidden layer in a character recognition neural network?
In the continuation of the anerior response... (minimalist version) Character recognition: given a raster image of the character "guess" which character. Entrances: an input for each pixel of the…
-
2
votes1
answer622
viewsA: Folder monitoring on Linux
As qmechanik very wisely suggested, the inotify-utils are an excellent starting point for this situation. Allow programs to be enabled when the file/ directory changes. Below are two program…
-
3
votes2
answers402
viewsA: Wrong formatting when opening a latex generated PDF
Solution 1: Evade the problem :) Edit Latex and merge: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} %% <<<<<< esta linha \begin{document} ... The…
-
3
votes5
answers294
viewsA: Problem with calculator program
Sorry to answer again but now in a way more according to what the OP intention. case 43 --> case '+' makes things more readable scanf returns a value (number of elements read) -- can be used for…
-
1
votes5
answers294
viewsA: Problem with calculator program
One of the easiest ways to write C is to generate it. In this case with flex. The typical structure of a program flexis: %% regExp {ação C} ... %% In our case the file calc.fl is: F […
-
2
votes1
answer864
viewsA: Import Latex to R Markdown
I assume you’re using pandoc doc.rmd -o doc.pdf or similar. The file Rmarkdown need a block of Metadata (I suggest that placed at the beginning of the document, and in this case I will use YAML)…
-
1
votes1
answer96
viewsA: Limit characters in Tesseract Portable
I’ve only been using the tesseract on Linux, via command line, or in scripts that send the command line do the job... 1) create a configuration file mydata with the valid characters:…
-
1
votes3
answers586
viewsA: Find files containing string and rename
The @Clayton Stanley solution can be composed with the find of the OP for situations where the files are in subdirectories: find -type f -name "*xxxx.example.com*" \ -exec rename…
-
1
votes3
answers5312
viewsA: How to add line break using sed?
Using Gnu-sed (present in linux and easy to install everywhere, and to times with the name gsed) the example proposed by OP works with slight modification: sed echo 'foo bar' | sed 's/.*oo/&\n/'…
-
1
votes3
answers211
viewsA: Program using malloc twice
This exercise they put you in is interesting: understanding other people’s code and eventually modify it. The enunciation code has the virtue of: introducing several concepts (memory types, mallocs,…
-
0
votes3
answers1826
viewsA: How to calculate PI with "n" decimal places in Javascript?
Pi One-Iner Below some one-Liner using various languages... (almost all stolen! from various sources) bash+bc (bc=Unix calculator)(tang(π/4)=1 therefore 4 x arcotang(1)= 4 x π/4= π) bc -l…
-
0
votes2
answers935
viewsA: How to forecast future values of a time series?
I’m not the right person to give this answer... Yet here comes a simplicist starter: associated with a forecast of future values there is usually the choice of a "model" of the expected data…
-
5
votes2
answers180
viewsA: Bash, know what board you’re running on
I don’t know if this answers the question but: #!/bin/bash echo "A script está em: $0" echo "O invocador está em $PWD" Update 1 print the absolute path of the script To get the absolute path, we…
-
3
votes2
answers87
viewsA: Problem with vector ordering
instead of for(i=0; j<10; i++) I thought you wanted to say for(i=0; i<10; i++)
-
3
votes4
answers3093
viewsA: Function to check if number is prime in Javascript
Okay okay okay, it’s almost the same thing: in bash, and cheating! $ eprimo () { curl -s http://primes.utm.edu/lists/small/100000.txt | grep -q -w $1 && echo "Sim" || echo "Não"; } $ eprimo…
-
0
votes4
answers361
viewsA: Decrease span field value with preg_replace
And by the way a clandestine and pornographic response (Perl :) with regular expressions: perl -pe 's/<span.*?priceText.*?>\K(.+?)(?=<)/$1*0.8/e' span.xml With xml parser: #!/usr/bin/perl…
-
2
votes2
answers155
viewsA: Undefined Ference to MIN
Oops, ignore this answer: had not noticed but the previous solution already had a variant almost equal to this... And by the way, a messy, un-generic solution,: #define MIN2(x1,x2) (x1 < x2 ? x1…
-
0
votes2
answers1648
viewsA: Bubble Sort matrix, bi dimensional vector
It seems to me that there is some confusion of integers and pointers. In function appears: (apontador > apontador ) // possivel mas não me parece que queiras isso int = apontador // raramente é o…
-
4
votes2
answers1045
viewsA: Calculation to determine whether triangle is rectangle gives no expected result
Variant of the previous version (@Maniero) #include <stdio.h> #include <math.h> #define ERROMAX 0.0001 int main (void) { float hip, cat1, cat2; scanf("%f", &cat1); scanf("%f",…
-
5
votes5
answers8000
viewsA: What is the difference between pointer and reference?
Moderator’s note: this reply was published as a joke of April 1. Usually this type of content is not accepted on the site, but on this specific date an exception is made. After the date, the…
-
6
votes2
answers110
viewsA: Why does the order of these scanf’s make a difference in the outcome?
scanf("%d",...) will read and put an integer value (example 4 bytes) at the address you are given. Since the variable you’re reading to has only one byte (char), the poor neighbor variable gets run…
-
0
votes2
answers89
views -
-1
votes4
answers10317
viewsA: How to delete files inside a folder
What is a php folder? If we’re on Unix, I suggest: rm -rf nome_da_pasta/* Very careful with folder removal experiments recursively! (This applies to all responses, of course).…
-
2
votes1
answer161
viewsA: HTML table in SVG
tries to include the code in the tag foreinObject <foreignobject x="10" y="10" width="800" height="500" > <table border=1><tr> <td> Olá mundo </td> <td> <svg…
-
1
votes1
answer152
viewsA: Convert PDF document pages to Jpgs
The script is fine and if it fulfills the function, more than fine. Still, if you’re gonna move it, one possible direction is to put the pdftoppm to convert and make scale directly, or something…
-
1
votes2
answers1296
viewsA: How to get operating system time in nanoseconds or milliseconds using Qt Creator?
Just an add-on (actually this is a formatted comment): the function clock_gettime() has great precision. Although in the present case it is probably not necessary even microseconds (the last…
-
4
votes2
answers299
viewsA: C operator precedence table
Just to point out that the operator _ , _ is one of the few operators in C which guarantees an order for the execution of its arguments. Only the following operators are guaranteed order of…
-
3
votes5
answers4008
viewsA: Regex take from one point to the other within a text
Good people, I decided it was a shame I never did a show in c#. It goes from there (the moment is solemn!) I installed the mono and tried to see if the Perl idea was applicable. It is. I was so glad…
-
0
votes5
answers4008
viewsA: Regex take from one point to the other within a text
Okay, okay, not quite c# or . net but here’s a regular expression /(.+?\n)(?=From:|$)/s that I think is within the spirit of the statement. Example of use: perl -n0E 'for $mail (…
-
1
votes3
answers739
viewsA: Add space to each letter in UPPERCASE
echo preg_replace('/\B[A-Z]/', ' $0', "Olá oiEusouMuitoLegal! Tem Dias..."); //Olá oi Eusou Muito Legal! Tem Dias...
-
3
votes1
answer1748
viewsA: Convert text links to html link
To handle HTML editing, regular expressions are not the best Hithithite: is more suitable solutions based on html/xml parsers. However, maintaining the approach of the original question: $reply =…
-
1
votes1
answer98
viewsA: Query problems on Xpath
Almost: one is missing @ in the name; then the consultation, which is so: //select[name="Inicio"]/option/@value Should stay that way: //select[@name="Inicio"]/option/@value…