Collection of useful libraries

Post your working scripts, libraries and tools for AHK v1.1 and older
dcazrael
Posts: 5
Joined: 21 Jul 2019, 23:02

Collection of useful libraries

01 Sep 2019, 21:19

Hey everyone,

I'm Az, a very new and inexperienced coder.

Over the last couple months I have written several scripts to make my work easier and relied a lot on scripts and functions from other people to get things done.
While learning I realized I enjoy the OOP based approach and thus try to write and use everything as class when possible.

I have collected some very useful libraries and adapted them to be classes.
Some functions I wrote by myself, but most code was written by others.

Array
extends functionality for arrays and Objects on the base object
This allows the use of additional methods on the array itself, rather than calling a function and passing the array

Example:
Let's say you have a function to remove duplicates from an array.
Usually you do something like this newArray := removeDuplicates(oldArray)
Extending the base object allows us to add methods to the array itself
array.removeDuplicates()


base64
base64 decoder and varZ compression (written by SKAN) to save binary data to png files

Example use:
saveImage(base64Code, fileName){
Bytes := Base64Dec( BIN, base64Code )
VarZ_Save( BIN, Bytes, fileName )
VarSetcapacity( base64Code, 0 )
}
saveImage(yourBase64Code, flower.png)


Control
Wrapper for "Control" Commands

Counter
example from the documention on how to use timers in a class

CSV
reads csv and loads data in arrays
can be used to specifically read columns or rows

flowers := new CSV(flowerCsv.csv)
flowerName := flowers.readCol(4, 1, true) ; reads 4th column of data, Row 1 is a header, skip headers


ExplorerInfo
retrieves info from a specific explorer window

explorer := new ExplorerInfo()
path := explorer.getPath() ; get path for currently active explorer window
fileCreateDir(path . "\system32")
fileCopy("C:\Windows\system32\*.*", path . "\") ; copies system32 contents to current window


functions
Wrapper for several Commands to make scripts more uniform

AHK 1 still has functionality split between legacy Commands and new functions
FileCreateDir, %pathToFile%
The wrapper simulates a function syntax
fileCreateDir(pathToFile)


JSON
Json class written by Cocobelgica

NetRequest
Allows us to requests data from the web via WinHttp or Browser

String
Allows us to interact upon strings similar to objects

More syntax unification
Instead of
test := Instr(testVar, "Lucky", 0, 1)
I like to use
test := testVar.inStr("Lucky", 0, 1)



Window
Wrapper for "Window" Commands

Everywhere I remembered where I got it from, I put a @Source tag in the documentation.
If you find something I forgot to document or put the source, please let me know, So I can update it.

The repository will be maintained on Github.

Thank you
Last edited by dcazrael on 13 Nov 2019, 03:54, edited 2 times in total.
dcazrael
Posts: 5
Joined: 21 Jul 2019, 23:02

Re: Collection of useful libraries

28 Oct 2019, 21:30

Updated some of the libraries.

I'm still very inexperienced in regards of code.
If anybody has tips on how to make these libraries better, please let me know.

Thanks
User avatar
Bugz000
Posts: 93
Joined: 30 Sep 2013, 10:01

Re: Collection of useful libraries

28 Oct 2019, 21:37

i would suggest a basic usage example at the top of each one (or perhaps served seperately but i personally prefer it together)

that way people less skilled than yourself can work out how to use them :)
Image
||-------[-HP-ML350E-G8-]-------||-[-32-core-xeon-]-||--[-48gb-ECC-]--||
||----[-Dell-Poweredge-r610-]---||-[-16-core-xeon-]-||--[-16gb-ECC-]--||
||-[-Lenovo-ThinkPad-x201-tab-]-||---[-4-core-i7-]--||-[-8gb-nonECC-]-||
||---------------------------[-shack--img-]---------------------------||
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Collection of useful libraries

30 Oct 2019, 08:01

Thanks for these! Just FYI, the NetRequests link in the OP has a typo, or the name of the library on GitHub does ("NetRequest.ahk").
Really useful stuff. Like @Bugz000, I think examples at the top of each library or in the OP would be very helpful indeed (but that's a lot of examples to put in one post :D ).
Regards,
burque505
dcazrael
Posts: 5
Joined: 21 Jul 2019, 23:02

Re: Collection of useful libraries

13 Nov 2019, 03:55

Thank you for the feedback.
I added some small examples for typical use cases.
Also fixed the typo for the NetRequest link.

Thank you again
dcazrael
Posts: 5
Joined: 21 Jul 2019, 23:02

Re: Collection of useful libraries

23 Dec 2019, 19:27

I made some small adjustments to the functions, adding a floorMod function similar to JAVA.
If you simply use "%" your results will be less or equal to the quotient
Via "/" you will get a return of an "integer closest to 0".

Depending on your application this can make a big difference in your outcomes.
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Collection of useful libraries

23 Dec 2019, 21:38

Nice work
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Collection of useful libraries

28 Dec 2019, 23:05

Here's a some additional array methods that you can use for your array library, just be aware they're written with the same functionality as JS array.prototype in mind as well as 0 base indexing. I actually dropped this on Reddit awhile ago but no one was overly interested.
dcazrael
Posts: 5
Joined: 21 Jul 2019, 23:02

Re: Collection of useful libraries

07 Jan 2020, 19:17

Hey Onimuru,

actually some of the methods I have added in the Array lib I provided are from the JS array.prototypes. I didn't see a use for everything since AHK already implements a lot of them.
I will go over it when I get time and add the ones, that aren't provided by AHK natively.

Thank you
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Collection of useful libraries

08 Jan 2020, 12:35

@dcazrael, thanks for your updates. @Onimuru, somehow I missed your linked post. Nice work as well, lots of useful stuff. By the way, I'd love to see some examples of your GDIp code if you have some.
Regards,
burque505

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 223 guests