Posts by Tom Melo • 1,703 points
58 posts
-
1
votes1
answer151
viewsA: Is there any technical reason for the Observer pattern or similarities not to be used independently of the observed object?
Is there any technical reason why the Observer or Simiandos pattern should not be used independently of the observed object? From the point of view of cohesion and coupling, both the Subject…
-
1
votes1
answer29
viewsA: Lamda functions - How do I loop AWS-Stepfunctions - with Nodejs?
According to the documentation you can create a Lambda Function that works as an "Iterator": Ex: exports.iterator = function iterator (event, context, callback) { let index = event.iterator.index…
-
0
votes2
answers183
viewsA: How to get the Exit code from a command block
set -e Forces completion of a pipeline execution (or sequence of commands) when an error occurs, so you can get Exit status through the $? Reference: set…
-
0
votes2
answers173
viewsA: How to validate data securely in the frontend?
Not! From an attacker’s point of view, there is no "secure validation on the front end", it will simply be ignored. As much as you limit the origin of the request(CORS), it is extremely simple to…
-
0
votes1
answer90
viewsA: Generate constant tags using Xstream in Java
An option to not need to declare your attributes in uppercase letter and with final access modifier, would be to use the annotation @XStreamAlias("nome do atributo"). Example:…
-
3
votes1
answer83
viewsA: Is there a property in Maven to access the "Resources" directory value?
${project.build.resources[N].directory} N = Index of your resource (e.g.: 0.1.2 and so on). According to the documentation, the default resource directory(a.k.a Resources) is located in:…
-
1
votes1
answer74
viewsA: Costs related to AWS Lambda and S3 codes
The question is a bit confusing and the "every function that starts the same lowers the S3 code" part generates different interpretations, but let’s get to the point: Function Code If you are…
-
1
votes4
answers938
views -
2
votes3
answers1819
viewsA: Create shortcut for complex commands in CMD
You can create an alias for your command using DOSKEY Just create a file in any directory, for example: C: Users Tommelo Documents macros.Doskey print=echo $* Then just add a regkey to make the…
-
1
votes3
answers99
viewsA: Run Shell Script by checking the 32bit or 64bit system architecture
#!/bin/bash if [ $(uname -m) = "x86_64" ]; then echo "x64" else echo "x86" fi
shell-scriptanswered Tom Melo 1,703 -
1
votes2
answers4682
viewsA: How to replace letter typed in python?
Resurrecting the topic... But anyone who still has any doubts about how to do this, I believe a character rotation algorithm(Cipher of Caesar), in some cases, may easier and more dynamic than the…
-
0
votes1
answer149
viewsA: Extract substring from a bash line with a Pattern
I do not know if I understood very well, but supposing that the file has the format: Sala 1:4 FF Sala1 2:5 FF Sala2 3:6 FF And you just want the numbers in the second column: #!/bin/bash while read…
-
1
votes4
answers260
viewsA: Send data to server even if window is closed
The event beforeunload will be triggered when a page suffers a "Unload" and not effectively to any scenario where the user leaves the page (turn off the computer for example). Maybe a solution with…
-
2
votes1
answer55
viewsA: Shell Script for Postgresql Download
Maybe the Sort -V may help you in this matter. Example: #!/bin/bash base_url="https://ftp.postgresql.org/pub/source/" href_pattern='s/.*href="\([^"]*\).*/\1/p' last_version=$(curl -s $base_url | sed…
-
2
votes1
answer445
viewsA: How to get the runtime of a program with shell script?
This is because, by default, the team sends the result to stderr instead of stdout. You just need to redirect the output. Example: #!/bin/bash outfile="benchmark.txt" for i in $(seq 1 15) do echo…
-
0
votes1
answer85
viewsA: List Classes with Generated Jar
This implementation is based on the lookup of directories/.class files that simply don’t exist when you generate the jar. Put some prints in the code that you will notice the search being performed…
-
1
votes4
answers117
viewsA: Copy one line at a time from the source file to the target files
From the point that the file has the following format: Rogério:Amélia Cleiton:Bruna Mauro:Carla Diego:Denise Maicon:Emiliane Delvair:Fátima José:Graça Marcos:Helena Neto:Irene Tiago:Júlia We can use…
-
3
votes1
answer58
viewsA: Print all 0
for (int i = 0; i <= 999999999; i++) { System.out.println(String.format("%09d", i)); } See the example above working on IDEONE…
-
2
votes1
answer90
views -
0
votes2
answers963
viewsA: Run HTTP POST asynchronously in JAVA
Looks like you’re using the Apache Http Components, and the api already provides the module Httpasyncclient for asynchronous requests. pom.xml <dependency>…
-
3
votes1
answer156
viewsA: Convert java lambda predicates
Picking up a lambda expression for runtime translation is a virtually impossible task(so far), I will try to give you two suggestions: 1 - Think of a simpler solution that doesn’t involve a…
-
1
votes1
answer249
viewsA: How to ignore certain elements in a list that will go through a random process? (pending)
One way is you create your own shuffle ignoring the desired elements: def shuffle(items, frozen_items): frozen = [(pos, item) for (pos, item) in enumerate(items) if item in frozen_items]…
-
1
votes1
answer537
viewsA: How to open and close a browser window programmatically using bash commands in Ubuntu 16.04?
Apparently its variable PID is not receiving the id of the process generated in the browser opening. It is a bit difficult to use the Jobs -p in this situation as it displays the processes managed…
-
0
votes1
answer295
viewsA: Access sub-tables in a moon table
You only need to set the reference in table(key, value): name = {"Lowes", "Renata", "Titia", "Maria"} health = {} posx = {} posy = {} posz = {} players = {["name"]=name, ["health"]=health,…
-
3
votes2
answers830
viewsA: Filter number of characters with SED or grep
I don’t know if I understand it very well, but suppose you have a text file in the following format: txt file. abcde aabbc kkkkk ggggggggggggg ccdde We can filter as follows: cat arquivo.txt | grep…
-
0
votes2
answers2266
viewsA: How to find the name of the key in a dictionary by the value contained in it?
A very basic example: dicio = {'pizza': {'massa', 'ketchup'}, 'feijoada': {'feijão', 'linguiça'}} def search(term): for k, v in dicio.items(): if term in v: return k return None…
-
0
votes1
answer205
viewsA: Error with facebook login in php
Apparently missing add the web platform in the settings: Settings -> Basic -> Add Platform Choose the option "Site" Set the url and save…
-
0
votes1
answer336
viewsA: Socket connection between servers
The very brief question is: how to connect and exchange messages between two servers via "sockets" (back-end only)? In the same way that you communicate through the front end, just open the…
-
2
votes1
answer251
viewsA: Generic and Comparable in Java
My question here is: Why I can only do one way and not both, since one element is inherited from the other and then also inherits the interface comparable Figure? The problem is unrelated to the…
-
3
votes2
answers422
viewsA: What is the advantage of using one database for reading and another for writing?
There are some points that make a lot of difference: Read performance: If I have more machines available(read replicas) do you agree that the readings will be faster? Distributed load balancing…
-
0
votes2
answers218
viewsA: I cannot capture ROUTE without using index in URL
Apparently it’s OK your .htaccess. Maybe the directives Errordocument and Fallbackresource help complete what you intend to do (direct all routes, even non-existent resources, to index.php).…
-
2
votes1
answer199
viewsA: How to make an Amazon EC2 instance listen to the 5000 port via HTTP?
Set your Security Group’s Inbound Rule to Custom TCP at port 5000, also add the range 0.0.0.0/0 in the Source to free access to any ip in your application.
-
1
votes1
answer99
viewsA: How to create a Mysql schema after starting an instance in AWS-RDS?
If your instance is with public access just configure ip, port, user and password in Workbench. If your instance only has access within your VPC, you need to configure the connection via SSH using…
-
0
votes1
answer82
viewsA: Delete "," in the first and last line of a CSV
Apparently the sed would solve in a simple way this example you gave: sed s/,,//g Assuming the text format is: +++ Host - Begin +++,, Name,Description test1,abc2 test2,abd3 +++ Host - End +++,,…
-
1
votes2
answers1532
views -
1
votes3
answers203
viewsA: Combine arrays
An ugly example: <?php $array1 = array('A', 'B', 'C'); $array2 = array(1, 2, 3); $array3 = array('x', 'y', 'z'); $output = array(); foreach ($array1 as $value1) { foreach ($array2 as $value2) {…
-
0
votes1
answer476
viewsA: Mock of a class that has parameters in the constructor
1 - Use of @Spy / Mockito.Spy() Ex: Constructor with parameter: public class MyService { private String param; public MyService(String anyParam) { this.param = anyParam; } public String getParam() {…
-
1
votes1
answer531
viewsA: Sending token via header or param
In practice, nothing prevents you from passing the token through the header, request body or query string. According to the RFC7519 the sending pattern of the token is through the Header…
-
0
votes1
answer220
viewsA: Python function in AWS Lambda
If you set the function subset_sum Like Handler of your Lambda Function, the parameters that are passed are different from your test subset_sum([1,2,3], 5). Handler invoke takes the parameters:…
-
2
votes1
answer673
viewsA: Set timeout on thread execution and save return value
An alternative would be the use of Executorservice Basic Example: Rpcresult.class: public class RpcResult { private int clientId; private String response; // getters and setters... }…
-
2
votes4
answers1081
viewsA: Get the contents of the last line of a Java file
Since you don’t know the number of lines or the size of the file: Randomaccessfile. You can make your own implemetation or use the Apache Commons IO implementation:…
-
3
votes1
answer576
viewsA: How does content-type work in java?
Content-Type is an HTTP Header that identifies which data structure will be sent/received from the server, and is language independent. In this case: Content-Type: application/x-www-urlencoded means…
-
1
votes1
answer895
viewsA: Delete last line - Java
The problem is that in your "record" method you are forcing the "break line" right after writing the text. One of the ways to avoid this, instead of replacing n, is to avoid line breaking. The…
-
0
votes1
answer398
viewsA: Looking for Keywords in Elasticsearch
You can get the result using Function Score Query. Documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html Assuming you are using the…
-
1
votes1
answer928
viewsA: How to generate a long life token for posting information on facebook
1 - You can renew your "short-lived-token"; 2 - From your "short-lived-token" you can get a "long-lived-token" with endpoint: GET /oauth/access_token? grant_type=fb_exchange_token&…
-
1
votes2
answers140
viewsA: Instantiate an object throughout the life cycle of the Java application
Just to clarify a few points that were a little confusing: There is no "being connected to Bucket", what aws sdk is doing is taking your credentials to sign the request, you are working with http…
-
0
votes2
answers174
viewsA: Split() javascript method in an array
// Utilizando for var phrases = ["How are you doing today?", "I am great"]; for (var index in phrases) { console.log(phrases[index].split(" ",…
-
3
votes2
answers1141
viewsA: What code to search for available domains?
Maybe the function checkdnsrr help you: http://php.net/manual/en/function.checkdnsrr.php if (checkdnsrr("www.globo.com.br", "A")) { echo "Domínio encontrado"; } else { echo "Domínio não encontrado";…
-
6
votes3
answers1357
viewsA: Is it wrong to use multiple cases for the same action on the switch?
As already answered, is valid and works. My choice is usually the aesthetic part of the code, in this case your performance is by no means a concern. Another approach(yes, with much more code to…
-
2
votes3
answers102
viewsA: Replace command output with a custom message
Have you tried: sudo openvpn --config srvproxy-udp-1194-config.ovpn > /dev/null && echo "Conectado" || echo "Ops, tem algo errado" ?