Leaderboard
Popular Content
Showing content with the highest reputation on 05/02/2016 in all areas
-
A while ago I suggested that _ArraySort could be optimized for 2D arrays. I have asked for MVPs to test this code and give feedback, but it seems everyone is rather busy. I have decided to reproduce the code here, so you may do with it as you wish. My results show that (generally) the more columns you have, the faster the function runs. In some tests it ran 6 times faster than the original. This is a spin-off from another project of mine which you may already be familiar with. #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Author ........: Jos ; Modified.......: LazyCoder - added $iSubItem option; Tylo - implemented stable QuickSort algo; Jos - changed logic to correctly Sort arrays with mixed Values and Strings; Melba23 - implemented stable pivot algo; czardas - speed optimization for 2D arrays ; =============================================================================================================================== Func _ArraySort_NEW2(ByRef $aArray, $iDescending = 0, $iStart = 0, $iEnd = 0, $iSubItem = 0, $iPivot = 0) If $iDescending = Default Then $iDescending = 0 If $iStart = Default Then $iStart = 0 If $iEnd = Default Then $iEnd = 0 If $iSubItem = Default Then $iSubItem = 0 If $iPivot = Default Then $iPivot = 0 If Not IsArray($aArray) Then Return SetError(1, 0, 0) Local $iUBound = UBound($aArray) - 1 If $iUBound = -1 Then Return SetError(5, 0, 0) ; Bounds checking If $iEnd = Default Then $iEnd = 0 If $iEnd < 1 Or $iEnd > $iUBound Or $iEnd = Default Then $iEnd = $iUBound If $iStart < 0 Or $iStart = Default Then $iStart = 0 If $iStart > $iEnd Then Return SetError(2, 0, 0) If $iDescending = Default Then $iDescending = 0 If $iPivot = Default Then $iPivot = 0 If $iSubItem = Default Then $iSubItem = 0 ; Sort Switch UBound($aArray, $UBOUND_DIMENSIONS) Case 1 If $iPivot Then ; Switch algorithms as required __ArrayDualPivotSort($aArray, $iStart, $iEnd) Else __ArrayQuickSort1D($aArray, $iStart, $iEnd) EndIf If $iDescending Then _ArrayReverse($aArray, $iStart, $iEnd) Case 2 If $iPivot Then Return SetError(6, 0, 0) ; Error if 2D array and $iPivot Local $iSubMax = UBound($aArray, $UBOUND_COLUMNS) - 1 If $iSubItem > $iSubMax Then Return SetError(3, 0, 0) If $iDescending Then $iDescending = -1 Else $iDescending = 1 EndIf Local $aTrac[$iUBound +1] ; to track migrating indeces For $i = $iStart To $iEnd $aTrac[$i] = $i Next __ArrayQuickSort2D_NEW2($aArray, $aTrac, $iDescending, $iStart, $iEnd, $iSubItem, $iSubMax) __SwapSequence2D($aArray, $aTrac, $iStart, $iEnd) Case Else Return SetError(4, 0, 0) EndSwitch Return 1 EndFunc ;==>_ArraySort ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __ArrayQuickSort2D ; Description ...: Helper function for sorting 2D arrays ; Syntax.........: __ArrayQuickSort2D ( ByRef $aArray, ByRef $iStep, ByRef $iStart, ByRef $iEnd, ByRef $iSubItem, ByRef $iSubMax ) ; Parameters ....: $aArray - Array to sort ; $iStep - Step size (should be 1 to sort ascending, -1 to sort descending!) ; $iStart - Index of array to start sorting at ; $iEnd - Index of array to stop sorting at ; $iSubItem - Sub-index to sort on in 2D arrays ; $iSubMax - Maximum sub-index that array has ; Return values .: None ; Author ........: Jos van der Zande, LazyCoder, Tylo, Ultima, czardas ; Modified.......: ; Remarks .......: For Internal Use Only ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func __ArrayQuickSort2D_NEW2(Const ByRef $aArray, ByRef $aTrac, Const ByRef $iStep, Const ByRef $iStart, Const ByRef $iEnd, Const ByRef $iSubItem, Const ByRef $iSubMax) If $iEnd <= $iStart Then Return Local $iTmp ; InsertionSort (faster for smaller segments) If ($iEnd - $iStart) < 15 Then For $i = $iStart + 1 To $iEnd $iTmp = $aTrac[$i] If IsNumber($aArray[$iTmp][$iSubItem]) Then For $j = $i - 1 To $iStart Step -1 ; Follows the same logic as __ArrayQuickSort1D If ((($aArray[$iTmp][$iSubItem] * $iStep) >= $aArray[$aTrac[$j]][$iSubItem] * $iStep) And IsNumber($aArray[$aTrac[$j]][$iSubItem])) _ Or (Not IsNumber($aArray[$aTrac[$j]][$iSubItem]) And StringCompare($aArray[$iTmp][$iSubItem], $aArray[$aTrac[$j]][$iSubItem]) * $iStep >= 0) Then ExitLoop $aTrac[$j + 1] = $aTrac[$j] Next Else For $j = $i - 1 To $iStart Step -1 If (StringCompare($aArray[$iTmp][$iSubItem], $aArray[$aTrac[$j]][$iSubItem]) * $iStep >= 0) Then ExitLoop $aTrac[$j + 1] = $aTrac[$j] Next EndIf $aTrac[$j + 1] = $iTmp Next Return EndIf ; QuickSort Local $L = $iStart, $R = $iEnd, $vPivot = $aArray[$aTrac[Int(($iStart + $iEnd) / 2)]][$iSubItem], $bNum = IsNumber($vPivot) Do If $bNum Then ; While ($iStep * ($aArray[$L][$iSubItem] - $vPivot) < 0 And IsNumber($aArray[$L][$iSubItem])) Or (Not IsNumber($aArray[$L][$iSubItem]) And $iStep * StringCompare($aArray[$L][$iSubItem], $vPivot) < 0) While ($iStep * ($aArray[$aTrac[$L]][$iSubItem] - $vPivot) < 0 And IsNumber($aArray[$aTrac[$L]][$iSubItem])) Or (Not IsNumber($aArray[$aTrac[$L]][$iSubItem]) And $iStep * StringCompare($aArray[$aTrac[$L]][$iSubItem], $vPivot) < 0) $L += 1 WEnd ; While ($iStep * ($aArray[$R][$iSubItem] - $vPivot) > 0 And IsNumber($aArray[$R][$iSubItem])) Or (Not IsNumber($aArray[$R][$iSubItem]) And $iStep * StringCompare($aArray[$R][$iSubItem], $vPivot) > 0) While ($iStep * ($aArray[$aTrac[$R]][$iSubItem] - $vPivot) > 0 And IsNumber($aArray[$aTrac[$R]][$iSubItem])) Or (Not IsNumber($aArray[$aTrac[$R]][$iSubItem]) And $iStep * StringCompare($aArray[$aTrac[$R]][$iSubItem], $vPivot) > 0) $R -= 1 WEnd Else While ($iStep * StringCompare($aArray[$aTrac[$L]][$iSubItem], $vPivot) < 0) $L += 1 WEnd While ($iStep * StringCompare($aArray[$aTrac[$R]][$iSubItem], $vPivot) > 0) $R -= 1 WEnd EndIf ; Swap If $L <= $R Then $iTmp = $aTrac[$L] $aTrac[$L] = $aTrac[$R] $aTrac[$R] = $iTmp $L += 1 $R -= 1 EndIf Until $L > $R __ArrayQuickSort2D_NEW2($aArray, $aTrac, $iStep, $iStart, $R, $iSubItem, $iSubMax) __ArrayQuickSort2D_NEW2($aArray, $aTrac, $iStep, $L, $iEnd, $iSubItem, $iSubMax) EndFunc ;==>__ArrayQuickSort2D_NEW2 ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: ___SwapSequence2D ; Description ...: Helper function for populating 2D arrays. [algorithm modelled on the knight's tour problem] ; Author ........: czardas ; =============================================================================================================================== Func __SwapSequence2D(ByRef $aArray, ByRef $aTrac, $iStart, $iEnd) Local $iCols = UBound($aArray, 2), $aFirst[$iCols], $i, $iNext For $iInit = $iStart To $iEnd ; initialize each potential overwrite sequence [separate closed system] If $aTrac[$iInit] <> $iInit Then ; rows will now be overwritten in accordance with tracking information $i = $iInit ; set the current row as the start of the sequence For $j = 0 To $iCols -1 $aFirst[$j] = $aArray[$i][$j] ; copy the first row [although we don't know where to put it yet] Next Do For $j = 0 To $iCols -1 $aArray[$i][$j] = $aArray[$aTrac[$i]][$j] ; overwrite each row [following the trail] Next $iNext = $aTrac[$i] ; get the index of the next row in the sequence $aTrac[$i] = $i ; set to ignore rows already processed [may be needed once, or not at all] $i = $iNext ; follow the trail as far as it goes [indices could be higher or lower] Until $aTrac[$i] = $iInit ; all tracking sequences end at this juncture For $j = 0 To $iCols -1 $aArray[$i][$j] = $aFirst[$j] ; now we know where to put the initial row we copied earlier Next $aTrac[$i] = $i ; set to ignore rows already processed [as above] EndIf Next EndFunc ;==> __SwapSequence2D2 points
-
Do it like this: #include <Array.au3> Local $Usernames[3] = ["Dan", "Bob", "Billy"] Local $blackListUsernames[2] = ["Dan", "Scott"] For $i=UBound($Usernames)-1 To 0 Step -1 $iFound=_ArraySearch($blackListUsernames,$Usernames[$i]) If Not @error Then _ArrayDelete($Usernames,$i) _ArrayDelete($blackListUsernames,$iFound) EndIf Next _ArrayDisplay($Usernames) _ArrayDisplay($blackListUsernames) _ArrayAdd($Usernames, $blackListUsernames) ;combines the 2 arrays into 1. _ArrayDisplay($Usernames) For arrays generated from web etc. both arrays have to be unique before using the For..Next loop: #include <Array.au3> Local $Usernames[4] = ["Dan", "Bob", "Billy","Bob"] $Usernames = _ArrayUnique($Usernames) ;Uniques the array. _ArrayDelete($Usernames,0) Local $blackListUsernames[3] = ["Dan", "Scott", "Dan"] $blackListUsernames = _ArrayUnique($blackListUsernames) ;Uniques the array. _ArrayDelete($blackListUsernames,0) For $i=UBound($Usernames)-1 To 0 Step -1 $iFound=_ArraySearch($blackListUsernames,$Usernames[$i]) If Not @error Then _ArrayDelete($Usernames,$i) _ArrayDelete($blackListUsernames,$iFound) EndIf Next _ArrayDisplay($Usernames) _ArrayDisplay($blackListUsernames) _ArrayAdd($Usernames, $blackListUsernames) ;combines the 2 arrays into 1. _ArrayDisplay($Usernames)2 points
-
After using >SciTE Hopper by Ashalshaikh (with the 2nd version by wakillon) & Melba23 posting >his version, I felt it would be a great learning curve to develop a similar application. The code was re-written with emphasis entirely on speed. I didn't want to make the GUI flashy as personally I prefer performance with addons, plus I developed this for my own use, so I wanted something that would aid the help of creating code, instead of hindering it. I would like to extend a big thank you to Ashalshaikh, wakillon & Melba23, especially Melba23 because his ideas and input really helped me to learn a great deal about interacting with SciTE & AutoIt. The code is released under GPLv3 and supports multiple languages. Download: http://softwarespot.wordpress.com/code/scite-jump/1 point
-
You have to measure the font size by testing testing. #include <GDIPlus.au3> _GDIPlus_Startup() $sText = "Example very very long string" $hImage = _GDIPlus_BitmapCreateFromScan0(300, 200) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) $dimen = _GDIPlus_ImageGetDimension($hImage) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF009900) Local $hFamily = _GDIPlus_FontFamilyCreate("Arial") Local $hLayout = _GDIPlus_RectFCreate(0, 0, $dimen[0], $dimen[1]) Local $hStringFormat = _GDIPlus_StringFormatCreate() $fSize = 50 Do $hFont = _GDIPlus_FontCreate($hFamily, $fSize) $aMeasure = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $hLayout, $hStringFormat) If $aMeasure[2] = 1 Then ExitLoop $fSize -= 1 _GDIPlus_FontDispose($hFont) Until False ConsoleWrite("Font size: " & $fSize & @CRLF) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText , $hFont, $hLayout, $hStringFormat, $hBrush) _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\GDIPlus_ImageWithText.jpg") ; Clean up resources _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\GDIPlus_ImageWithText.jpg")1 point
-
For those, as me, who don't know what WebSocket is and what can be done using it: https://en.wikipedia.org/wiki/WebSocket It sounds good to have a TCP control this way. Maybe some examples will be good to have an impression of what can be done. Thx.1 point
-
#include <File.au3> #include <Winapi.au3> ;~ #include <Binary.au3> ; I don't know what this is supposed to refer to, but move this outside std UDFs directory Global Const $CP_SHIFT_JIS = 932 Local $TxtPath = FileOpenDialog("Select the TXT file", @ScriptDir, "text files (*.txt)", 1) If @error = 1 Then Exit Local $NEWdata = FileReadToArray($TxtPath) Local $Newtext For $i = 0 To UBound($NEWdata) - 1 ; are those 3 replacements necessary? $NEWdata[$i] = StringRegExpReplace($NEWdata[$i], "<cf>", @CRLF) $NEWdata[$i] = StringRegExpReplace($NEWdata[$i], "<lf>", @LF) $NEWdata[$i] = StringRegExpReplace($NEWdata[$i], "<cr>", @CR) $Newtext &= _WinAPI_WideCharToMultiByte($NEWdata[$i], $CP_SHIFT_JIS) & Chr(0) Next $hNewfile = FileOpen("NEW_" & CompGetFileName($TxtPath), 2 + 16) FileWrite($hNewfile, $Newtext) FileClose($hNewfile) TrayTip("Import", "Finish!", 3) Sleep(3000) Func CompGetFileName($Path) If StringLen($Path) < 4 Then Return -1 $ret = StringSplit($Path, "\", 2) If IsArray($ret) Then Return $ret[UBound($ret) - 1] EndIf If @error Then Return -1 EndFunc ;==>CompGetFileName This modified version should do what you want. Beware the difference between 0x00 and Chr(0).1 point
-
Sorry, I was busy with some gfx filter ideas I had which I wanted to implement and thus I didn't see this thread. Well done czardas, the speed is around 80% - 90% faster than the original one. I tested an 2D array with 3765 lines and 10 columns. The content of the sorted array is the same as the built-in sort function! I assume you love arrays...1 point
-
Just add a simple Else to @VIP code and should work like you wish, something like this: Global $ListIP = "192.168.1.168|192.168.1.200|192.168.1.2" ;Bat buoc phai co dau | hay them tu 2 IP tro len Global $MatKhau = "khongdangchokhach" Local $aArray = StringSplit($ListIP, "|") If IsArray($aArray) Then For $X = 1 To UBound($aArray) - 1 If $aArray[$X] = @IPAddress1 Then $sPass = InputBox("Dr.Tung", "Nhap mat khau", "", "$") If $sPass <> $MatKhau Then Exit (MsgBox(48, "Loi cmn roi!", "Sai Mat Khau roi baby!", 5)) ExitLoop Else ; Added Else that if the IP is not on the list Exit Exit ; Exit Code EndIf Next Else ;~ $sPass = InputBox("Dr.Tung", "Nhap mat khau", "", "$") ;~ If $sPass <> $MatKhau Then Exit (MsgBox(48, "Loi cmn roi!", "Sai Mat Khau roi baby!", 5)) Exit EndIf Regards Alien.1 point
-
Optimized _ArraySort
czardas reacted to JLogan3o13 for a topic
@czardas I don't have a ton of time to write anything up, but have a bevy of high end machines, both physical and virtual, if you want to post some examples you would like tested.1 point -
@jguinch <snip> Your comment below is right, it's definitely not my day1 point
-
A funny and fast way using Scripting.Dictionary #include <Array.au3> Local $a[4] = ["Dan", "Bob", "Billy", "Bob"] Local $b[3] = ["Dan", "Scott", "Dan"] ; create the dictionaries Local $sda = ObjCreate("Scripting.Dictionary") Local $sdb = ObjCreate("Scripting.Dictionary") ; populate them For $i In $a $sda.Item($i) Next For $i In $b $sdb.Item($i) Next ; list the wanted items Local $sdc = ObjCreate("Scripting.Dictionary") For $i In $a If not $sdb.Exists($i) Then $sdc.Item($i) Next For $i In $b If not $sda.Exists($i) Then $sdc.Item($i) Next ; get the result array $aResult = $sdc.Keys() _ArrayDisplay($aResult, "$aResult")1 point
-
You confuse the ASCII reading of a binary UTF16-LE file with a UTF16-LE (e.g. native AutoIt) string. Did you try to run my example code? As you code it, the variable $text contains exactly what is inside the double quotes, i.e. not what you want. First, don't read the text as binary, don't make the BOM part of the string. The simplest way is to FileRead the file into $text.1 point
-
Much simpler: $text(Unicode) = "データのダウンロードに失敗しました。" $test = _WinAPI_MultiByteToWideChar($text, $CP_SHIFT_JIS) MsgBox($MB_SYSTEMMODAL, "Title", $test) But of course the MsgBox won't display JIS correctly.1 point
-
Myicq, Rather than asking us to solve "puzzle / algorithm" questions, how about explaining clearly what it is you are trying to achieve by all this - because I for one will not put in any more effort until you do so. I could produce various algorithms to parse arrays all day long, but unless I understand what the end result is supposed to be I have no idea whether they are relevant to the real world problem you are trying to solve. M231 point
-
How about just a like, i would also give it stars if it were in examples?1 point
-
1 point
-
#include <Array.au3> Local $InputString = "A Bs3;4fd'g" ; => ABs34fdg Local $sOutPut = StringRegExp($InputString, "[[:alnum:]]",3) Local $rOutPut = StringRegExpReplace($InputString, "[^[:alnum:]]", "") ConsoleWrite("StringRegExp: " & IsArray($sOutPut) & " - " & _ArrayToString($sOutPut,"") & @CRLF) ConsoleWrite("StringRegExpReplace: " & IsArray($rOutPut) & " - "&$rOutPut & @CRLF)1 point
-
AutoIt Radio Player v0.0.0.8 Update of 30 apr 2016
coffeeturtle reacted to Synapsee for a topic
Last ver : v0.0.0.8 AutoIt Radio Player v0.0.0.8.zip Changelog : TODO : Console return : Related link : bass.dll source : http://www.un4seen.com/bass.html (v2.4.12.1) bass.au3 source : bass related forum post (patch 9.2/Constant from 9.0) nice autoit program for help with Curl.au3 usage by wakillon : Mp3SearchEngine nice autoit program "radio related" by nend : http://trayradio.com/1 point -
Computer Info UDF's
RestrictedUser reacted to JSThePatriot for a topic
When I first visit a new client, I take inventory of their machines, what is on them, stats, and other useful information. Up till now I would either write the information down, or just try to remember it myself. Then I decided why not write a script that would allow me to gather all this useful information, and put it in a format that I can understand and possibly print. I created that program (its even listed in this thread). I then expounded on my ideas, and have created this great Computer Information Library. Feel free to use it as you see fit, but please credit when you use one of my functions. Keywords: CompInfo, CompInfo.au3, Library, Computer, Computers, Info, Information, WMI, Windows Management Instrumentation Requires: AutoIt v3.2 + or AutoIt Beta v3.2.1.2+ Software UDFs _ComputerGetStartup _ComputerGetSoftware _ComputerGetUsers _ComputerGetGroups _ComputerGetServices _ComputerGetThreads _ComputerGetProcesses _ComputerGetOSs _ComputerGetShares _ComputerGetEventLogs _ComputerGetBootConfig _ComputerGetExtensions _ComputerGetDesktops _ComputerGetDependentServices _ComputerGetPrintJobs _ComputerGetLoggedOnUsers Hardware UDFs _ComputerGetDrives _ComputerGetPrinters _ComputerGetProcessors _ComputerGetBIOS _ComputerGetSoundCards _ComputerGetVideoCards _ComputerGetKeyboard _ComputerGetMouse _ComputerGetSystemProduct _ComputerGetNetworkCards _ComputerGetSystem _ComputerGetMonitors _ComputerGetMotherboard _ComputerGetBattery _ComputerGetMemory I have finally created an include file with the above listed UDF's. I will be continually adding to this file. Include File: CompInfo.au3 | 1671 Previous Downloads (Total) Example File: CompInfoExamples.au3 | 929 Previous Downloads (Total) I have listed special thanks in the include file. Please note all example code will now start with #include "CompInfo.au3". I am working on adding error checking and standardizing the code. (Note: I haven't spent much time doing this as of late) NerdFencer has created a set of Drive UDF's that were inspired from this code. If you need more drive information please see his thread. ?do=embed' frameborder='0' data-embedContent> Edit 01: Added _ComputerGetPrinters Edit 02: Added _ComputerGetCPUs Edit 03: Changed _DriveGetInfo to _ComputerGetDrives Edit 04: Updated _ComputerGetDrives with documentation and error checking. Edit 05: Fixed _ComputerGetUsers @ComputerName wasnt being used properly. Edit 06: Added _ComputerGetGroups Edit 07: Updated _ComputerGet Printers/Groups with documentation and error checking. Edit 08: Changed _ComputerGetUsers to include more information. Updated _ComputerGetUsers with documentation and error checking. Edit 09: Changed _ComputerGetStartup to include more information. Updated _ComputerGetStartup with documentation and error checking. Edit 10: Added _ComputerGetServices Edit 11: Added to the top of the post about requiring AutoIt's Beta version. Edit 12: Added _ComputerGetBIOS Edit 13: Added _ComputerGetThreads Edit 14: Changed _ComputerGetCPUs to _ComputerGetProcessors and included more information. Edit 15: Added _ComputerGetProcesses Edit 16: Changed _ComputerGetPrinters to include more information and documentation. Edit 17: Added an Example file containing all 11 current UDF's in one simple file. Edit 18: Added _ComputerGetOSs, _ComputerGetShares, _ComputerGetEventLogs Edit 19: Added to the top about no longer requiring a Beta version to work correctly. Requires v3.2 + Edit 20: Added _ComputerGetSoundCards, _ComputerGetVideoCards Updated _ComputerGetGroups (moved "Description" to element 4 to match the rest of the library). Updated Processes, OSs, Processors, Services, Software, Threads, Printers, BIOS, and EventLogs to have the same header layout. Alphabetized CompInfo.au3 and CompInfoExamples.au3 Edit 21: Updated _ComputerGetOSs (Bug Fix) in CompInfoExamples.au3 (Thanks Koala) Edit 22: Added _ComputerGetKeyboard, _ComputerGetMouse Edit 23: Added _ComputerGetSystemProduct, _ComputerGetBootConfig Updated Spelling errors and misc items in CompInfoExamples.au3 Edit 24: Added _ComputerGetNetworkCards Edit 25: Added _ComputerGetExtensions, and _ComputerGetSystem Edit 26: Added _ComputerGetDesktops, _ComputerGetDependentServices, _ComputerGetPrintJobs, _ComputerGetBattery, _ComputerGetMotherboard, and _ComputerGetMonitor Edit 27: Added _ComputerGetMemory, and _ComputerGetLoggedOnUsers Edit 28: Updated CompInfo Version Information Error Edit 29: Linked ?do=embed' frameborder='0' data-embedContent> Thanks, JS1 point -
Use: $CBS_DROPDOWNLIST for ComboBox's style GUICtrlCreateCombo("item1", 10, 10, 50, 17,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL) )1 point