Posts by JuniorNunes • 4,886 points
146 posts
-
1
votes2
answers35
viewsA: How to Catch Variable Macros in a String
You can use the match to do this: var text = "HIGHLANDER esse aqui [TESTE] muito massa pra ver se [você recebe sms, [BAR] desconsidere ai, valeu! [FOO]"; var result = text.match(/\[\w+\]/g);…
javascriptanswered JuniorNunes 4,886 -
5
votes2
answers815
viewsA: How to take text inserted into an input and insert it into a label ?
You can do so to go modifying while you are writing: email.addEventListener('keyup', function() { document.querySelector('.label-email').innerHTML = this.value; }); <div class="index-login">…
-
0
votes2
answers158
viewsA: My shell script does not list all user processes
Use like this: ps -fu $(whoami) Read more about the ps here
-
1
votes1
answer522
viewsA: Compare files from a directory with md5sum and shellscript
Dude, I got to do with the awk, see if this helps you: md5sum * | awk '{if(length(te[$1]) == 1) print "O arquivo: " te[$1] " e " $2 " são iguais."; else te[$1] = $2 }' Explaining: md5sum * will…
-
1
votes2
answers351
viewsA: Use of Uniq
You can use this command: sort -u -t ';' -k5,5 nome-do-arquivo -u (Unique) which causes the equal values to be grouped. -t ';' Sets the column separator (which in the case of your file is ;). -k5,5…
-
2
votes1
answer101
viewsA: Split whole text into javascript pieces
Though I think it best that this return be a array, I managed to separate that way: var response = "222/05/2017 a 26/05/2017 em Belo Horizonte - PaperCut MF Técnico Presencial (34 hrs) - Fila de…
-
0
votes2
answers77
viewsA: How to modify specific parts within an html file?
Using the sed gets like this: sed -r 's/href="(.*)"/href="<?php echo base_url("\1"); ?>"/' arquivo-html >> novo-html Where: html file = Your file you want to change the urls new-html =…
-
1
votes2
answers863
viewsA: How to add attribute in JSON array?
A different way: var json = [{"descricao": "teste", "January": "2454.00", "February": "220.00", "March": "1070.25"}, { "descricao": "teste2", "January": "275.00"}, { "descricao": "teste3",…
-
3
votes3
answers524
viewsA: Regex in javascript for partial match in URL
You can use the .test of Regexp: /\w+\.com(\/[\/\w]*)?$/.test(url); Remembering to escape from "/". var url = "www.url.com/foo/bar/send/123"; var res = /\w+\.com(\/[\/\w]*)?$/.test(url);…
-
1
votes1
answer28
viewsA: Capturing elements by tag and inserting into an array
You can use the document.querySelectorAll, thus: var arr = document.querySelectorAll("#banners figure")
-
1
votes1
answer1023
viewsA: Transform String into Shell Script array
Do it like this: ARRAY=() while read line do [[ "$line" != '' ]] && ARRAY+=("$line") done <<< "$BASES" To check the array: for x in "${ARRAY[@]}" do echo "$x" done…
shell-scriptanswered JuniorNunes 4,886 -
1
votes1
answer2571
viewsA: Popular dynamic select with javascript
Do the following: Within your getProduct specify the correct json index: $scope.products = result.product; And see if it returns the result you expect. I ran a simulation down here so you could see…
-
36
votes3
answers83000
viewsA: Format currency with mile separator
Using your code I made some modifications: function numberToReal(numero) { var numero = numero.toFixed(2).split('.'); numero[0] = "R$ " + numero[0].split(/(?=(?:...)*$)/).join('.'); return…
javascriptanswered JuniorNunes 4,886 -
2
votes3
answers175
viewsA: Exclusion via regex
Using the sed gets like this: sed -r 's/\.[0-9]{3}"$//' nome-arquivo >> novo-arquivo Adapted from reply of @rray
-
9
votes5
answers16658
viewsA: input only numbers with jquery
See if that helps you: $('#numeric').keyup(function() { $(this).val(this.value.replace(/\D/g, '')); }); <script…
-
4
votes2
answers559
viewsA: Regular Expression for password
A different way: var a = '1a11aa1'.match(/\d.*\d+/g) != null; console.log(a); var b = 'a1a11'.match(/\d.*\d+/g) != null; console.log(b); var c = '1aaaa1'.match(/\d.*\d+/g) != null; console.log(c);…
-
3
votes1
answer243
viewsA: Script this considers enter as white space
You can use the unicode of whitespace to better specify: $(this).val($(this).val().replace(/\u0020+/g, ' ')); Example: input = 'input[type="text"]:not(.inputData), textarea'; $(document).on('blur',…
-
-1
votes4
answers182
viewsA: How can I get a specific snippet inside a string using PHP?
A different way using preg_replace: $string = "banner_2_0_.jpeg"; $result = preg_replace('/.*_(\d+)_(\d+)_\..*$/', "$2", $string); print_r($result); // Result: 0 Looking backwards for one or more…
phpanswered JuniorNunes 4,886 -
18
votes4
answers1173
viewsA: What does the regular expression "/(?=(?:...)*$)/" do in detail?
Let’s go by part: /(?=(?:...)*$)/ ?= Will capture the space followed by the expression after the =. ?: Sets the entire expression within parentheses in a non-sampling group. ... Any character 3…
-
3
votes1
answer72
viewsA: Getting specific property of a JSON object
You’ll get it like this: {{ gasto['2016'] }} Upshot: "mes": { "2": { "dia": { "5": { "-KcENENmSJcZp56clzz5": { "descricao": "teste", "valor": "99" } } } } }…
-
1
votes2
answers109
viewsA: how to change the page subtitle by choosing a select
See if that helps you: servico.onchange = function() { subtitulo.innerHTML = this.value; } <header class="jumbotron"> <h1> <img src="img/logo.png"> </h1> <h2>Pedido de…
-
2
votes1
answer281
viewsA: Find out which branch has a certain tag - Git
You can use the command: git branch --contains tags/<nome-tag> Substitute <nome-tag> by the tag you are looking for.
gitanswered JuniorNunes 4,886 -
3
votes2
answers100
viewsA: Error capturing checked attribute
Well, it has already been answered, but I leave here a different way: $('#caption-item-1').click(function(){ $('#doacao-proximo-1').css({'display': $('#boleto-input').prop('checked') ?…
-
0
votes3
answers655
viewsA: How to manipulate part of the href attribute of a link using Javascript in Wordpress?
A different way: document.querySelectorAll('.rodape a').forEach(function(el) { el.setAttribute('href', el.getAttribute('href').replace('#', '')); console.log(el); }); <div class="rodape">…
-
7
votes4
answers3526
viewsA: How to pick a String that is between Javascript tags using Regex
You can do it like this: var text = "Meu nome <[email protected]>"; var email = text.replace(/.*<(.*)>.*/, '$1'); console.log(email); Note that $1 represents the (.*), between the <…
-
0
votes3
answers1216
viewsA: Count elements and display a quantity
A different way than the ones already posted, with jquery: $('.conteudo p:first').css({ color: 'red' }); <script…
-
0
votes2
answers1096
viewsA: How to set custom name in Javascript array index?
To assign a key and value ALWAYS use json format instead of array: var obj = { '200': ['icon-check', 'The key match with the message!'], '400': ['icon-close', 'The key doesn\'t match with the…
-
4
votes3
answers21853
viewsA: How to select an option in <select> via text using jQuery?
A different way: function selectByText(select, text) { $(select).find('option:contains("' + text + '")').prop('selected', true); } selectByText('#animal', 'Bezero'); <script…
-
0
votes1
answer79
viewsA: JS Functional how to start
Well, from what I understand you want to check if a property of all the items in the array are equal and return the result, see if this suits you: function compareArrayValues(arr, field, callback) {…
javascriptanswered JuniorNunes 4,886 -
1
votes3
answers226
viewsA: Sum inputs checkbox and at the end subtract one
I imagine that solves your problem: $('#molhos input[type="checkbox"]').change(function() { var count = $('#molhos input[type="checkbox"]:checked').length; count = count == 0 ? 0 : count-1; var…
-
1
votes1
answer250
viewsA: problem with jquery Mask in dynamic form
You will have to load the function every time you add an input (modify the DOM), so use the $(document).bind('DOMSubtreeModified', function(){ });: <script>…
-
3
votes1
answer5011
viewsA: allowing only letters in the input with jquery Mask
$(document).ready(function(){ $('#letras').mask('SSSS'); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script…
-
4
votes1
answer40
viewsA: Receive code from input
In pure javascript you can do so: texto.onkeyup = function() { resultado.textContent = this.value } <input type="text" id="texto"> <div id="resultado"> </div> In jQuery:…
-
1
votes1
answer900
viewsA: result: print JS variable value in <td>
A simple way would be to put an id on td which will receive the value, and then assign using the innerHTML, thus: function Enviar() { var n50, n20, n5, n1, valor, restv, qtd_n, valor_i; n50=0;…
-
0
votes4
answers150
viewsA: Basic JS exercise: simple text search
See if it suits you: var myText = "xxxx XXXX xxxx xxxx Junior Nunes"; var myName = 'Junior'; if(myText.indexOf(myName) != -1) { var hits = myName.split(''); console.log(hits); } else {…
javascriptanswered JuniorNunes 4,886 -
8
votes2
answers123
viewsA: Find words between characters { }, and remove text in PHP?
To do this, you need to follow a pattern, either the first is male or female, and the second is opposite to the first: $comoesta = "{O,A} {portador,portadora} é {o,a} mais…
-
0
votes3
answers145
viewsA: How to have id security exposed in links - PHP + Javascript
The part that is in the client (Javascript, HTML, CSS) can always be manipulated, you need to validate the data on the server side (PHP, in your case), there you will have the ID passed, just check…
-
5
votes5
answers4393
viewsA: Transforming a JSON information into a variable
Use like this: var buy = json.buy; You can use brackets too: var buy = json['buy']; Where json is the variable that contains your json.…
-
2
votes3
answers944
viewsA: Javascript - Function that returns value from a CSS property
You can pass the style between brackets [estilo]: var elemento = document.getElementById("teste"); function css(el, estilo){ console.log(estilo+':', document.defaultView.getComputedStyle(el,…
-
1
votes1
answer821
viewsA: Laravel with panel Laravel-admin
A solution would be to do this control with javascript: document.querySelectorAll('[name="ReacaoAlergica"]').forEach(function() { this.addEventListener('click', function() {…
-
3
votes1
answer4816
viewsA: How to change the width of a native bootstrap navbar?
You can do the following: .navbar.custom { width: 50%; margin: 0 auto; } <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"…
-
4
votes4
answers2310
viewsA: I cannot disable a checkbox with enable = false
You can use the property disabled instead of enable, follows an example: document.getElementById('click').addEventListener('click', function() { document.getElementById('check').disabled =…
javascriptanswered JuniorNunes 4,886 -
8
votes2
answers7935
viewsA: Install specific version of a library with NPM
You can use the @ to specify the version, thus: npm i [email protected]
npmanswered JuniorNunes 4,886 -
1
votes2
answers866
viewsA: Toggle - get true or false result
You can do it like this: $('#teste[type="checkbox"]').change(function() { $(this).next('div').toggleClass('lcs_on', this.checked).toggleClass('lcs_off', !this.checked); }); .lcs_on:after { content:…
-
7
votes2
answers100
viewsA: Format php number
Do it like this: $novoValor = str_replace(',', '.', $valor);
phpanswered JuniorNunes 4,886 -
2
votes1
answer106
viewsA: PHP Array for JS Array
In that case the best thing to do is to use a console.log only in the variable to find out how the structure is coming, so: console.log(js_arr); After it returns the structure, watch carefully to…
-
1
votes2
answers141
viewsA: Search content within tag parameters
Just change the $(this).text() for: $(this).html() Stay like this: $('#search').keyup(function() { filterMap(this); }); function filterMap(element) { var value = $(element).val().toLowerCase();…
-
2
votes2
answers1678
viewsA: How to change the select text after an option is chosen?
You can do it like this: ddi.onchange = function() { var option = this.querySelector('option:checked'); option.setAttribute('data-name', option.innerHTML); //essa parte é opcional caso você não…
-
1
votes2
answers63
viewsA: PHP does not print output when equal to 0
It must be coming empty, put it like this: echo "<td width='11%' style='text-align:center;><p><br/>". $dados['dado_1'] ? $dados['dado_1'] : '0' ."</p></td>";…
phpanswered JuniorNunes 4,886 -
3
votes1
answer400
viewsA: Transform Array and String
You can use the json_encode to turn into string. $dataString = json_encode($arrayOut); In case you want to take some fields, before using the json_encode make a loop and take out the fields you…