Leaderboard
Popular Content
Showing content with the highest reputation on 03/02/2022 in all areas
-
Improving _ArrayDisplay speed
mutleey and one other reacted to pixelsearch for a topic
"Unstable sort" vs "Stable sort", is it really important and useful ? There are very few comments about it on our Forum. I found a trac ticket #3620 dated 4 years ago, some stackoverflow comments, Wiki & other web pages etc... The pics above explain it : * Left pic : the array is unsorted (location : plant 1 after plant 2) But let's notice how the products are nicely presented in their own column (a, b, c, d, e) for each plant. * Middle pic : we click on the location column's header to sort it, plant 1 comes first as expected... but now the product column is a total mess because the rows order hasn't been preserved when the same key was found during the sort (the keys here are plant #1 and plant #2). This is an unstable sort. * Right pic : with the appropriate code, we click on location column's header and get a stable sort. The rows aren't scrambled any more for each plant and the product column looks great (as it was in the pic on the left) AutoIt sorts are natively unstable (quicksort in _ArraySort, or the creation of the indexes for the virtual listview in _ArrayDisplay) . I found it challenging to write some code for _ArrayDisplay to get a stable sort when a column needs sorting. Also it allowed me to compare AutoIt results with C++ results (as C++ got natively a stable sort algorithm in its STL, added to its non-stable sort algorithm) Comparative tests in C++ and AutoIt, on arrays of 10.000 rows and 6 columns (which got duplicate keys in their sorted column) gave good results (no differences in the output). Maybe the following code to achieve a stable sort in ArrayDisplay could be useful to someone one day, who knows ? Func __ArrayDisplay_SortArrayStruct(Const ByRef $aArray, $iCol, $bStableSort = False) Local $iDims = UBound($aArray, $UBOUND_DIMENSIONS) Local $tIndex = DllStructCreate("uint[" & $_g_ArrayDisplay_nRows & "]") Local $pIndex = DllStructGetPtr($tIndex) Static $hDll = DllOpen("kernel32.dll") Static $hDllComp = DllOpen("shlwapi.dll") Local $lo, $hi, $mi, $r, $nVal1, $nVal2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; If $bStableSort Then Local $aDupe[$_g_ArrayDisplay_nRows], $iDupe, $bMove ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Sorting by one column For $i = 1 To $_g_ArrayDisplay_nRows - 1 $lo = 0 $hi = $i - 1 Do $mi = Int(($lo + $hi) / 2) If $_g_ArrayDisplay_aNumericSort[$iCol] Then ; Numeric sort If $iDims = 1 Then $nVal1 = Number($aArray[$i]) $nVal2 = Number($aArray[DllStructGetData($tIndex, 1, $mi + 1)]) Else $nVal1 = Number($aArray[$i][$iCol]) $nVal2 = Number($aArray[DllStructGetData($tIndex, 1, $mi + 1)][$iCol]) EndIf $r = $nVal1 < $nVal2 ? -1 : $nVal1 > $nVal2 ? 1 : 0 Else ; Natural sort If $iDims = 1 Then $r = DllCall($hDllComp, 'int', 'StrCmpLogicalW', 'wstr', $aArray[$i], 'wstr', $aArray[DllStructGetData($tIndex, 1, $mi + 1)])[0] Else $r = DllCall($hDllComp, 'int', 'StrCmpLogicalW', 'wstr', $aArray[$i][$iCol], 'wstr', $aArray[DllStructGetData($tIndex, 1, $mi + 1)][$iCol])[0] EndIf EndIf Switch $r Case -1 $hi = $mi - 1 Case 1 $lo = $mi + 1 Case 0 ExitLoop EndSwitch Until $lo > $hi ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; If $r = 0 And $bStableSort Then If $i = $mi + 1 Then DllStructSetData($tIndex, 1, $i, $i + 1) $aDupe[$i] = $i $aDupe[DllStructGetData($tIndex, 1, $i)] = $i Else $iDupe = $aDupe[DllStructGetData($tIndex, 1, $mi + 1)] If $iDupe = 0 Then $aDupe[$i] = $i $aDupe[DllStructGetData($tIndex, 1, $mi + 1)] = $i DllCall($hDll, "none", "RtlMoveMemory", "struct*", $pIndex + ($mi + 1) * 4, "struct*", $pIndex + $mi * 4, "ulong_ptr", ($i - $mi) * 4) DllStructSetData($tIndex, 1, $i, $mi + 2) Else $bMove = False For $j = $mi + 2 To $i If $aDupe[DllStructGetData($tIndex, 1, $j)] <> $iDupe Then $bMove = True ExitLoop; For $j... EndIf Next If Not $bMove Then DllStructSetData($tIndex, 1, $i, $i + 1) Else DllCall($hDll, "none", "RtlMoveMemory", "struct*", $pIndex + $j * 4, "struct*", $pIndex + ($j - 1) * 4, "ulong_ptr", ($i - $j + 1) * 4) DllStructSetData($tIndex, 1, $i, $j) EndIf $aDupe[$i] = $iDupe EndIf EndIf ContinueLoop ; For $i... EndIf ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DllCall($hDll, "none", "RtlMoveMemory", "struct*", $pIndex + ($mi + 1) * 4, "struct*", $pIndex + $mi * 4, "ulong_ptr", ($i - $mi) * 4) DllStructSetData($tIndex, 1, $i, $mi + 1 + ($lo = $mi + 1)) Next Return $tIndex EndFunc ;==>__ArrayDisplay_SortArrayStruct If anyone finds a bug, please report here, thank you Edit: March 4, 2022 : The code above is ok to get a stable sort. But I'm revising my opinion concerning the speed process. If the array is big and the column to sort got plenty of duplicate keys, then the time to prepare the "stable-sort index" will be longer than preparing it with the native unstable sort code. So one should always have this in mind and use the stable sort only when it's really needed (on small arrays of a few thousands elements for example) Edit: March 5, 2022 : Working on a solution for a faster stable sort, to avoid the nasty loop For $j = $mi + 2 To $i (which takes time if any duplicate key is found many times in the array) Results look promising, When ready, I'll post an alternate way in a new post below.2 points -
[Auto Answers] Could use some help with script
Musashi reacted to SOLVE-SMART for a topic
Hi folks, I completed a first version v0.1.0 of "Au3AnswerByTag". It can be visit and checked on GitHub. If you don't want to get the complete release package, just use the zip archive that is attached to this post 😉 . Only the program files are in the zip, no documents or other GitHub related stuff. Now it's time to do proper testing or at least just a review @Nine 😅 . But please keep in mind that I have to talk again with @barkeeper about the current features and possible upcoming changes. Best regards Sven ________________ Stay innovative! Au3AnswerByTag.zip1 point -
AutoIt Extension for Visual Studio Code
barkeeper reacted to SOLVE-SMART for a topic
Hi @Danp2, I also enjoy it every day 😀 . Maybe I can help a bit. Please check if the path is set and correct for AutoIt3Wrapper.au3 here: Unfortunately F12 doesn't work properly to open #include UDFs/scripts. I couldn't determine when it will work and when not, it's pity. I use a small tool, Au3GotoDefinition (written by me, initial commit 14 Jul 2019), which runs in the background and replaced the unstable F12 functionality. To jump back and forth I use the mouse keys: I am pretty sure you will find "Keyboard Shortcuts" Ctrl+K Ctrl+S (to open the keyboard shortcuts) for doing this as well. Update: I already found it: Bookmarks are not available out of the box. Like you wrote, you have to add an extension. This is basically the way to go with VSCode 😅 You ask about recommended extensions. This of course depends on your needs. Here are some general useful extension that are programming language independent: Path Intellisense Project Manager Color Highlight Output Colorizer And several snippet extensions for your programming language of choice 😀 . Best regards Sven ________________ Stay innovative!1 point -
Most browsers will try to properly encode a URL before sending it. As you have found out, the _InetGetSource() function does not do any special encoding of your URL. Therefore, you must make sure that your URL is properly encoded before sending it. The example below shows one of many functions (_UnicodeURLEncode) that can be used to encode all or part of a URL. You can find another example in the topic below. If you are building URLs dynamically, it's probably a good idea to encode the URL whether you think you need to or not. Example: #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include <Inet.au3> #include <Debug.au3> #include <json.au3> example() Func example() Local $sEncodedRequest, $sRespone, $sJson Local $oJson Const $REQUEST = "https://postman-echo.com/get?first_name=سلام" _DebugSetup(Default, False, 5) ;Encode & display the URL $sEncodedRequest = _UnicodeURLEncode("https://postman-echo.com/get?first_name=سلام") _DebugOut("HTTP Request (Raw) = " & $REQUEST) _DebugOut("HTTP Request (Encoded) = " & $sEncodedRequest) ;Send HTTP GET request $sRespone = _INetGetSource($sEncodedRequest, False) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "_INetGetSource failed! @error = " & @error) ;Decode JSON response $oJson = Json_Decode(BinaryToString($sRespone, $SB_UTF8)) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Unable to decode response. @error = " & @error) ;Display pretty-printed response (unicode and slashes are unescaped) $sJson = Json_Encode($oJson, $JSON_PRETTY_PRINT + $JSON_UNESCAPED_UNICODE + $JSON_UNESCAPED_SLASHES, " ") _DebugOut(@CRLF & "JSON Response (unicode and slashes are unescaped)") _DebugOut($sJson) EndFunc ;=============================================================================== ; _UnicodeURLEncode() ; Description: : Encodes an unicode string to be URL-friendly ; Parameter(s): : $UnicodeURL - The Unicode String to Encode ; Return Value(s): : The URL encoded string ; Author(s): : Dhilip89 ; Note(s): ; https://www.autoitscript.com/forum/topic/46894-unicodeurl-udf/ ;=============================================================================== Func _UnicodeURLEncode($UnicodeURL) Local $UnicodeBinary = StringToBinary ($UnicodeURL, 4) Local $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1) Local $UnicodeBinaryLength = StringLen($UnicodeBinary2) Local $UnicodeBinaryChar Local $EncodedString For $i = 1 To $UnicodeBinaryLength Step 2 $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2) If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar) Else $EncodedString &= '%' & $UnicodeBinaryChar EndIf Next Return $EncodedString EndFunc Example output HTTP Request (Raw) = https://postman-echo.com/get?first_name=سلام HTTP Request (Encoded) = https://postman-echo.com/get?first_name=%D8%B3%D9%84%D8%A7%D9%85 JSON Response (unicode and slashes are unescaped) { "args": { "first_name": "سلام" }, "headers": { "x-forwarded-proto": "https", "x-forwarded-port": "443", "host": "postman-echo.com", "x-amzn-trace-id": "Root=1-6215610f-575e35fb5529a4b26d20bf55", "user-agent": "AutoIt", "cache-control": "no-cache" }, "url": "https://postman-echo.com/get?first_name=%D8%B3%D9%84%D8%A7%D9%85" }1 point
-
use <> because != is not correct syntax in AutoIt1 point
-
I tried to run an app under LSA using impersonate user, Runas Func and much more but nothing helped finally i found how to go ahead Herez the script for anyone having the same problem As per the License Q: How many copies of Sysinternals utilities may I freely load or use on computers owned by my company? A: There is no limit to the number of times you may install and use the software on your devices or those you support. Installation and use will not cause any violation of the License #NoTrayIcon #include-once Opt("MustDeclareVars", 1) _Runas_SYSTEM('notepad.exe', '-heya') ;$sRunProgramAsSystem : The Program which has to be run under LSA ;$sParams : The parameters which have to be passed to the specific program ;$sSession : if the program is GUI based then the Session should be the Current Session Usually 1 , if null Console Session is used ;$sPriority : -low, -belownormal, -abovenormal, -high, -background or -realtime Func _Runas_SYSTEM($sRunProgramAsSystem, $sParams = '', $sSession = 1, $sPriority = '-abovenormal'); Your Program Goes here. Local $sPath = @ScriptDir & '\PsExec.exe' If Not FileExists($sPath) Then MsgBox(16, 'Error', 'Please download the PsExec.exe from the upcoming site') ShellExecute('http://technet.microsoft.com/en-us/sysinternals/bb897553') Return SetError(1, 0, -1) EndIf If $sParams Then $sParams = ' ' & $sParams Local $aResult = ShellExecuteWait($sPath, '-i ' & $sSession & ' ' & $sPriority & ' -d -s -h "' & $sRunProgramAsSystem & '"' & $sParams, @SystemDir, 'open', @SW_HIDE) If @error Then ConsoleWrite('! > Error Occured Error Code: ' & @error) Return $aResult EndFunc ;==>_Runas_SYSTEM Regards Phoenix XL1 point