Posts by JJoao • 5,113 points
222 posts
-
0
votes2
answers400
viewsA: How to change the conjunction between the authors of the hepthesis model in Overleaf?
I’m not really sure, but see if this helps 1) In your example you are using \documentclass[bind,a4paper]{thesis} looked forward to hepthesis 2) For Bibtex see if \usepackage[...Lingua...]{babelbib}…
-
1
votes2
answers793
viewsA: Chatbot in Python with NLTK
(assuming it is worth linux/mac/Unix) Suggest creating a "chat.py" file, an "input.txt" file, and: $ cat chat.py ... o ficheiro da pergunta $ cat in.txt oi oi oi adeus $ python chat.py < in.txt…
-
0
votes1
answer146
viewsA: Flag at command line bash shell
A small example: #!/bin/bash case $1 in ## definir o pósprocessador -r) pp="shuf" ;; # -r shuffle -s) pp="sort" ;; # -s sort *) pp="cat -n" ;; # default numera linhas esac function proc(){ ls /bin…
-
1
votes2
answers343
viewsA: Adding strings from a regular expression
<?php $texto = " |5,00|7,00|| |10,00|2,00|| |3,00|30,00||"; // "texto" da pergunta $texto= str_replace(",",".",$texto); // locales (ver @ValdeirPsr) $b=preg_replace('/\|(.+?)\|(.+?)\|/e', '"$0" .…
-
-1
votes3
answers282
viewsA: strcpy function does not work on Linux
#include <stdio.h> #include <stdlib.h> void envia(char *pdados) { char comando[1000]; sprintf(comando, "curl -s '%s%s' > /dev/null", …
-
1
votes2
answers54
viewsA: How to run a bash file "mytest.sh" on a MAC without using ". /" alias and globally?
I see two orthogonal questions here: for easy use of a script, recommend installing the script in a PATH folder (example sudo cp script /usr/local/bin for general use; or cp script ~/bin for…
-
0
votes2
answers466
viewsA: Check empty directories and pick up command output
Or directly search for empty directories: find . -type d -empty
-
1
votes3
answers1309
viewsA: I want to change a string in 3 positions
def rot(s): return ''.join([chr(ord('A')+(ord(c)-ord('A')+3)%26) for c in s]) given a letter c,p=ord(c)-ord('A') , gives its position inside the letters. p {0.. 25}; (p+3)%26 sum 3 circularly within…
-
4
votes8
answers4394
viewsA: How to identify "Capicua" numbers that have 5 digits?
Already now a solution batuteira (I only know how to make of these ): generate them instead of recognizing them. The general idea is: a 5 digit chart has the following structure abcde in which: ab…
-
2
votes1
answer64
viewsA: Taking data from one Json and saving in another [Perl]
With Perl + JSON Module: #!/usr/bin/perl use JSON; my $j = '[ {"name":"AK-47 | Aquamarine Revenge (Battle-Scarred)", "price":1292, "have":10, "max":28}, {"name":"AK-47 | Aquamarine Revenge (Factory…
-
1
votes1
answer147
viewsA: Slow bash script
It seems unlikely that the delay is due to wget. (but this is not the issue) Probably the problem with the tested examples has to do with the lack of definition User-agent (the -U "Mozilla/5.0" of…
-
0
votes3
answers166
viewsA: Get String Snippet with Regular Expression
var t = .... ; var id = t.replace(/.*youtube.com\/.\/(.*?)%.*/, '$1'); console.log(id); EDIT: Ooops: Wrong Java... String id = t.replaceAll(".*youtube.com/./(.*?)%.*","$1")…
-
0
votes5
answers4863
viewsA: How to make a regex that ignores non-alphanumeric characters?
I’m not sure I understand the request, but var s="m.o...e,!d--a"; console.log(s.replace(/\W/g,"").match(/moeda/) ? "y":"n") (that is, remove the "no letter" first and then search for "coin") can be…
-
3
votes5
answers9375
viewsA: Program to find MMC in Python
By the way a lazy and inefficient version: calculate the common multiples in [a.. a*b] and select the first... [x for x in range(a,a*b+1) if x%b==0 and x%a==0][0]
-
1
votes3
answers6054
viewsA: Draw a rectangle using Python repeating structures
Be it a=height and w=width: print(w*"#" + "\n" ##### + (a-2)*("#" + (w-2)*" " + "#\n") # # + w*"#") #####…
-
0
votes3
answers8998
viewsA: How to call, in Python, a function whose name is stored in a variable?
import random def f1(x) : return x+11 def f2(x) : return x+22 def f3(x) : return x+33 def a(x): return globals()["f%d"% random.randint(1,3)](x) print(a(100),a(100),a(100)) Producing (for example) $…
-
1
votes3
answers300
viewsA: Code for reversing sequence of non-vowels ending with zero status
This nay is a direct answer to the question put, but only a solution of the problem posed. Follow a filter that using regular expressions searches only the critical zones and writes them inverted.…
-
2
votes4
answers4160
viewsA: Copy from txt file to other
If it is valid to use a command line (like the ones on linux, mac, even in windows) the concept of filter can be interesting. A filter accepts a textual input and returns an output also textual --…
-
0
votes2
answers74
views -
1
votes2
answers152
viewsA: How to cut a suffix from an expression in bash (egrep/sed/etc)
Usually in these situations it is useful to have prefix and suffix. By the way using a different approach: ls -d *.*/ | ## get directorias contendo "." sed -r 's!(.*)\.(.*)/!\1\n\2!' | ## separar…
-
0
votes6
answers2305
viewsA: Transform results combination function into a dynamic function
Opps, 3 years late! a functional version in Python but easily javascriptable: def p(comp,max,pref=[],min=1): if comp==0 : print(pref) else: for x in range(min, max-comp+2): p(comp-1, max, pref+[x],…
-
0
votes5
answers2310
viewsA: Why are other encodings used besides UTF-8?
In the question UTF8, Ansi, etc., it should not be forgotten that: at least we have to deal with the past, with legacy texts It’s probably all been said. Still, here’s some of my personal novel: (1)…
-
3
votes5
answers1273
viewsA: Why Nan Nan == 0?
NaN ^ NaN = 0 Because exactly that happens? By laziness, forgetfulness, bug, chance! NaN ^ NaN should give NaN The operation NaN ^ NaN does not make much sense -- bit-to-bit operations with…
javascriptanswered JJoao 5,113 -
11
votes3
answers235
viewsA: Why is it not possible to use comparison operators with Nan?
The NaN, +inf and -inf are attempts to model exceptions, errors, indeterminations and overflows connected arithmetic. The floating comma representations (eg double of C) have conventions to…
-
0
votes3
answers1468
viewsA: First and last character occurrence
We can remove: (a) from start until [ ^[^\[]*\[ (b) from ] until the end \][^\]]*$ ie replace(/(a)|(b)/,""): var n = '<HR>\n[{"key":"value","key2":["¥"]}]\n<HR>';…
-
0
votes5
answers2432
viewsA: Take the last position of a split()
Only one variant of the elegant solution @J.Guilherme(+1): var n = "Jose da Silva Sauro"; n = n.replace(/(.+) (\w+)$/, function(_,a,b){return b.toUpperCase()+ ", "+ a});…
javascriptanswered JJoao 5,113 -
0
votes4
answers29938
viewsA: Regular expression to accept only numbers and a ","
Just remember that HTML5 already includes some kind of field validation. Examples 1: Interiros enter 100 e 5000 <input type="number" name="n1" min="100" max="5000"> Example 2: numbers with…
javascriptanswered JJoao 5,113 -
2
votes8
answers955
viewsA: split/regex only on the first vertical bar "|"
texto = "João|||23anos|"; console.log(texto.split(/\|(.*)/,2));…
-
1
votes3
answers2681
viewsA: Adding text files to python
I don’t like to ask for file names interactively, or for them to become fixed; I prefer to create scripts that receive parameters via the command line. In this sense I recommend the fileinput…
python-3.xanswered JJoao 5,113 -
0
votes2
answers323
viewsA: Python accumulator list
According to the statement, I expected a different result: the list of partial accumulated sums. I suggested a recursive definition: def fctn(f,l,n): if not l: return [n] else: return…
-
1
votes2
answers1461
viewsA: Read a txt file and place each character in a position of an array in C
Another variant, taking advantage of the string format of fscanf: #include <stdio.h> int main(){ char texto[1000]; FILE *file; if((file = fopen("texto.txt", "r")) == NULL){…
-
1
votes1
answer319
viewsA: What is the purpose of the C++ qsort function compare function?
qsort in C and C++, intended to handle generic-type arrays. For that you need: handle generic types -- to handle the address of value involved (hence the use of "generic pointers" conventionally…
-
0
votes1
answer135
viewsA: Creating a file from a list and several different files
Suppose you have a recent awk (GNU-awk example of linux systems) awk ' { a[$1 " " $2][FILENAME]=$3} END { printf("0: Animais %s, %s\n", ARGV[2], ARGV[3]); for (x in a ){ printf("%s %d,%d\n", x,…
-
0
votes3
answers378
views -
2
votes2
answers534
viewsA: How to run a loop until the lines of a given.txt file end
I don’t like to interactively ask for filenames; I prefer the creation of scripts that receive parameters via line command. In that sense recommend the module fileinput: #!/usr/bin/python # -*-…
-
2
votes2
answers192
viewsA: Generating a file that is output from a command only if a condition is met
It’s not completely clear what you want... We obviously can’t analyze the memory used in the past. Let’s start by storing memory usage (with top) from now until two hours from now. I would suggest…
-
1
votes1
answer85
viewsA: Delete words from a file
Using Perl (sorry...) but easy to translate to awk $ cat stoplist.txt de a o .... $ cat ex.cvs meu caro amigo;jjoao;classe a eu ando a aprender weka;Thyago;classe b mas a sua sintaxe dá-me algumas…
-
3
votes4
answers392
viewsA: Program that returns the unusual numbers of two lists (python)
By the way a rather primitive solution using sets: 1) not common(a,b)= a b - a b list((set(a) | set(b)) - (set(a) & set(b))) 2) not common(a,b)= a-b b-a list(set(a)-set(b) | set(b)-set(a))…
-
1
votes2
answers351
viewsA: Use of Uniq
By the way, if it’s important to keep the order of the original file, can: awk -F';' '++n[$5] == 1' nome -F ';' -- sets the Fieldseparator (field separator) n[$5] -- counts the number of occurrences…
-
1
votes2
answers214
viewsA: How to get the result of the gdialog menu selection in the Shell Script variable?
Short answer: gdialog sends output to and STDERR; so you need to redirect STDERR to STOUT or join 2>&1 to the invocations of gdialog: escolha=$(gdialog .......... 2>&1) Eventually the…
-
0
votes2
answers81
views -
1
votes3
answers537
viewsA: How to remove the space of "4 980 Raphael" only between numbers
It gives me the idea that the previous answers are only removing the first space (wherever you are) ie sed 's/ //' I propose: echo "... 4 434 Rafael" | sed -r 's/([0-9]) ([0-9])/\1\2/' i.e.: replace…
-
3
votes2
answers1499
viewsA: Remove all line breaks from just one column of a csv file on Linux
With a file this size, it’s clearly recommended to use a parser/CSV modules. However assuming that the "" are correct and that there is no \"Inside the quotes we can try to use black magic... 1 awk…
-
1
votes4
answers1354
viewsA: XML returned by web service with encoding error
There are a couple of typical mistakes that lead to these kinds of situations. In this case there was a conversion to utf8 of a latin1 but indicating that it was something else (in this case…
-
2
votes3
answers175
viewsA: Exclusion via regex
In sublime: select Exp.regulates and: find= (DT_HR_ALTERACAO="\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\.\d{2,3} replace= \1 At the command line: perl -i.bak -pe 's/...find anterior.../$1/g' ex.xml…
-
3
votes7
answers185
viewsA: Capture year outside the regex
Mark with the prefix "####" the odd years, and then edit for manual correction: perl -i.bak -pe 's/(?<=EMISSAO=")(\d{4,})/$1 < 2018 ? $1 : "###$1"/ge' ex.xml sublime ex.xml…
-
1
votes2
answers537
viewsA: Replace files with sed
The solution proposed by @Iguita is perfect (solves the problem at once). Yet answering directly to your sub-question : insert file in column 2 of a csv file, you can use the command Paste: paste…
-
2
votes2
answers259
viewsA: Problems with bash - echo with char ! (exclamation)
The @Douglas already said everything, but by the way only one more explanatory comment of such strange behavior: in bash !... corresponds to the notation for the history. !123 is used to expand to…
-
3
votes2
answers812
viewsA: What is the dollar sign for before a variable?
In Unix in general there is possibility to choose the "shell" that is intended to be used. Example: bash Dash zsh sh ksh csh ... Each has its syntactic and semantic definition. In several Linux and…
shell-scriptanswered JJoao 5,113 -
-2
votes4
answers1173
viewsA: What does the regular expression "/(?=(?:...)*$)/" do in detail?
Already now a variant of the same idea, using the same philosophy -- this time a simple substitute in Perl (to emphasize that this question is orthogonal to the programming language) $ echo "1000 e…