Posts by stderr • 30,356 points
651 posts
-
3
votes1
answer3476
viewsA: How to put elements of a list in another list
Use the method extend to add list items a and the append to add the second item in the list b: a = [1, 2, 3] b = [2, 4, 6] c = [] c.extend(a) c.append(b[1]) print(c) # [1, 2, 3, 4]…
-
5
votes3
answers14487
viewsA: Divide a list into n sublists
You can use the range: def chunks(lista, n): for i in range(0, len(lista), n): yield lista[i:i + n] l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] print(list(chunks(l, 3))) # [[0, 1, 2], [3,…
-
2
votes2
answers4607
viewsA: How to know which button was clicked?
This will depend on how the button Record is invoked, if you call it so: private void button_inserir_Click(object sender, EventArgs e) { // ... button_guardar_Click(sender, e); } You may know who…
-
4
votes2
answers1413
viewsA: How to verify which is the name of the spreadsheet tab Excel C#
You can use the method GetOleDbSchemaTable, as mentioned in that reply. public static List <string> ListSheetInExcel(string filePath) { OleDbConnectionStringBuilder sbConnection = new…
-
2
votes2
answers194
viewsA: How do I exchange the 3 and 5 occurrences of a word in a string
The question was already very good answered by Miguel, follows below an alternative manipulating the indices of the string: def trocar (texto, substituir, substituto, ocorrencias): indice =…
python-3.xanswered stderr 30,356 -
1
votes1
answer405
viewsA: Attach file using Webbrowser Delphi
It is not possible to change this field because it is read-only due to security issues. What you can do is send the file separately using the components of Indy, the TIdMultipartFormDataStream and…
-
9
votes1
answer2775
viewsA: Load Combobox from a List<>
Use the property DataSource of Combobox. // ... List<Control.CadCategoriaProduto> produto = new List<Control.CadCategoriaProduto>(); // ... cmbCategoria.DataSource = produto;…
-
1
votes2
answers53
viewsA: how to structure php nodes
Thus? $nodes[] = '"name": "' . $row['name'] . '", "color": "' . $row['color'] . '"'; //Array //( // [0] => "name": "Baixo Alentejo", "color": "#f0e68d\r\n" //) To format as JSON, use the…
-
4
votes1
answer530
viewsA: Alternative to If/Else
Without if/else should not be possible, but you can you can use the operator && to do in a if only: private void maskedTextBoxEAN_Leave(object sender, CancelEventArgs e) { if…
-
1
votes1
answer418
viewsA: Sending a payload with scapy
Raw is a file class packet.py of Scapy. You can see the source code here. class Raw(Packet): name = "Raw" fields_desc = [ StrField("load", "") ] def answers(self, other): return 1 #s = str(other) #t…
-
0
votes1
answer803
viewsA: Replace a variable within a Word file
The syntax of the method Find.Execute is: bool Execute( ref Object FindText, ref Object MatchCase, ref Object MatchWholeWord, ref Object MatchWildcards, ref Object MatchSoundsLike, ref Object…
-
2
votes2
answers1301
viewsA: Size difference (Release/Debug)
By default there are three build settings: Groundwork, Debug and Release. In the Project Manager, Build Configurations represents Groundwork, the settings of Debug and Release are listed in separate…
-
4
votes5
answers1240
viewsA: How to split a string into specific Javascript sizes?
string.match console.log("stackoverflow".match(/.{1,3}/g)); Array.map var str = 'stackoverflow'; var partes = 3 var pedacos = [] str.split('').map(function(v, i){ var len = str.length - 1 if ((i %…
-
1
votes4
answers559
viewsA: Load url on same page
You can use the json_encode to format the json, and curl to place the order: function enviarSMS($email, $senha, $numero, $msg){ $curl = curl_init("https://site.com/apiJSON.php?data="); $data =…
-
5
votes2
answers1023
viewsA: How to remove a repeated character in sequence?
Another alternative is: function unique($palavra){ $p = str_split($palavra); return implode(array_map(function ($c) use ($p) { return ($c > 0 && $p[$c] == $p[$c - 1] ? '': $p[$c]); },…
-
5
votes3
answers1045
viewsA: Fibonacci with parallel execution? Threads?
You can use the multiprocessing: (In free translation) multiprocessing is a package that supports spawning processes using an API similar to the module threading. The package multiprocessing offers…
-
1
votes2
answers1282
viewsA: Shell/Bash - Script continues before finishing the line that is running
There are some alternatives. One of them is the command timeout. Executes a command with a time limit, executes the given command and ends if it is still running after the time interval specified.…
-
1
votes1
answer127
viewsA: Remove part of a text in the combobox
You can use the function TPath.GetFileNameWithoutExtension: Uses IOUtils; // .... procedure TForm1.FormCreate(Sender: TObject); const Arquivos: array[1..3] of string = ('demons.txt ','arch.txt…
-
0
votes2
answers2514
viewsA: How to delete a specific line from a file?
To upload the file to Listbox, do so: string caminho = AppDomain.CurrentDomain.BaseDirectory.ToString() + "foobar.txt"; listBox1.Items.Clear(); if (File.Exists(caminho)) { string[] linhas =…
-
12
votes3
answers1093
viewsA: How to check if at the end of String is one or zero?
You can use the function String#endsWith: System.out.println("jrp_jasper.jrp_jas_nome|0".endsWith("0")); // true System.out.println("jrp_jasper.jrp_jas_sobrenome|1".endsWith("0")); // false It is…
-
5
votes2
answers890
viewsA: How to add parallelism in execution with the subprocess module?
The code works but every time I run a program, by example, c: windows Notepad.exe, the prompt gets stuck until I close the program. This happens due to redirecting which is made up of file…
-
2
votes1
answer256
viewsA: Shellexecute without Security Warning
Yes. And you will have to use the function ShellExecuteEx. You can temporarily disable the environment variable SEE_MASK_NOZONECHECKS: Do not perform a zone check. This flag Allows ShellExecuteEx to…
-
6
votes3
answers1852
viewsA: Reading blank blank blank blank blank files
You can use the function str.splitlines(): with open("arquivo.txt", "r") as f: linhas = f.read().splitlines() for linha in linhas: print (linha)…
-
3
votes1
answer33
viewsA: How to declare functions in an array declared in a class block?
According to the page of PHP on properties, this happens because: [...] Are defined using one of the keywords public, protected, or private, followed by a normal variable declaration. This…
-
1
votes1
answer25
viewsA: Remove UI Debugging Tools from Window
Clear the option: Tools ⇢ Options ⇢ Debugging ⇢ General ⇢ Enable UI Debugging Tools for XAML. Source…
-
1
votes1
answer33
viewsA: Local and global variable difficulty - PHP
You can declare the variable outside the if: $email_cad = $_GET["email_cad"]; if(!empty($email_cad)){ $sql = "SELECT email_cad FROM part_user WHERE email_cad = '$email_cad' "; }else { echo "Insira…
-
2
votes2
answers2753
viewsA: Capturing user keystrokes in Python on Linux
You can use the pyxhook: #!/usr/bin/env python import pyxhook def OnKeyPress(event): print (event.Key) # Pressione <space> para terminar o script if event.Ascii == 32: exit(0) hm =…
-
1
votes2
answers2187
viewsA: Copy directory from one ssh server to another
You can use the sshpass: sshpass is a Utility Designed for running ssh using the mode referred to as "Keyboard-Interactive" password Authentication, but in non-interactive mode. To install on…
-
4
votes2
answers466
viewsA: Changing Key in Windows 10 Registry
Has two quotes " the most: subprocess.Popen( "REG ADD HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\" ----------^ " /v AdobeDoMal /d " + TEMPDIR + "\\" + FILENAME,…
-
2
votes3
answers129
viewsA: Detect text within a special character and convert it into a PHP function
You can also use the function strpos to check whether a string is found in a text. <form method="post" action="#"> <textarea name="texto" rows="4" cols="40">Lorem impsun [galeria] Lorem…
-
2
votes3
answers641
viewsA: Add zeros right Textbox C#
You can also do so: private void textBox1_Leave(object sender, EventArgs e) { textBox1.Text = String.Format("{0:#,##0.00}", double.Parse(textBox1.Text)); }
-
2
votes1
answer1011
viewsA: Move all files with the . prj extension to a folder
In more recent versions of Delphi, there is a function that does this: IOUtils.TDirectory.GetFiles, to use it, add IOUtils in Uses. Use like this: Uses IOUtils; //... procedure…
-
3
votes2
answers591
viewsA: Start a command line tool in Python
To execute an external command use the module subprocess: import subprocess subprocess.call(["ls", "-l"]) Or using the method os.system(): import os os.system("ls -l") Editing: Use sys.platform: to…
-
5
votes1
answer5651
viewsA: How to take screenshot of the screen in Python?
First if you have not installed the module, install: ~$ sudo apt-get install python-pip && pip install pyscreenshot Obs: The pip is a tool for installing Python modules. To use the…
-
3
votes1
answer208
viewsA: Print array value in bash by PHP shell_exec
You’ve done nothing wrong. This problem happens due to script be interpreted differently in two different environments. When executing ./teste1.sh the system will look at the shebang, which in this…
-
4
votes2
answers1231
viewsA: Regular expression (regex) for links to web pages using Python
import urllib, re url = "/q/143677" html = urllib.urlopen(url).read() urls = re.findall('(?<=href=["\'])https?://.+?(?=["\'])', html) for url in urls: print url Regular expression will match…
-
0
votes2
answers46
viewsA: Playing more than one txt field inside the database
This is because you are accessing a fixed value of array and not the current iteration element. Alter: $dividir[0] and $dividir[1] for $valores[0] and $valores[1]. How to do this has already been…
-
1
votes1
answer494
viewsA: Treeview - click on Node and open specific screen
You can do this at the event NodeMouseDoubleClick of TreeView: private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { string node = e.Node.Text; switch (node) {…
-
2
votes1
answer2199
viewsA: What does (-X,-H,-d) mean for this command (Curl -X POST -H "Content-Type: application/json" -d) and how to do it for the php file?
curl -X POST -H "Content-Type: application/json" -d According to the documentation: -X: Specifies the request method (GET, HEAD, POST or PUT) to use when communicating with the server. -H: Indicates…
-
0
votes1
answer233
viewsA: Return 2 PDO queries in JSON
To merge the arrays you can use the function array_merge(). About the error when using the function json_encode() is due to array is not properly coded, that is to say, UTF-8. To solve this you can…
-
1
votes3
answers2128
viewsA: Send PHP variable to Shell Script
When performing the function shell_exec it is possible to pass variable values as arguments to the command that will be executed: $arquivo = "teste"; $dir = "testeDir"; $resultadoExec =…
-
1
votes1
answer326
viewsA: Show contents of a file by opening the file with the content string of a variable
You can do it like this: variavel="$(< Affonso\,\ I.\ P..txt)" echo "$variavel"
-
1
votes1
answer581
viewsA: Help with the argparse library
This happens when the unittest takes control, it will interpret the command line options again. --type is a valid argument for the main application, not for the unittest. You have to separate the…
-
1
votes3
answers1174
viewsA: Conversion of variables type int to char*. C++
Follow another form (C++11): #include <iostream> #include <sstream> using namespace std; string concatInt(int num1, int num2){ stringstream ss; ss << num1 << num2; return…
-
0
votes2
answers621
viewsA: Pick up all hours that are between start time and end time with PHP
Another way is to convert the hours into seconds and with the function range generate the schedules: function listaHorarios($horaInicio, $horaFinal) { // Converte os horários em segundos $secsInicio…
-
2
votes2
answers207
viewsA: Integer combination command. C++
Follow another alternative using Stringstream: #include <iostream> #include <sstream> using namespace std; int main() { int num1, num2, num3; stringstream ss; num1 = 505; num2 = 560; ss…
-
3
votes1
answer32
viewsA: date conversion with php
You can use the function strtotime and date: $data_BD = "2016-07-27"; $data = date("d/m/Y", strtotime($data_BD)); echo $data; // 27/07/2016 See demonstração If you prefer to use DateTime: $data_BD =…
-
4
votes3
answers600
viewsA: Creation of Array within Function
One of the ways to return a array as a result of the function is: function paises($pais){ $resultado = []; switch($pais){ case 'br': $resultado['pais'] = 'Brasil'; $resultado['capital'] =…
-
3
votes1
answer51
viewsA: Show message if a particular word is typed
You can use Console.ReadLine(): string entrada = Console.ReadLine(); if (entrada == "tree"){ Console.WriteLine("Mensagem!"); }…
-
3
votes1
answer94
viewsA: Delete list item if directory does not exist
According to the documentation this happens because: (In free translation) There is a subtlety when the sequence is being modified by the loop (this can only occur by mutable sequences, i.e.,…